Jquery 无法运行两个不同的动画功能

Jquery 无法运行两个不同的动画功能,jquery,html,css,function,jquery-animate,Jquery,Html,Css,Function,Jquery Animate,编辑: 好的,我知道了。非常抱歉,感谢Anthony、Rakesh和Nidhin:问题是因为我在toTheLeft函数中使用了符号+: $inner.animate{'left':'+'+newLeft+'px'},'fast' ------------------^ 我正在开发一个像播放列表一样连续显示视频的系统,我希望用户能够在右/左箭头上单击以显示播放列表中隐藏的视频。很像vimeo.com 问题是,我有两个动画功能,如果我点击右箭头超过2或3次,我就不能再点击左箭头了。我的意思是,它没有

编辑: 好的,我知道了。非常抱歉,感谢Anthony、Rakesh和Nidhin:问题是因为我在toTheLeft函数中使用了符号+:

$inner.animate{'left':'+'+newLeft+'px'},'fast'

------------------^

我正在开发一个像播放列表一样连续显示视频的系统,我希望用户能够在右/左箭头上单击以显示播放列表中隐藏的视频。很像vimeo.com

问题是,我有两个动画功能,如果我点击右箭头超过2或3次,我就不能再点击左箭头了。我的意思是,它没有任何动画效果

以下是我的JS代码:

function toTheLeft(){
        var posLeft = $("#inner").position().left;
        var liWidth = $( ".list" ).outerWidth( true );
        var nLeft   = (liWidth+posLeft);
        if(nLeft > '0') { 
            var newLeft = '0'; 
        } else { 
            var newLeft = nLeft; 
        }
        $( "#inner" ).animate({'left': '+'+ newLeft +'px'}, 'fast' );
    }

    function toTheRight(){
        var posLeft = $("#inner").position().left;
        var liWidth = $( ".list" ).outerWidth( true );
        var inWidth = $("#inner").outerWidth( true ); // get width;
        var posRight = (inWidth + posLeft); // add the two together

        var vWidth  = $("#videos").outerWidth( true );
        var newLeft = (liWidth-posLeft);

        if(posRight > vWidth) {
            $( "#inner" ).animate({'left': '-'+ newLeft +'px'}, 'fast');
        }

    }
$("#left").on( "click", toTheLeft );

$("#right").on( "click", toTheRight );
html代码只有左右两个部分。在我点击2到3次之前,一切都正常。div视频显示5个视频,内部包含10个或更多视频

提前谢谢。这让我发疯。

你可以尝试使用“停止”来停止正在运行的动画


$inner.stop.animate{'left':'+'+newLeft+'px'},'fast'

这是因为您的左值没有改变。。 检查一下这把小提琴的操纵台。。 您的左值保持不变

 var posLeft = $("#inner").position().left;
    var liWidth = $( ".list" ).outerWidth( true );
    var inWidth = $("#inner").outerWidth( true ); // get width;
    var posRight = (inWidth + posLeft); // add the two together

    var vWidth  = $("#videos").outerWidth( true );
    var newLeft = (liWidth-posLeft);
这方面没有价值变化

在控制台打开的情况下检查此JSFIDLE

您已经定义了三次var newLeft。不需要。只需在if条件之外定义var newLeft,而trynewLeft依赖于posLeft,每次单击箭头时它都会发生变化。所以每次函数运行时我都要定义它。那很好……这样你就可以全局定义newLeft,并在不同的函数中使用newLeft的不同值。谢谢,这听起来很愚蠢,但我该怎么做呢抱歉,在jquery中还是新的。明白了!我已经编辑了我的问题。谢谢!谢谢,但它不起作用。我证实了。如果我在同一个箭头上单击两次,它将被阻止。但是如果我点击右箭头,然后点击左箭头,它就可以正常工作了。我真的不明白。也许多点HTML代码会有帮助。你确定你没有双重身份证吗?