1
我有一個奇怪的情況,我需要在用戶開始拖動它時儘快修改可拖動元素的位置。所以,在可拖動元素的開始事件處理程序中,我試圖設置位置。它不響應位置變化,除非 - 這很奇怪 - 我改變位置後會做一些javascript錯誤。下面是一個例子:如何在JQuery UI Draggable元素的啓動事件處理程序中使css位置更改生效?
<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()不起作用,它們都不是these methods。
這就是我需要什麼。我也需要它只是第一次發生,所以在一次解綁呼叫中折騰了這一點。 – Jim 2009-07-09 19:29:29