jquery - make these javascript functions more portable -


i'm missing fundamental understanding of javascript function flow control...

i've created jquery slideshow. show broken down logical sections, each section controlled function (makes easy add sections later)...

function myslideshow() {     section1();     section2();     section3(); } 

each section has multiple functions composed of jquery statements, animations, timed stuff...so maybe..

function section1() {     firstpart();     settimeout('secondpart()',5000);     settimeout('thirdpart()',6000); } 

now here's issue... want define functions "firstpart(), secondpart(), thirdpart()" inside of section1(). want various reasons:

  1. each section may logically have own "parts"
  2. portability of section

so keep section , of respective parts inside of section.

i can't seem work... when define "parts" inside of section of functions ran @ same time.

so ideally i'd have is:

function section1() {     firstpart();     settimeout('secondpart()',5000);     settimeout('thirdpart()',6000);      function firstpart(){            //some code here     }      function secondpart(){            //some code here     }      function thirdpart(){            //some code here     }  } 

but again doesn't work out properly; works i'm not implementing properly! not sure if need leverage function callbacks (not sure how set in "scalable manner").

another area improvement: settimeouts used ensure secondpart runs after firstpart... wondering if there better ways "wait" on previous function (with jquery animations) complete.

i appreciate direction can offer. thanks!

you're calling "settimeout()" incorrectly:

settimeout(secondpart, 5000); 

that pass reference local function. when pass string, runtime system evaluate when timer goes off, in global context. thus, won't find local function.

as last question, (if not all) jquery animation routines allow function passed last argument. function run after animation completes. again, in such cases, should pass reference function , not string containing function call expression. (i doubt work jquery anyway.)


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -