스크롤 다운 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');
});
// 현재 viewoport내의 element 확인
$.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
};
/* scroll-down function */
$(window).on('resize', function() {
//브라우저 크기 확인 실시
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() {
// scroll 숨기기
var $window = $(window);
@ -65,8 +67,8 @@ $(document).ready(function() {
// 스크롤 할때마다 다음 section값으로 수정
$('.sec').each(function(index, item){
if ($(item).isInViewport()) {
var seq = index+2;
if(seq == 8) {
var seq = index+2;
if(seq == 8) { //마지막 순서 안보이게 처리
$('#btn-scroll').removeClass("btn-scroll-fix");
$('#btn-scroll').addClass("btn-scroll-hide");
$('#btn-scroll').attr('onclick','');
@ -76,13 +78,14 @@ $(document).ready(function() {
}
});
});
});
});
function fn_Move(seq) {
//section 별 width 달라서 interval 처리
var interval = 100;
var offset = $("#sec" + seq).offset();
if(seq > 3) interval = 250;
if(seq > 4) interval = 250;
$('html, body').animate({
scrollTop: offset.top - interval
}, 300);