javascript - Page hangs because of animation, when other page is viewed -
for me personally, odd..
i have script infinity animated elements. when view ony page, code works fine. when leave script , run other browser window.. strange things start happen. example go check facebook, , after 10 seconds go site script (which should work time) then, script crushes , full page hangs..
you can check own, i've created codepen this:
just go there, leave opened , surf @ page in other window..
the problem badgeclone function - know sure. badge1 variable takes .badge element, clone , make animation. when active window script again, after view page, var badge1 returns .badge element multiply times in console log - , browser dies.
piece of code function (badgeclone)
function badgeclone() { var badge1 = $('.badge'); var badge2 = $('.badge').clone(); var badgewidth = badge1.width(); var badgeheight = badge1.height(); badge1.after(badge2); badge2.css({ 'line-height': '180px', 'text-align': 'center', 'font-size': '70px', 'font-weight': 'bold', 'color': '#fff', 'opacity':'0' }); badge2.animate({ 'width': badgewidth * 2 + 'px', 'height': badgeheight *2 + 'px', 'line-height': '360px', 'font-size': '140px', 'top': '-150px', 'right': '-100px' }, 500, "linear", function() { if(count >= 9) { count = 1 } else { count++ } badge2.text(count); badge2.delay(300).animate({ 'width': badgewidth + 'px', 'height': badgeheight + 'px', 'line-height': '180px', 'font-size': '70px', 'top': '-60px', 'right': '-40px', 'opacity': '1'}, 500, "linear", function(){ badge1.fadeout(600, function(){ console.log(badge2); $(this).remove(); console.log(badge1); }); }); }); }
i've heard that, can because of new browsers features. make somthing auto queue on script when window inactive , when active window site again, things in queue blast off in 1 time.
this can true, question is.. how stop it?
once again - in advance :)
Comments
Post a Comment