Skip to content

Commit 59ec06a

Browse files
authored
Merge pull request alvarotrigo#2420 from passion4code/offsetTop-option
Offset top option
2 parents 01bd9f1 + d168251 commit 59ec06a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ $(document).ready(function() {
202202
responsiveWidth: 0,
203203
responsiveHeight: 0,
204204
responsiveSlides: false,
205+
offsetTop: 0,
205206

206207
//Custom selectors
207208
sectionSelector: '.section',
@@ -473,6 +474,8 @@ In order to prevent fullpage.js from creating the scrollbar in certain sections
473474

474475
- `responsiveSlides`: (default `false`) [Extension of fullpage.js](http://alvarotrigo.com/fullPage/extensions/). When set to `true` slides will be turned into vertical sections when responsive mode is fired. (by using the `responsiveWidth` or `responsiveHeight` options detailed above). Requires fullpage.js >= 2.8.5.
475476

477+
- `offsetTop`: (default `0`). When set to a numeric value, this defines a top offset for the container height. This is particularly useful if you have a fixed header navigation that follows your scroll and you do not want the header navigation to cut off content in your sections.
478+
476479
- `lazyLoading`: (default `true`) Lazy loading is active by default which means it will lazy load any media element containing the attribute `data-src` as detailed in the [Lazy Loading docs](https://github.com/alvarotrigo/fullPage.js#lazy-loading) . If you want to use any other lazy loading library you can disable this fullpage.js feature.
477480

478481
## Methods

jquery.fullPage.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
responsiveWidth: 0,
168168
responsiveHeight: 0,
169169
responsiveSlides: false,
170+
offsetTop: 0,
170171

171172
//Custom selectors
172173
sectionSelector: SECTION_DEFAULT_SEL,
@@ -191,7 +192,7 @@
191192
var isTouchDevice = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|playbook|silk|BlackBerry|BB10|Windows Phone|Tizen|Bada|webOS|IEMobile|Opera Mini)/);
192193
var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0) || (navigator.maxTouchPoints));
193194
var container = $(this);
194-
var windowsHeight = $window.height();
195+
var windowsHeight = $window.height() - options.offsetTop;
195196
var isResizing = false;
196197
var isWindowFocused = true;
197198
var lastScrolledDestiny;
@@ -437,7 +438,7 @@
437438

438439
isResizing = true;
439440

440-
windowsHeight = $window.height(); //updating global var
441+
windowsHeight = $window.height() - options.offsetTop; //updating global var
441442

442443
$(SECTION_SEL).each(function(){
443444
var slidesWrap = $(this).find(SLIDES_WRAPPER_SEL);
@@ -537,6 +538,11 @@
537538
options.css3 = support3d();
538539
}
539540

541+
if (options.offsetTop) {
542+
container.css("top", options.offsetTop);
543+
container.height(container.height() - options.offsetTop);
544+
}
545+
540546
options.scrollBar = options.scrollBar || options.hybrid;
541547

542548
setOptionsFromDOM();
@@ -648,7 +654,7 @@
648654
$('html').addClass(ENABLED);
649655

650656
//due to https://github.com/alvarotrigo/fullPage.js/issues/1502
651-
windowsHeight = $window.height();
657+
windowsHeight = $window.height() - options.offsetTop;
652658

653659
container.removeClass(DESTROYED); //in case it was destroyed before initializing it again
654660

0 commit comments

Comments
 (0)