更新时间:2023-12-02 21:52:16
由于您列出了您希望每4秒发生一次你可以简单地使用 setInterval()
Since you listed you want this to happen every 4 seconds you can simply use setInterval()
var $post = $(".post");
setInterval(function(){
$post.toggleClass("display");
}, 4000);
注意,选择器缓存在 $中发布
以最小化每个时间间隔内查询DOM所需的次数。
Note, the selector is cached in $post
to minimize the number of times the DOM needs queried on each interval.
Example on jsfiddle