HOME > jQuery > スクロールして画面の下に来た時にパーツをフェードアウト・インする方法

スクロールして画面の下に来た時にパーツをフェードアウト・インする方法

スクロールして画面の下に来た時にパーツをフェードアウト・インする方法。コンタクトボタンやSNSボタンを表示するとか、広告表示を消すとか。そういう時に使えますね。

以下は、右下にdisplay: fixed;で表示していたコンタクトボタンをフェードアウトさせた例です。

/* fixContact */
$(function() {
   var fixContact = $('#fixContactBtn');
   $(window).bind("scroll", function() {
	scrollHeight = $(document).height();
	scrollPosition = $(window).height() + $(window).scrollTop();
	if ( (scrollHeight - scrollPosition) / scrollHeight <= 0.05) {
            fixContact.fadeOut();
	} else {
            fixContact.fadeIn();
	}
});
});

一番下まで、としないほうがいいんじゃないかということで5%になってます。

参考サイト

    Warning: Undefined array key "HTTP_REFERER" in /home/xs241045/ridesign.jp/public_html/lib/wp/wp-content/themes/libridesign2017/single-post.php on line 54

Warning: Undefined array key "HTTP_REFERER" in /home/xs241045/ridesign.jp/public_html/lib/wp/wp-content/themes/ridesignjp2016/relatedLinks.php on line 10