gpt4 book ai didi

javascript - 在 css 更改时触发的 jQuery 事件

转载 作者:行者123 更新时间:2023-11-29 10:53:03 27 4
gpt4 key购买 nike

我正在使用 .animate 方法在 1 秒内将 div 向右移动 100px。

所以那是每 10 毫秒 1 像素。是否有一个事件会在每次像素移动后触发?或者甚至是每移动 10-20 像素后触发的事件?

上面的例子很简单,我将用它来跟踪多个元素的 left: 属性,并且仅当它们在可见范围内时才计算出何时显示它们浏览器。

最佳答案

step function in animate是你需要的(你必须向下滚动一点)

The second version of .animate() provides a step option — a callback function that is fired at each step of the animation. This function is useful for enabling custom animation types or altering the animation as it is occurring. It accepts two arguments (now and fx), and this is set to the DOM element being animated.

$(something).animate({
..... settings...
},
{
{
step: function(now, fx) {
// where your code goes
}
});

关于javascript - 在 css 更改时触发的 jQuery 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6400977/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com