jquery - 显示 div 的 x,y 并随着 div 移动更新值

标签 jquery html dom animation

我有一个div在循环中移动(使用jquery)。我能够将 x,y 位置写入页面;但是,只有初始值会写入页面。有没有办法在 div 移动时更新值?

var sun = $j(".sun");
var position = sun.position();
$j(".sun").circulate({
  speed: 3600,
  width: Wwidth,
  height: Wwidth,
  loop: true,
  zIndexValues: [1000, 1000, 1000, 1000]
});
console.log('x: ' + position.left + ' y: ' + position.top);

最佳答案

您可以修改正在使用的循环插件,以便每次更改太阳位置时都会进行回调。或者您可以将您的阅读部分放在 setInterval 语句中:

setInterval(function (){
   var sun = $j(".sun");
   var position = sun.position();
   console.log('x: ' + position.left + ' y: ' + position.top);
},1000); // This code will be runned each 1000 ms, so you can modify it..

关于jquery - 显示 div 的 x,y 并随着 div 移动更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11781376/

相关文章:

python - 如何使用 python HTTPServer 返回 ajax 响应?

javascript - 使用 Javascript 替换 HTML 中的 href 文本

html - firefox 导致 float 问题

javascript - 单击链接提交表单模拟特定按钮

javascript - 选择以 "abc"开头并以 "xyz"结尾的元素

javascript - 经常为 JavaScript 事件处理函数定义的 "event"参数是什么?

javascript - 带滑动的轮播幻灯片 jQuery Bootstrap 3

html - 登录表单太大

C++ 或 Python : Bruteforcing to find text in many webpages

javascript - jQuery:保存异步调用结果以供稍后使用?