Monday 15 September 2014

Slow jQuery - long load times? -



Slow jQuery - long load times? -

i completly new jquery. it's possible missed basic things , code looks piece of junk. sense free ignore 1 if like.

i wrote code, sometimes, browser doesn't respond "clics" , doesn't anything. works properly, after time it's stuck again. ideas? lot!

$(document).ready(function() { $("#text2").hide(); $("#text3").hide(); $('#ball1').click(function() { $('#text2').fadeout('slow'); $('#text3').fadeout('slow'); $('#text1').fadein('slow'); $("#arrow").animate({left:'40px'}); $('#ball2').click(function() { $('#text1').fadeout('slow'); $('#text3').fadeout('slow'); $('#text2').fadein('slow'); $("#arrow").animate({left:'400px'}); $('#ball3').click(function() { $('#text2').fadeout('slow'); $('#text1').fadeout('slow'); $('#text3').fadein('slow'); $("#arrow").animate({left:'770px'}); }); }); }); });

i think scope messed up. forget close each function, instead nest them in first. it's slow because maintain assigning click events every time click #ball1. replace this:

$(document).ready(function() { $("#text2").hide(); $("#text3").hide(); $('#ball1').click(function() { $('#text2').fadeout('slow'); $('#text3').fadeout('slow'); $('#text1').fadein('slow'); $("#arrow").animate({left:'40px'}); }); $('#ball2').click(function() { $('#text1').fadeout('slow'); $('#text3').fadeout('slow'); $('#text2').fadein('slow'); $("#arrow").animate({left:'400px'}); }); $('#ball3').click(function() { $('#text2').fadeout('slow'); $('#text1').fadeout('slow'); $('#text3').fadein('slow'); $("#arrow").animate({left:'770px'}); }); });

jquery

No comments:

Post a Comment