gpt4 book ai didi

javascript - 动画播放状态不适用于 Safari

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:11:01 24 4
gpt4 key购买 nike

我不知道出了什么问题,但我遇到的每个错误都与 Safari 相关,而且非常烦人。我的网站上有一个代码,当用户鼠标不在页面主体上时,比如在另一个选项卡中或物理上不在页面上,圆形动画暂停,当用户鼠标再次返回主体时,css 动画恢复它停止的地方。它在 Chrome、Firefox 上完美运行……但在 Safari 上……它有这个蓝色背景,当您离开 body 时弹出,当您返回时它会变得疯狂并立即开始所有颜色。有时它甚至不会在完成后启动,您必须刷新。这是我录制的 gif。

当蓝色背景出现时:

https://gyazo.com/1d063cb8ccce17481df858330b5c8a80

当所有颜色同时开始时:

https://gyazo.com/9b77fe0746c34aeae73af970aec9e75b

它应该是什么样子

https://gyazo.com/cdcebb77327b166d0995b2598938e6d7

这是我的代码。

打码笔 https://codepen.io/anon/pen/dWvwKR

Java 脚本

$("body").on("mouseleave",function(){
console.log("MOUSE IS OUT");
$("#firstCircle").css({"animation-play-state":"paused"});
$("#firstCircle").css({"-webkit-animation-play-state":"paused"});
$("#firstCircle").css({"-ms-animation-play-state":"paused"});
$("#firstCircle").css({"-moz-animation-play-state":"paused"});
$("#firstCircle").css({"-o-animation-play-state":"paused"});

$("#secondCircle").css({"animation-play-state":"paused"});
$("#secondCircle").css({"-webkit-animation-play-state":"paused"});
$("#secondCircle").css({"-ms-animation-play-state":"paused"});
$("#secondCircle").css({"-o-animation-play-state":"paused"});
$("#secondCircle").css({"-moz-animation-play-state":"paused"});

$("#thirdCircle").css({"animation-play-state":"paused"});
$("#thirdCircle").css({"-webkit-animation-play-state":"paused"});
$("#thirdCircle").css({"-ms-animation-play-state":"paused"});
$("#thirdCircle").css({"-moz-animation-play-state":"paused"});
$("#thirdCircle").css({"-o-animation-play-state":"paused"});

$("#fourthCircle").css({"animation-play-state":"paused"});
$("#fourthCircle").css({"-webkit-animation-play-state":"paused"});
$("#fourthCircle").css({"-moz-animation-play-state":"paused"});
$("#fourthCircle").css({"-o-animation-play-state":"paused"});
$("#fourthCircle").css({"-ms-animation-play-state":"paused"});

$("#fifthCircle").css({"animation-play-state":"paused"});
$("#fifthCircle").css({"-webkit-animation-play-state":"paused"});
$("#fifthCircle").css({"-ms-animation-play-state":"paused"});
$("#fifthCircle").css({"-moz-animation-play-state":"paused"});
$("#fifthCircle").css({"-o-animation-play-state":"paused"});

$("#sixthCircle").css({"animation-play-state":"paused"});
$("#sixthCircle").css({"-webkit-animation-play-state":"paused"});
$("#sixthCircle").css({"-o-animation-play-state":"paused"});
$("#sixthCircle").css({"-moz-animation-play-state":"paused"});
$("#sixthCircle").css({"-ms-animation-play-state":"paused"});
});


$(window).on("mouseenter",function(){
console.log("MOUSE IS IN");
$("#firstCircle").css({"animation-play-state":"running"});
$("#firstCircle").css({"-webkit-animation-play-state":"running"});
$("#firstCircle").css({"-ms-animation-play-state":"running"});
$("#firstCircle").css({"-moz-animation-play-state":"running"});
$("#firstCircle").css({"-o-animation-play-state":"running"});

$("#secondCircle").css({"animation-play-state":"running"});
$("#secondCircle").css({"-webkit-animation-play-state":"running"});
$("#secondCircle").css({"-ms-animation-play-state":"running"});
$("#secondCircle").css({"-moz-animation-play-state":"running"});
$("#secondCircle").css({"-o-animation-play-state":"running"});

$("#thirdCircle").css({"animation-play-state":"running"});
$("#thirdCircle").css({"-webkit-animation-play-state":"running"});
$("#thirdCircle").css({"-ms-animation-play-state":"running"});
$("#thirdCircle").css({"-moz-animation-play-state":"running"});
$("#thirdCircle").css({"-o-animation-play-state":"running"});

$("#fourthCircle").css({"animation-play-state":"running"});
$("#fourthCircle").css({"-webkit-animation-play-state":"running"});
$("#fourthCircle").css({"-ms-animation-play-state":"running"});
$("#fourthCircle").css({"-moz-animation-play-state":"running"});
$("#fourthCircle").css({"-o-animation-play-state":"running"});

$("#fifthCircle").css({"animation-play-state":"running"});
$("#fifthCircle").css({"-webkit-animation-play-state":"running"});
$("#fifthCircle").css({"-ms-animation-play-state":"running"});
$("#fifthCircle").css({"-moz-animation-play-state":"running"});
$("#fifthCircle").css({"-o-animation-play-state":"running"});

$("#sixthCircle").css({"animation-play-state":"running"});
$("#sixthCircle").css({"-webkit-animation-play-state":"running"});
$("#sixthCircle").css({"-ms-animation-play-state":"running"});
$("#sixthCircle").css({"-moz-animation-play-state":"running"});
$("#sixthCircle").css({"-o-animation-play-state":"running"});
});


});

最佳答案

您好@thatoneguy90,这是因为 Safari 在 1000 毫秒(1 秒)后暂停非事件选项卡上的 JS 以保留 CPU。您需要解决 setIntervalrequestAnimationFrame 的自动暂停问题。当您滚动到视口(viewport)外时,这也可能导致蓝色。

一定要访问这个,以获取有关如何使其工作的 JS 示例:
How can I make setInterval also work when a tab is inactive in Chrome?

您可能还会发现这有助于获取有关该主题的更多信息:
How do browsers pause/change Javascript when tab or window is not active?

此外,如果这接近最终结果,您也可以使用 CSS 实现。

关于javascript - 动画播放状态不适用于 Safari,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43691545/

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