jQuery:如何根据您在导航中的位置产生不同的效果

发布于 2024-09-24 08:48:23 字数 221 浏览 2 评论 0原文

我有这个:

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

但是在某种情况下,我希望 fx 为scrollRight,比如说当(myCondition == true)时

我该怎么做?

I have this:

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

But there is a certain case where I want the fx to be scrollRight lets say when (myCondition == true)

how do I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

各自安好 2024-10-01 08:48:24

你的意思是这样吗:

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

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

do you mean this:

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

$('#mask').cycle({  
    fx: myFx,
    timeout: 0,  
    speed:   300,  
    startingSlide: 0  
}); 
赴月观长安 2024-10-01 08:48:24

我冒险假设要向右滚动,请将 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
       });
}

I'm going out on a limb and assuming that to scroll right you change fx: to scrollRight. In that case

if(myCondition == true) {
      $('#mask').cycle({
               fx: 'scrollRight',
               timeout: 0,
               speed: 300,
               startingSlide: 0
       });
} else {
      $('#mask').cycle({
               fx: 'scrollLeft',
               timeout: 0,
               speed: 300,
               startingSlide: 0
       });
}
滥情空心 2024-10-01 08:48:23

这应该可行。

(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";
}

This should work..

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

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

It would be smarter to make an _fx() function, though..

function _fx(c) {
     return (c == true) ? "scrollLeft" : "scrollRight";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文