Skip to content

Instantly share code, notes, and snippets.

@novogrammer
Created May 25, 2015 14:58
Show Gist options
  • Save novogrammer/eeae59dab2a83662aecc to your computer and use it in GitHub Desktop.
Save novogrammer/eeae59dab2a83662aecc to your computer and use it in GitHub Desktop.
jQueryのプラグインを見よう見まねで作ってみた
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)
})
(($)->
$.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