Last active
July 12, 2019 06:20
-
-
Save dohoons/4c7db25fdd8ab52cb7b18206eeff2bd4 to your computer and use it in GitHub Desktop.
scroll check : https://jsfiddle.net/dohoons/xg29zo4m/
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
// scroll check | |
(function() { | |
var $window = $(window); | |
var $target = $('.scroll-check'); | |
function scrollHandle() { | |
var winHeight = $window.height(); | |
var scrollTop = $window.scrollTop(); | |
$target.each(function() { | |
var $this = $(this); | |
var ratio = 1 - (Number($this.data('ratio')) || 80) / 100; | |
var isViewportIn = scrollTop > ($this.offset().top - winHeight) + (winHeight * ratio); | |
$this.toggleClass('in', isViewportIn); | |
}); | |
} | |
$target.addClass('ready'); | |
$window.on('resize scroll', scrollHandle); | |
scrollHandle(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment