Created
May 25, 2015 14:58
-
-
Save novogrammer/eeae59dab2a83662aecc to your computer and use it in GitHub Desktop.
jQueryのプラグインを見よう見まねで作ってみた
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
jQuery ($)-> | |
$(".product .image").myScrollTrigger({offset:-300 | |
,init:-> | |
$this=$(this) | |
$this.css({marginLeft:"20px",opacity:0}) | |
,appear:-> | |
$this=$(this) | |
$this.transit({marginLeft:"0px",opacity:1},2000) | |
}) | |
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
(($)-> | |
$.fn.myScrollTrigger=(options)-> | |
settings=$.extend({ | |
offset:0, | |
init:->, | |
appear:->, | |
},options) | |
return this.each -> | |
that=this | |
$that=$(that) | |
settings.init.apply(that,[]) | |
$(window).on("load scroll resize",-> | |
elementTop=$that.offset().top | |
elementHeight=$that.height() | |
scrollTop=$(window).scrollTop() | |
windowHeight=$(window).height() | |
if scrollTop+windowHeight > elementTop+elementHeight+settings.offset | |
unless $that.hasClass("appeared") | |
settings.appear.apply(that,[]) | |
$that.addClass("appeared") | |
) | |
)(jQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment