我在这里有些问题 与我的js。
它的功能是正确的,但在某些情况中,性能太慢。
我轻轻地向下滚动,但当我试图再次滚动时,它会慢慢地滚动。
我能做些什么来提高业绩?
谢谢!
$(function(){
var windowHeight = $(window).height();
var windowWidth = $(window).width();
var sectionsNumbers = $("#content section").length-1;
var sectionCount = 0;
// Scroll sets
var windowScrollX = ((sectionsNumbers+1)*windowWidth)-windowWidth;
var windowScrollY = ((sectionsNumbers+1)*windowHeight)-windowHeight;
$("#content").css("width", windowScrollX+windowWidth);
$("#content").css("height", windowScrollY+windowHeight);
$(".illusion1").css("width", windowScrollX+windowWidth);
$(".illusion1").css("height", windowScrollY+windowHeight);
// Set mask w and h
$("#mask").css("width", windowWidth);
$("#mask").css("height", windowHeight);
$(".scrollRule").css("height", (sectionsNumbers+1)*windowHeight);
$("#content section").each(function() {
// Defines its width and height
$(this).css("width", windowWidth);
$(this).css("height", windowHeight);
// Defines its position
$(this).css("left", sectionCount*windowWidth);
$(this).css("top", sectionCount*windowHeight);
sectionCount++;
});
// When window scrolls
$(window).scroll(function(){
var curScrollTop = $(window).scrollTop();
var angleVar = windowScrollX/windowScrollY;
$("#content").stop().animate({left: "-"+curScrollTop*angleVar, top: "-"+curScrollTop}, {duration: 250, easing: easeOutQuart });
$(".illusion1").stop().animate({left: "-"+curScrollTop*angleVar*0.5, top: "-"+curScrollTop*0.5}, {duration: 250, easing: easeOutQuart });
//{duration: 1500, easing: easeOutQuart }
});
});