jquery - Image Preloader Problem -


I came up with this code and found that in the first load of the image, the infection works fine, but for the second time, the infection Will not be visible.

  var imgIndex = 0; SlideImages (); ARTR ("style", "display: none;"). Load (function () ($ ("(SRR"), "image / and live" (this) .appendTo ("div.picCon"); $ (this) .show ("& lt ;? php echo $ PortfolioTransition ;? & gt; ", & amp; lt; php $ effectDuration ;;>, function () {SetTimeout (hideImg, 2000);});});} Function hideImg () {$ (" div .picCon img: visible "). FadeOut (function () {$ (" div.picCon "). Blank (); imgIndex = (imgIndex & lt; the images.length)? ImgIndex + 1: 0; slides images () ;});}  

Where $ portfolioTransition = "bounce"; $ EffectDuration = 1000;

Is there any way that the image is already running in the cache Is there? Or an alternative way so that my code will work below ..):

Found in the work for Fari, but not in Chrome.

  function slide images atr ("circle", image [imgidx]). Et ("style", "display: none; "." ("Load", function () {$ (this) .appendTo ("div.picCon"); $ (this) .show ("& lt ;? php echo $ portfolioTransition ;? & gt;", & Lt ;? php $ effectDuration ;? & gt; function () {SetTimeout (hideImg, 2000);})}} Each (function () {if (this.complete) $ (this) .trigger ("load");}); }  

quoted from

It is possible that The load event will not be triggered if the browser is full of images from the cache.

I think setting a load handler can be a trick before setting the src attribute. Try changing your chain order in your code to

  $ ("& lt; img />").attr("style", "display: none;"); .load (function () {...}) .attr ("src", images [imgindex])  

updated answer

Here the full code and demo are workable ( I believe )

Required changes

  1. Before setting up the src Setting the Load Event image
  2. Automatically ignite the event when loaded
  3. Use an () method, when the load event works directly with # 1 Indemnification for different browsers (# 2 Minister without the need) and not others (we only want to do once loaded)
  4. Way to fix it you increase the counter images.

In short we have suggested the move and have succeeded in our own, but this also introduces a change because each trick works in different browsers, and we only have two Want to use one of the moves, not both ..


Comments