Jquery动画不使用多个参数

时间:2014-03-29 16:21:47

标签: jquery

由于某些原因,此代码无效。

 $(document).mouseup(function (e)
{
    var container = $("#shopping-cart");

    if (!container.is(e.target) // if the target of the click isn't the container...
        && container.has(e.target).length === 0) // ... nor a descendant of the container
    {
        container.hide('slide', {direction: 'left'}, 1400);
    }
});

但是,此代码确实有效。

$(document).mouseup(function (e)
{
    var container = $("#shopping-cart");

    if (!container.is(e.target) // if the target of the click isn't the container...
        && container.has(e.target).length === 0) // ... nor a descendant of the container
    {
        container.hide(500);
    }
});

有没有人知道为什么?

1 个答案:

答案 0 :(得分:0)

您是否插入了jQuery UI链接?

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>

如果点击body div shopping-cart消失,则使用此scode

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
#shopping-cart{
    background-color: #093;
    float: left;
    height: 500px;
    width: 500px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).mouseup(function (e){
    var container = $("#shopping-cart");
    if (!container.is(e.target) && container.has(e.target).length === 0){
        container.hide('slide', {direction: 'left'}, 1400);
    }
});
</script>
</head>
<body>
<div id="shopping-cart">aaaaaa</div>
</body>
</html>