Мониторинг координат
Доброго времени суток! Ребята есть код(http://cssdeck.com/labs/fgbu1gj7) там координаты заносятся сразу, а не подскажите ли вы, как сделать так что бы они менялись динамически, то есть я хочу что бы они указывали координаты элемента именно в данный момент. Спасибо.
|
$(document).ready(function(){ $(".target").animate({"top": "+=220px"}, 1000, function() { position = $(".target").position(); document.getElementById('xC').value= position.left; document.getElementById('yC').value= position.top; }); }); |
Спасибо за ответ, но тут, как я вижую, функция занесения координат запускается по завершению animate, а цель стоит что бы мониторинг был моментальный, что то вроде того как тут указываются координаты мышки http://shpargalkablog.ru/2013/05/get...nside-div.html
|
Lalked,
:-? <!doctype html> <html> <head> <meta charset="utf-8"> <title>Test</title> <style class="cssdeck">.field{ position:relative; width:400px; height:400px; border:1px solid black; margin:50px; } .target{ width:5px; height:5px; background:red; position:absolute; top:10px; left:10px; } input{ margin-left:50px; }</style></head> <body> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div class="field"> <div class="target"></div> </div> <input type="text" id="xC" value="">X <input type="text" id="yC" value="">Y <script class="cssdeck">$(document).ready(function(){ $(".target").animate({"top": "+=220px", "left" : "+=0"} , {duration: 1000,step: function ( now, fx ) { if(fx.prop == 'left')document.getElementById('xC').value= now if(fx.prop == 'top')document.getElementById('yC').value= now }}) });</script></body> </html> |
Всем, Спасибо большое!
|
Часовой пояс GMT +3, время: 04:06. |