Skip to content

Instantly share code, notes, and snippets.

@dohoons
Last active July 12, 2019 06:20
Show Gist options
  • Save dohoons/4c7db25fdd8ab52cb7b18206eeff2bd4 to your computer and use it in GitHub Desktop.
Save dohoons/4c7db25fdd8ab52cb7b18206eeff2bd4 to your computer and use it in GitHub Desktop.
// 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