2014-10-04 40 views
0

您好我想創建jQuery腳本,這將是jQuery的動畫DIV的自動更新位置

我已經在這,但這不是更新所有的時間,所有的時間動畫的div自動更新位置

我在這一刻

function start(){ 
    var p = $("#box"); 
    var position = p.position(); 
    $("#box").text("left: " + position.left + ", top: " + position.top); 
} 

回答

0

代碼有沒有你試過一個jQuery這樣的:

$("##box").click(function() { 
$("#imgsrc").animate({ 
opacity: 0.25, 
left: "+=50", 
height: "toggle" 
}, 5000, function() { 
// Animation complete. 
}); 
}); 

用您的圖像源更改#imgsrc。

+0

一下後得到div的位置。現在我明白了,但這不是所有的時間都在更新 – Danny 2014-10-04 09:34:58

0

你會在這個http://pastebin.com/XssfKGT2我希望得到我的動畫DIV的位置動畫

Js Fiddle

function pos() { 
    position = $("#box").position(); 
    $("#box").text("left: " + position.left + ", top: " + position.top); 
} 
pos() 

$('#animate').on('click', function() { 
    $("#box").animate({ 
     left: 40 
    }, function() { 
     pos() 
    }); 
}); 
+0

謝謝:)但是我可以一直得到郵件。當div移動? – Danny 2014-10-04 18:00:05

+0

是檢查這個http://jsfiddle.net/victor_007/L2deyz30/3/ – 2014-10-04 18:10:03