Skip to content

Instantly share code, notes, and snippets.

@sou5534
Last active February 21, 2018 00:48
Show Gist options
  • Save sou5534/13afc5d23a58092dd1d78e4903e79715 to your computer and use it in GitHub Desktop.
Save sou5534/13afc5d23a58092dd1d78e4903e79715 to your computer and use it in GitHub Desktop.
<div class="target">aaaaa</div>
// ターゲットを非表示にしとく
$(".target").css("visibility","hidden").css("opacity","0");
// .targetのついた画像をスクロールに合わせfadeIn
$(window).on("load scroll resize", function(){
$(".target").each(function(){
var imgPos = $(this).offset().top;
var scroll = $(window).scrollTop();
var windowHeight = $(window).height();
if (scroll > imgPos - windowHeight + windowHeight / 5){
// ここに処理を書く
$(this).css("visibility","visible")
$(this).animate({opacity: 1}, 300);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment