settimeout - Jquery image fade with sequential sources -


I have created a fat script to replace the image with Fadin, I want to change it every 5 seconds while taking a new one. One of the pools of images I have 4 JPEG sequential names in this case: dish1 dish2 dish3 dish4 but the result is in pagload and there is no change in image:

  $ (document). Ready (work () {function chngImg (curImg = 1, imgNum = 4) {var src = "immagini / dishes_pizze / dish" + curimg + ".jpg"; $ ('# image'). FadeOut ("slow") $ ('# Snap'). Entry ('src', src); $ ('# image'). Feedin ("slow"); curimg ++; if (curg; iGnIM) {curImg = 1;} // End if setTimeout ('chngImg (curImg, imgNum);', 5000);} // and chngimg}); // endready  

Any help would be helpful, I'm new to jQuery.

The problem occurs when you pass the function name in the setTimeout function The function should be public, but in your code, the function is declared inside chngImg $ (document) .ready . This is a local function, which is why your code is not run. And you can not set the default value of the argument.

Your code should be

  function chngImg (curImg, imgNum) {if (! Curimg) {curImg = 1; } If (! Ignum) {imgNum = 4; } Var src = "idagini / dishpages / dish" + qmog + ".jpg"; $ ('#pictures') fadeOut ("slow"). $ ('#paintings'). Attr ('src', src); $ ('#pictures') fadein ("slow"). CurImg ++; If (curImg> IMGNM) {curImg = 1; } // end if setTimeout ('chngImg (curImg, imgNum);', 5000); } $ (Document) .ready (function () {chngImg ();});  

Or you can pass the callback to setTimeout such as:

  $ (document) .ready (function () {Function ChngImg (curImg, imgNum) {if (! Curimg) {curImg = 1;} If (! IMGNm) {imgNum = 4;} var src = "Imagini / Dish_Pages / Dish" + Qoom + ".jpg"; $ ('$'). $ ('Src', 'src'); $ ('# image'). Feedin ("slow"); curImg ++; if (Kurim and GT); ImgNum) {curImg = 1;} // end if setTimeout (function () {chngImg (curImg, imgNum);}, 5000)}} chngImg ();});  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -