-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
436 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* @file jQuery Plugin: jquery.simple-scroll-follow | ||
* @version 3.0.1 | ||
* @version 3.1.0 | ||
* @author Yuusaku Miyazaki <[email protected]> | ||
* @license MIT License | ||
*/ | ||
|
@@ -146,7 +146,9 @@ $.extend($.simpleScrollFollow.prototype, /** @lends external:jQuery.simpleScroll | |
this.option = $.extend({ | ||
enabled: true, | ||
limit_elem: $('body'), | ||
min_width: 0 | ||
min_width: 0, | ||
upper_side: null, | ||
lower_side: null | ||
}, option); | ||
if (typeof this.option.limit_elem == 'string') { | ||
this.option.limit_elem = $(this.option.limit_elem); | ||
|
@@ -161,8 +163,16 @@ $.extend($.simpleScrollFollow.prototype, /** @lends external:jQuery.simpleScroll | |
* @return {number} - 算出されたoffset_bottom | ||
*/ | ||
_calcOffsetBottom: function(elem) { | ||
return $(elem).offset().top + | ||
$(elem).height() + | ||
return $(elem).offset().top + this._calcElemHeight(elem); | ||
}, | ||
|
||
/** | ||
* @private | ||
* @arg {Object} elem - Target element to calc height | ||
* @return {number} - the height which includes border-width and padding | ||
*/ | ||
_calcElemHeight: function(elem) { | ||
return $(elem).height() + | ||
Number($(elem).css('border-top-width' ).replace(/px$/, '')) + | ||
Number($(elem).css('border-bottom-width').replace(/px$/, '')) + | ||
Number($(elem).css('padding-top' ).replace(/px$/, '')) + | ||
|
@@ -188,8 +198,8 @@ $.extend($.simpleScrollFollow.prototype, /** @lends external:jQuery.simpleScroll | |
|
||
// 画面の上端、下端を取得 | ||
var win = { | ||
scroll_top: $(window).scrollTop(), | ||
scroll_bottom: $(window).scrollTop() + $(window).height() | ||
scroll_top: this._getUpperSide(), | ||
scroll_bottom: this._getLowerSide() | ||
}; | ||
|
||
// 追尾要素の "現在の" 上端、下端を取得 | ||
|
@@ -209,6 +219,36 @@ $.extend($.simpleScrollFollow.prototype, /** @lends external:jQuery.simpleScroll | |
return true; | ||
}, | ||
|
||
/** | ||
* @private | ||
* @returns {number} Upper side of window | ||
*/ | ||
_getUpperSide: function() { | ||
var winScrollTop = $(window).scrollTop(); | ||
if (this.option.upper_side) { | ||
var upperLimitBottom = this._calcOffsetBottom(this.option.upper_side); | ||
if (winScrollTop < upperLimitBottom) { | ||
winScrollTop = upperLimitBottom; | ||
} | ||
} | ||
return winScrollTop; | ||
}, | ||
|
||
/** | ||
* @private | ||
* @returns {number} Lower side of window | ||
*/ | ||
_getLowerSide: function() { | ||
var winScrollBottom = $(window).scrollTop() + $(window).height(); | ||
if (this.option.lower_side) { | ||
var lowerLimitTop = $(this.option.lower_side).offset().top; | ||
if (winScrollBottom > lowerLimitTop) { | ||
winScrollBottom = lowerLimitTop; | ||
} | ||
} | ||
return winScrollBottom; | ||
}, | ||
|
||
/** | ||
* @private | ||
* @desc イベントハンドラ: 画面スクロール | ||
|
@@ -311,7 +351,7 @@ $.extend($.simpleScrollFollow.prototype, /** @lends external:jQuery.simpleScroll | |
$(this.follow.elem) | ||
.css({ | ||
position: 'fixed', | ||
top: 0, | ||
top: this._getPositionToStickToWindow(this.option.upper_side), | ||
bottom: 'auto', | ||
left: this.follow.offset_left, | ||
right: 'auto' | ||
|
@@ -328,13 +368,26 @@ $.extend($.simpleScrollFollow.prototype, /** @lends external:jQuery.simpleScroll | |
.css({ | ||
position: 'fixed', | ||
top: 'auto', | ||
bottom: 0, | ||
bottom: this._getPositionToStickToWindow(this.option.lower_side), | ||
left: this.follow.offset_left, | ||
right: 'auto' | ||
}) | ||
.width(this.follow.width); | ||
}, | ||
|
||
/** | ||
* @private | ||
* @arg {object} limit - this.option.upper_side or this.option.lower_side | ||
* @returns {number} position-top/bottom to stick to window | ||
*/ | ||
_getPositionToStickToWindow: function(limit) { | ||
if (limit) { | ||
return this._calcElemHeight(limit); | ||
} else { | ||
return 0; | ||
} | ||
}, | ||
|
||
/** | ||
* @private | ||
* @desc イベントハンドラ: 画面リサイズ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "jquery.simple-scroll-follow", | ||
"description": "jQuery plugin to move the element according to the scrolling window.", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
"author": "Yuusaku Miyazaki <[email protected]>", | ||
"homepage": "https://github.com/sutara79/jquery.simple-scroll-follow", | ||
|
Oops, something went wrong.