스크롤 다운 element isVisible check로직 수정

This commit is contained in:
ecpla 2023-03-13 16:37:44 +09:00
parent 59d5a7b67c
commit 0a4ac20223

View File

@ -25,17 +25,7 @@ $(document).ready(function() {
$('.sec6 .onlineSwiper .items .List .inner div.thumbnail div.detail-cover').css('opacity','0'); $('.sec6 .onlineSwiper .items .List .inner div.thumbnail div.detail-cover').css('opacity','0');
}); });
// 현재 viewoport내의 element 확인 /* scroll-down function */
$.fn.isInViewport = function() {
var elementTop = $(this).offset().top;
var elementBottom = elementTop + $(this).outerHeight();
var viewportTop = $(window).scrollTop();
var viewportBottom = viewportTop + $(window).height();
return elementTop + 300 < viewportBottom
};
$(window).on('resize', function() { $(window).on('resize', function() {
//브라우저 크기 확인 실시 //브라우저 크기 확인 실시
var windowHeight = $(window).height(); //요소의 높이를 반환 var windowHeight = $(window).height(); //요소의 높이를 반환
@ -48,6 +38,18 @@ $(document).ready(function() {
} }
}); });
// 현재 viewport내의 element 확인
$.fn.isInViewport = function() {
var element = $(this);
var viewportHeight = $(window).height(); // Viewport Height
var scrolltop = $(window).scrollTop(); // Scroll Top
var y = $(element).offset().top;
var elementHeight = $(element).height();
// 반드시 요소가 화면에 보여야 할경우
return (((y + elementHeight) < (viewportHeight + scrolltop)) && (y > (scrolltop - elementHeight)));
};
$(window).on('scroll', function() { $(window).on('scroll', function() {
// scroll 숨기기 // scroll 숨기기
var $window = $(window); var $window = $(window);
@ -66,7 +68,7 @@ $(document).ready(function() {
$('.sec').each(function(index, item){ $('.sec').each(function(index, item){
if ($(item).isInViewport()) { if ($(item).isInViewport()) {
var seq = index+2; var seq = index+2;
if(seq == 8) { if(seq == 8) { //마지막 순서 안보이게 처리
$('#btn-scroll').removeClass("btn-scroll-fix"); $('#btn-scroll').removeClass("btn-scroll-fix");
$('#btn-scroll').addClass("btn-scroll-hide"); $('#btn-scroll').addClass("btn-scroll-hide");
$('#btn-scroll').attr('onclick',''); $('#btn-scroll').attr('onclick','');
@ -80,9 +82,10 @@ $(document).ready(function() {
}); });
function fn_Move(seq) { function fn_Move(seq) {
//section 별 width 달라서 interval 처리
var interval = 100; var interval = 100;
var offset = $("#sec" + seq).offset(); var offset = $("#sec" + seq).offset();
if(seq > 3) interval = 250; if(seq > 4) interval = 250;
$('html, body').animate({ $('html, body').animate({
scrollTop: offset.top - interval scrollTop: offset.top - interval
}, 300); }, 300);