我想更改可拖動項目的大小,如果position.left
超過100個,則返回原始大小。 但如果我添加else
聲明,jqueryUI effect()
不起作用。jQuery UI .effect()在if..else條件下不起作用
$("img").draggable({
axis: "x",
drag: function() {
$("div").html($(this).position().left)
if ($(this).position().left > 100) {
$(this).effect("size", {
to: {
width: 200,
height: 200
}
});
} else {
$(this).effect("size", {
to: {
width: 100,
height: 100
}
});
}
}
});
<link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<img src="http://via.placeholder.com/100" alt="">
<div></div>
但如果我刪除別的工作正常。
$("img").draggable({
axis: "x",
drag: function() {
$("div").html($(this).position().left)
if ($(this).position().left > 100) {
$(this).effect("size", {
to: {
width: 200,
height: 200
}
});
}
}
});
<link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<img src="http://via.placeholder.com/100" alt="">
<div></div>
如何在if..else
語句中使用.effect()
?
感謝您的答覆我真的很感激它,但它沒有達到我想要的。當'position.left'小於100時有一個未知的bug。 –