我有一个奇怪的情况,我需要在用户开始拖动它时立即修改可拖动元素的位置。因此,在可拖动元素的启动事件处理程序期间,我试图设置位置。它不会响应位置更改,除非 - 这很奇怪 - 我在更改位置后做了一些导致 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 的 hide() 和 show() 不起作用,这些方法也不起作用。