Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何向 jQuery 添加自定义事件侦听器? 例如:我有一个动画元素,如何添加一个事件侦听器,一旦其坐标等于特定值,它就会应用一些动作?
简短的回答是你不能完全按照你的意愿去做。
但是,您可以获得相同的效果。诀窍是,您需要将“触发器”放在将要改变的事物上。
因此,例如,在您的示例中,一旦对象的坐标处于某个值中,您就希望有一个动画事件。为此,您需要在每次对象移动时检查坐标(在您用于移动对象的任何函数中)。然后如果它们相等,则触发动画功能。