Sunday, 15 April 2012

How do you make JQuery to load images on page load ? -


The code below works fine with 'mousemov', but I want to display images on page load, Nothing else that I have changed images are displayed on page load. Any help is greatly appreciated! Thanks Ian

  $ (document) .ready (function () {$ ("body"). Mousemove (function () {$ ("li.fsn-level-1") each. Child ("span") first () children ("img") length; if (IMGCount & lt; 2) {$ (this) children ("span"). ("Span") "" (")" ("& lt; img id = 'imgPlus' src = 'picture / plus' style = 'display: inline' / & gt;"); $ (this) ) First (). ("& Lt; img id = 'imgMinus' src = 'images / minus.png' style = 'display: none' / & gt;");} var closed = $ (this). HasClass ("closed"); var open = $ (this) .hasClass ("open"); var first =! Close & open; if (first) {$ (this) .removeClass ("Open") $ (find this ")" ("closed" (this) child ("span") first (). ("IMG [id = 'imgplus']"; if (plus. Lamp) (")" ("Img [id = 'imgMinus']"); if (minus.length) minus.hide (); } $ (This). Unbund ('hover'). Bind ('hover', function () {claus eAllSubMenu (); Var closed = $ (this) .hasClass ("closed"); Var open = $ (this ) .hasClass ("open"); Var first =! Closed & amp; Amp; Open! If (before || closed) {$ (this) .removeClass ("closed"); $ (This) .removeClass ("open") addClass ("open") Var sub = $ (this). Children ("ul"); If (sub. Langal) {sub. (;); } Plus plus = $ (this). Children ("span") first (). ("Img [id = 'imgPlus']"); If (plus.length) plus.hide (); Var minus = $ (this). Children ("span") first (). ("Img [id = 'imgMinus']"); If (minus.length) minus.show (); } If (open) {$ (this) .removeClass ("open") $ (this) .removeClass ("off"). AddClass ("Closed"); Var plus = $ (this). Children ("span") first (). ("IMG [ID = 'IMGPlus']"); If (plus.length) plus.show (); Var minus = $ (this). Children ("span") first (). ("Img [id = 'imgMinus']"); If (minus.length) minus.hide (); }}); });    

It's hard to see what you're actually trying to do, but This is what I found:

After the page is ready, you are adding images:

  $ (this). Children ("span") first (). Prepaid ("& lt; img id = 'imgplus' src = 'picture / plus page' style = 'display: inline' / & gt;"); $ (This). Children ("span") first (). Prepaid ("& lt; img id = 'imgMinus' src = 'images / minus.png' style = 'display: none' / & gt;");   

This will cause images to be loaded at that time on time, i.e.: you are waiting for the page to be ready (load), then you are adding them, and loading them Are forced to page after loading.

If you need to be dynamic (which looks like this), try it before calling $ (document) .ready (); In this way they will be included in the load for the document (and therefore whichever occurs later).

No comments:

Post a Comment