refresh image with jquery asynch -
i use script beneath refresh webcam image. refreshes every 18 seconds , after 8 refresh stops refreshing. have feeling not cancel correctly. because after time see loading sign going haywire. there wrong script?
var count = 0; function camrefresh() { count++; if(count > 8) clearinterval(timeout); updatecam(); } var timeout = setinterval(camrefresh, 18000); }); function updatecam() { $('#loading').show('fast'); $('#activecam').attr('src', 'http://weeg.binaer.no/weeg_com/nesjordet.jpg?time='+date()); $('#loading').hide('slow'); $('#currentswitch').hide(1500); $('#dayswitch').show(); }
i suspect animation of loading element in updatecam() function has timing issue if previous animation didn't finish yet - chain stop() in there. try this:
function updatecam() { $('#loading').show('fast'); $('#activecam').attr('src', 'http://weeg.binaer.no/weeg_com/nesjordet.jpg?time='+date()); $('#loading').stop().hide('slow'); $('#currentswitch').hide(1500); $('#dayswitch').show(); } also note setting src attribute doesn't wait until image loaded. can put hook in load function:
$('#activecam').attr('src', 'http://weeg.binaer.no/weeg_com/nesjordet.jpg?time='+date()) .load(function() { $('#loading').stop().hide('slow'); $('#currentswitch').hide(1500); $('#dayswitch').show(); });
Comments
Post a Comment