Created
July 18, 2014 13:54
-
-
Save maiko-ampersand/969f5a4b78adeb019011 to your computer and use it in GitHub Desktop.
jQueryでシンプルなstickyのプラグイン ref: http://qiita.com/se_ino/items/b7e9839fcfcf7665ceca
This file contains hidden or 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
| (function($) { | |
| 'use strict'; | |
| $.fn.stickeyMenu = function(options) { | |
| var $this = $(this); | |
| var defaultSetting = { | |
| startTop : 0 , | |
| stopTop : 0 , | |
| zIndex : 10 | |
| } | |
| var settings = $.extend( {},defaultSetting,options); | |
| var init = function() { | |
| var $self = $(this); | |
| $self.css( { | |
| 'position' : 'fixed' , | |
| 'top' : settings.startTop , | |
| 'zIndex' : settings.zIndex | |
| }) | |
| $(window).on('load scroll',function() { | |
| var _top = settings.startTop - $(this).scrollTop(); | |
| if(settings.stopTop <= _top ) { | |
| $self.css( { | |
| 'top' : settings.startTop - $(this).scrollTop() | |
| }); | |
| } | |
| else { | |
| $self.css( { | |
| 'top' : settings.stopTop | |
| }); | |
| } | |
| }) | |
| }; | |
| this.each(function() { | |
| init.apply(this); | |
| }); | |
| return this; | |
| } | |
| })(jQuery); | |
| $(function() { | |
| var _startTop = 500; // 初期位置 | |
| $('.gloval_menu_section').stickeyMenu( { | |
| startTop : _startTop | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment