Skip to content

Instantly share code, notes, and snippets.

@maiko-ampersand
Created July 18, 2014 13:54
Show Gist options
  • Select an option

  • Save maiko-ampersand/969f5a4b78adeb019011 to your computer and use it in GitHub Desktop.

Select an option

Save maiko-ampersand/969f5a4b78adeb019011 to your computer and use it in GitHub Desktop.
jQueryでシンプルなstickyのプラグイン ref: http://qiita.com/se_ino/items/b7e9839fcfcf7665ceca
(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