简体   繁体   English

使用jQuery检测在另一个HTML元素上移动的HTML元素

[英]Detecting a html element moving over another html element using jquery

In my web page i have two square boxes(div tags).The box 'a' starts to animate from left and moves over box 'b' and continues to the end.I want to alert the user when the box 'a' moves over box 'b'.I was able to accomplish this using the co ordinates of both boxes and by using setInterval(function(){ 在我的网页中,我有两个方框(div标签)。方框'a'从左开始动画,移至方框'b'上并继续到结尾。当方框'a'移动时,我想提醒用户在框“ b”上。我能够使用两个框的坐标并使用setInterval(function(){

//code to check the overlap and alert //检查重叠和警告的代码

},1); },1); .I wanted to know if there was another simpler way of doing the same?? 我想知道是否还有另一种更简单的方法? as i consider setInterval(function(){},1); 当我考虑setInterval(function(){},1); is very costly ie to call the function evry millisecond.Any solution regarding this would be of great help.Thanks. 这是非常昂贵的,即调用函数evry毫秒。与此有关的任何解决方案都会有很大帮助。谢谢。

setInterval with an interval of 1 ms will work for you! 间隔为1 ms的setInterval将为您工作! every ms you check to see if box a is within the range of box b, exactly as you suspected 您每检查一次ms,以查看框a是否在框b的范围内,完全与您怀疑的一样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM