По какой-то причине этот код не работает.
$(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);
}
});
Кто-нибудь здесь знает, почему?
Вы ввели ссылку jQuery UI?
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
с этим 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>
if (!$(e.target).closest(container).length)
. Смотрите: jsfiddle.net/4dbYX