jQuery 15

div 내부에 있는 스크롤 영역 계산, 스크롤시 섹션에 맞는 tab에 active ( position() )

// 스크롤시 섹션에 맞는 tab에 active 주기 $("#wrap_content").scroll(function () { const height = $("#wrap_content").scrollTop(); // 해당 스크롤 좌표값(높이) const content = $('.content_area'); content.each(function () { const a = $(this).position(); if (a.top == height || a.top < height + 200) { const thisIndex = $(this).index() const tabIndex = $('.tab').eq(thisIndex); tabIndex.addClass('active'); // $('.tab').not(t..

Publish/JavaScript 2022.10.01

[문제 해결] 스크롤 해서 맨 아래 도달시 스크립트 이벤트 활성화 하기

const docHeight = $(document).height(); const winHeight = $(window).height(); // $(window).scroll(function() { // const nene = $(window).scrollTop(); // console.log(nene); // console.log(docHeight); // console.log(winHeight); // }) $(window).scroll(function() { if($(window).scrollTop() + winHeight + 100 >= docHeight) { $(".main .pc_footer").addClass("active"); } else { $(".main .pc_footer").remo..

Publish/JavaScript 2022.06.20

TOP 위로가기 버튼 만들기

// top 버튼 $(window).scroll(function () { if ($(this).scrollTop() > 100) { $(".btn_top").fadeIn(); } else { $(".btn_top").fadeOut(); } }); $(".btn_top").click(function () { window.scrollTo({ top: 0, behavior: 'smooth' }); }); 위 코드는 조금 자잘한 문제들이 있음. 아래 코드가 반응이 더 빠르고, 부드럽게 이동함. // top 버튼 $(window).scroll(function () { if ($(this).scrollTop() > 100) { $(".btn_top").fadeIn(); } else { $(".btn_top").fa..

Publish/JavaScript 2022.06.17

[ 숫자 카운트 ] 스크롤시 setTimeout 실행 //하지만 무한반복된다

//숫자 카운트 function numberCounter(target_frame, target_number) { this.count = 0; this.diff = 0; this.target_count = parseInt(target_number); this.target_frame = document.getElementById(target_frame); this.timer = null; this.counter(); }; numberCounter.prototype.counter = function () { var self = this; this.diff = this.target_count - this.count; if (this.diff > 0) { self.count += Math.ceil(this.dif..

Publish/JavaScript 2022.04.02