Skip to content

Instantly share code, notes, and snippets.

@kawabataryo
Last active August 29, 2015 14:09
Show Gist options
  • Save kawabataryo/2c3251a0c60b0ba0aca9 to your computer and use it in GitHub Desktop.
Save kawabataryo/2c3251a0c60b0ba0aca9 to your computer and use it in GitHub Desktop.
特定の位置で対象を表示する
/**
* 特定の位置で対象を表示する
* @param {String} el 対象のセレクター ※必須
* @param {Number} position 特定の位置 ※必須
*/
function ShowElementOnScroll(el,position){
this.$el = $(el);
this.position = position;
this.$window = $(window);
this.event();
}
ShowElementOnScroll.prototype = {
event: function(){
var that = this;
this.$window.on('scroll', function(){
var scrollTop = that.getScrollTop(this);
that.decidePosition(scrollTop);
});
},
getScrollTop: function(self){
return $(self).scrollTop();
},
decidePosition: function(scrollTop){
if( scrollTop > this.position ){
this.$el.stop().fadeIn(200);
}else{
this.$el.stop().fadeOut(200);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment