我怎样才能得到一个css位置改变一个jQuery UI可拖动元素的开始事件处理过程中生效?
-
12-09-2019 - |
题
我具有奇数的情况中,我需要尽快修改一个可拖动的元件的位置作为用户开始拖动它。因此,可拖动的元素的开始事件处理过程中,我试图设置的位置。这并不位置改变,除非作出回应 - 这是奇怪的 - 我做了什么我改变位置后引起JavaScript错误。下面是一个例子:
<html>
<head>
<title>Drag reposition test</title>
<script type="text/javascript" src="js/css_browser_selector.js"></script>
<script type="text/javascript" src="development-bundle/jquery-1.3.2.js"></script>
<script type="text/javascript" src="development-bundle/ui/jquery-ui-1.7.1.custom.js"></script> <!-- Includes JQuery UI Draggable. -->
<style type="text/css">
#draggable { width: 150px; height: 150px; padding: 0.5em; }
</style>
<script type="text/javascript">
$(function() {
$("#initialdragger").draggable({
start: function(e, ui) {
$('#initialdragger').css('top', 400);
x = y; // Javascript error, which weirdly causes a redraw.
}
});
});
</script>
</head>
<body>
<div id="initialdragger" class="ui-widget-content" style="border-width: 1px; border-color: black; background-color: orange; width: 300px">
<p>Drag me around</p>
</div>
</body>
</html>
我怎样才能合法地导致重绘在这种背景下发生的呢? JQuery的隐藏()和show()不工作也不做这些方法的。
解决方案
我觉得结合mouseDown事件会得到你想要的东西。
<script type="text/javascript">
$(function() {
$("#initialdragger").draggable();
$('#initialdragger').bind("mousedown", function(e) {
$(this).css('top', 400);
});
});
</script>
不隶属于 StackOverflow