jQuery:我如何根据您在导航中的位置获得不同的效果

时间:2010-09-20 19:17:31

标签: jquery jquery-plugins jquery-cycle

我有这个:

$('#mask').cycle({ 
    fx: 'scrollLeft',
    timeout: 0, 
    speed:   300, 
    startingSlide: 0 
});

但是有一种情况我想让fx成为scrollRight让我们说什么时候(myCondition == true)

我该怎么做?

3 个答案:

答案 0 :(得分:0)

这应该有用..

(myCondition == true) ? _fx = "scrollLeft" : _fx = "scrollRight";

$('#mask').cycle({ 
    fx: _fx,
    timeout: 0, 
    speed:   300, 
    startingSlide: 0 
});

虽然创建_fx()函数会更聪明。

function _fx(c) {
     return (c == true) ? "scrollLeft" : "scrollRight";
}

答案 1 :(得分:0)

你的意思是:

var myFx = 'scrollLeft';
if( window.location.href.indexOf('myCondition=true') != -1 ) {
    myFx = 'scrollRight';
}

$('#mask').cycle({  
    fx: myFx,
    timeout: 0,  
    speed:   300,  
    startingSlide: 0  
}); 

答案 2 :(得分:0)

我要走出困境并假设要向右滚动,你将fx:更改为scrollRight。在那种情况下

if(myCondition == true) {
      $('#mask').cycle({
               fx: 'scrollRight',
               timeout: 0,
               speed: 300,
               startingSlide: 0
       });
} else {
      $('#mask').cycle({
               fx: 'scrollLeft',
               timeout: 0,
               speed: 300,
               startingSlide: 0
       });
}