I used $(document).ready
to load script:
$(document).ready(function (){
$('.flexslider').flexslider({
animation: 'fade',
controlsContainer: '.flexslider'
});
});
Next I want to change option "animation" by buttons:
<div class="container span12 menu">
<a id="link-fade" class="menubtn" href="#">FADE</a>
<a id="link-slide" class="menubtn" href="#">SLIDE</a>
</div>
but this not working:
$(document).ready(function (){
$('#link-fade').click(function(){
$('.flexslider').flexslider({
animation: 'fade',
controlsContainer: '.flexslider'
});
return false;
});
$('#link-slide').click(function(){
$('.flexslider').flexslider({
animation: 'slide',
controlsContainer: '.flexslider'
});
return false;
});
});
In my opinion the only way to do it is remove whole element, create new one and call flexslider function with new one. "animation" parameter is used only during initialization of widget.
Whilst this is untested, I did find this small piece of code within the Docs:
Note, this would only work with Flexslider 2.2.0:
Source: FlexSlider Docs https://github.com/woothemes/FlexSlider
As for your code, the second click wouldn't work as Jakub Michálek mentioned within the comments, it's already initialised - you'd have to re-adjust it via the properties that commonly, most plugins/programmers carter for, as long as their variables are publicly adjustable somehow =)
This might be an oldish question, but I figured, since it was one of the first results I got on Google for the problem, I'd share my solution.
@MackieeE's answer got me about halfway (thanks!), but I couldn't find the missing pieces in any one place. What I found solved the problem was to (1) use Flexslider's
start
property to assign a reasonable value - namely the slider object from flexslider - to theflexslider
variable, (2) make that variable global by attaching it to javascript'swindow
object, so that it's reachable from outside the scope of thestart
callback, and then (3) change thevars
property of the slider object to modify the flexslider options. After that, you can change pretty much any property attached to your slider pretty much when- and wherever you like.Complete (example) code below:
Hope this helps anyone else looking for an answer to this or a similar question. :)
Declare your slider and catch object with data... Like this :
Now you can manipulate the stuff after declaration :