Hello, I know in JavaScript you are able to write functions that you can just call at a later time. I'm working on a jQuery UI slider, and I wrote a function for the animation that happens when you start sliding. I would also like this same function to fire for the "change" event, but I can't seem to get it to work.
Here is the shortened code sample:
- $(function(){
- var posterO = $(".poster-slider")
- .slider({
- slide: function(event, ui){ //This is the function I would like to reuse at "change", below
- poster.css(...);
- posterLi.css( ... );
- ptCopy.css( ... );
- sliderValue = ui.value;
- },
- //change:,
- animate:true
- });
- //When "#abundant-trees" link is clicked, the slider handle changes, firing the "change" event, but the "slide" function is not called.
- $("#poster-switcher a[href=#abundant-trees]").click(function(link){
- posterO.slider("value", 100);
- link.preventDefault(); //Stop browser from following the link that was clicked on.
- })
- });
I would like to apply the "slide" function to the "change" event without having to duplicate all the code.