Same javascript different sites, drastically different performance
Hello and thanks in advance,
*Problem*:
Drastically different performance with the same javascript on two different sites. My site will occasionally lockup with the whole "script is outta control, do you want to shut it down" thing, while the other one I can actively see updating numbers in the inspector.
*Question*:
What causes my site to be slower? The only thing I could think of is that I have crappy GoDaddy economy hosting. Is this a good assumption, anything else it could be to create the discrepancy between two sites with identical stuff?
*Code*:
jQuery(window).scroll(function(){
var offset = window.pageYOffset;
$('#page-1').css({
"background-position" : "40% "+ (200 - (offset / 4))+"px"
});
$('#page-2').css({
"background-position" : "40% "+ (300 -(offset / 4))+"px"
});开发者_Go百科
$('#page-3').css({
"background-position" : "40% "+ (750 - (offset / 4))+"px"
});
$('#page-4').css({
"background-position" : "40% "+ (1000 -(offset / 4))+"px"
});
$('#page-5').css({
"background-position" : "40% "+ (1200 - (offset / 4))+"px"
});
*Markup*:
<ul id="container">
<li id="page-1">
<div style="position:absolute; right:50px; top:450px;"><h1>Test1</h1></div>
</li>
<li id="page-2">
<div style="position:fixed; left:50px; top:-400px;"><h1>Test2</h1></div>
</li>
<li id="page-3">
</li>
<li id="page-4">
</li>
<li id="page-5">
</li>
</ul>
*Side Note*
The code I created is not the code above, I actually was making some improvements on it, but somehow the site that gave me the inspiration is still faster, and without the improvements.
*UPDATE*
Here are the sites, sorry for not including them.
Mine:
http://www.gam3rtech.com/work/scrollPage.php
Other:
http://www.davegamache.com/sandbox/best-of-2010/index.php
Wow, so the issue is that I was using jQuery 1.4, upgraded to 1.4.4 and it started working like it was supposed to, updating extremely fast.
Went up to 1.6.2, 1.6.1, 1.6 and it stopped updating as quickly.
Went back to 1.4.4 and it still isn't working like it was. I am completely baffled.
精彩评论