drupal - Passing a variable to setTimeout() -


i've installed jcarousel on drupal 7 need scroll horizontally both sides when client hovers on arrows.

i've been trying pass variable timeout function , doesn't seem work. in following code timeout recognizes only: var n = function () {c.next();}; need able tell timeout either scroll left or right using c.prev() or c.next() depending on arrow user clicked.

var c = this; var k = 1; var n = function () {c.next();};  if (k == 1) n = function () {c.prev();}; if (k == 5) n = function () {c.next();};  this.timer = window.settimeout(n, 500) 

i've tried way , doesn't work either.

var c = this; var k = 5; this.timer = window.settimeout(function() {c.nextprev(k);}, 500) 

...

  nextprev: function(k) {  if (k === 1) return "prev()"; if (k === 5) return "next()";  } 

any or guideline appreciated!

try this, doesn't feel 100% right, introduces techniques seem need:

c.nextprev execute , return function needed, capturing c , k closure...

c.nextprev = function(k){    return function(){ // feel prev , next might backwards... think     if (k === 1) c.prev();       if (k === 5) c.next(); // nothing if k not 1 nor 5  } };  c.timer = window.settimeout(c.nextprev(k), 500); 

...or maybe without preceding code....

here bind sets "this" c.

settimeout( (k === 5)? c.next.bind(c): ((k === 1)? c.prev.bind(c): function(){} ) ); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -