$(window).scroll
함수에서 dom을 쿼리하고 있습니다. 나는 그 좋은 연습을 생각하지 않는다.
자바 스크립트를 통해 dom에 액세스하면 변수가 캐시되는 속도가 매우 느립니다.
코드에 많은 것들이 있습니다. 도움이되는지 확인하십시오.
Fiddle
$(function(){
var $window = $(window);
var windowHeight = $window.height();
var windowWidth = $window.width();
var content = $("#content");
var section = content.children("section");
var sectionsNumbers = section.length-1;
var illusion = $(".illusion1");
var mask = $('#mask');
// Scroll sets
var windowScrollX = ((sectionsNumbers+1)*windowWidth)-windowWidth;
var windowScrollY = ((sectionsNumbers+1)*windowHeight)-windowHeight;
content.css({"width":windowScrollX+windowWidth,"height":windowScrollY+windowHeight});
illusion .css({"width":windowScrollX+windowWidth,"height":windowScrollY+windowHeight});
// Set mask w and h
mask.css({"width":windowWidth,"height":windowHeight});
$(".scrollRule").css("height", (sectionsNumbers+1)*windowHeight);
section.each(function(sectionCount,val) {
// Defines its width and height
var $this = $(this);
$this.css({"width":windowWidth,"height":windowHeight,"left":sectionCount*windowWidth,"top":sectionCount*windowHeight});
});
// When window scrolls
var angleVar = windowScrollX/windowScrollY;
var curScrollTop;
$(window).scroll(function(){
var $this = $(this);
curScrollTop = $this.scrollTop();
content.stop().animate({left: "-"+curScrollTop*angleVar, top: "-"+curScrollTop}, {duration: 1250, easing: 'easeOutQuart'});
illusion.stop().animate({left: "-"+curScrollTop*angleVar*0.5, top: "-"+curScrollTop*0.5}, {duration: 1250, easing: 'easeOutQuart'});
});
});
경우 다 codez이야? –
스크롤 속도가 느린 이유는 스크롤 막대가 움직이는 모든 픽셀에 대해'$ (window) .scroll() '함수를 한 번씩 실행하기 때문입니다. 전체 페이지를 스크롤하면 해당 기능이 3325 번 호출된다는 것을 의미합니다. –
애니메이션을 사용 중지하면 얼마나 효과가 있습니까? – Jordan