Last active
August 29, 2015 14:09
-
-
Save kawabataryo/2c3251a0c60b0ba0aca9 to your computer and use it in GitHub Desktop.
特定の位置で対象を表示する
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
/** | |
* 特定の位置で対象を表示する | |
* @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