3

Is there a way, in jQuery Cycle, to retrieve a parameter?

Example

$('#slider').cycle({speed: 750})

How can I, in Javascript/jQuery, retreive the value 750?

I tried
console.log( $('#slider').cycle.speed )
console.log( $('#slider').cycle.('speed') )

but the value is undefined

Cœur
  • 37,241
  • 25
  • 195
  • 267
Simon Arnold
  • 15,849
  • 7
  • 67
  • 85

3 Answers3

5

I don't see any plugin commands which allow you to retrieve the value. However, exploring the results with Firebug, it appears that the plugin stores its options under the cycle.opts data attribute. If you really need to get at the value, you can use:

$('#pics').data("cycle.opts").speed

Demo: http://jsfiddle.net/ZWDa4/

Note that this is not an ideal solution since there's no guarantee that it will continue to work with future updates.

Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
1

Should it not be:

console.log($("#slider").cycle("speed"));

Or

var s = $("#slider").cycle();
console.log(s.speed);

Not having it to test means I can't be 100% sure, but all the options are here (as you probably know) http://jquery.malsup.com/cycle/options.html

The final option is to change the approach:

var speed = 750
$("#slider").cycle({"speed: " + speed });

Then you have the speed as a seperate variable?

RemarkLima
  • 11,639
  • 7
  • 37
  • 56
0

You can try with jquery.data(element,key,value) . Eg: jquery.data($('#slider'),cycle,speed)

Gayu
  • 23
  • 6