代码之家  ›  专栏  ›  技术社区  ›  NullVoxPopuli

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

  •  0
  • NullVoxPopuli  · 技术社区  · 15 年前

    我有这个:

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

    但是有一个特定的例子,我希望fx是scrollRight,比如说when(myCondition==true)

    我该怎么做?

    3 回复  |  直到 15 年前
        1
  •  0
  •   David Titarenco    15 年前

    (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";
    }
    
        2
  •  0
  •   jrharshath    15 年前

    var myFx = 'scrollLeft';
    if( window.location.href.indexOf('myCondition=true') != -1 ) {
        myFx = 'scrollRight';
    }
    
    $('#mask').cycle({  
        fx: myFx,
        timeout: 0,  
        speed:   300,  
        startingSlide: 0  
    }); 
    
        3
  •  0
  •   jon3laze    15 年前

    我要冒险出去,假设要向右滚动你就要改变 fx:

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