开发者

Display Alert when element passes a certain left position?

I have an element with a fixed position, it's animated with js and it's left position changes from 0 to 1000 randomly.

How can I display an alert each time the element crosses the 500px barrier?

I could only think of making an infinite loop that checks if leftpos < 500px and then using a variable to store whether he is right or left and display the alert when the variable changes but it seems over complicated though maybe i开发者_开发技巧t's the only solution.

Is there a better solution to doing this?


If you are using Javascript to move the element around you can add this check to the re-positioning code.

If it is somebody that drags and drops it, you could use the mouseup to to fire a javascript method to check location.


PHP is server-side code. That mean the code is executed on the server and the output is sent to the client. Therefor, PHP can't do what you want. You need JavaScript. Check out something like jQuery and its position API and maybe a alert plugin if you want to get fancy:

  • Position
  • Alert

Alternatively, you could just use a standard JavaScript alert.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜