简体   繁体   English

为什么 CSS 在多次打开 Safari 后旋转会随机切换方向,我该如何防止这种情况发生?

[英]Why does CSS rotate randomly switches direction after multiple turns on Safari and how can I prevent this?

I needed to create a card element that always flips in the same direction when clicked and the following snippet does exactly what I want but only when using Chrome and Firefox. When viewing the snippet on Safari both on iOS and MacOS, one encounters a weird issue where after approximately 20 clicks, the card flips randomly back and forth and becomes unpredictable as shown in the attached screen record.我需要创建一个卡片元素,单击时它总是朝同一方向翻转,下面的代码片段完全符合我的要求,但仅当使用 Chrome 和 Firefox 时。在 iOS 和 MacOS 上查看 Safari 上的代码片段时,遇到一个奇怪的问题在大约 20 次点击后,卡片随机来回翻转,并且变得不可预测,如随附的屏幕记录所示。

Is this a known issue and is there anything to prevent this from happening?这是一个已知问题吗?有什么可以防止这种情况发生的吗?

 let rot = 0; function flip() { rot++; const flipContent = document.getElementById("flip").querySelector(".flip-content"); flipContent.style.transform = `rotateX(${rot * 0.5}turn)`; flipContent.style.boxShadow = (rot % 2 === 0)? `20px 20px 10px 0 rgba(0,0,0,0.4)`: `20px -20px 10px 0 rgba(0,0,0,0.4)`; }
 html, body { display: flex; margin: 0; height: 100%; width: 100%; }.flip-card { width: 70vmin; height: 70vmin; margin: auto; background: transparent; perspective: 1000px; transition: scale 0.3s; scale: 90%; cursor: pointer; }.flip-content { width: 100%; height: 100%; transform-style: preserve-3d; transition: all 0.6s ease-in-out; box-shadow: 20px 20px 10px 0 rgba(0,0,0,0.4); }.front-face, .back-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; }.front-face { background-color: blue; }.back-face { background-color: red; transform: rotateX(180deg); }.flip-card:hover { scale: 100%; }
 <body> <div id="flip" class="flip-card" onclick="flip()"> <div class="flip-content"> <div class="front-face"></div> <div class="back-face"></div> </div> </div> </body>
A screen record made on Safari on MacOS that demonstrates the issue 在 MacOS 上 Safari 上制作的屏幕记录演示了该问题

Add the prefix vendor -webkit- for Safari in front of backface-visibility property:backface-visibility属性前添加前缀 vendor -webkit- for Safari:

 .front-face, .back-face { position: absolute; width: 100%; height: 100%; -webkit-backface-visibility: hidden; backface-visibility: hidden; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果选项卡在 ajax 调用完成之前切换,它会影响其他选项卡。 我该如何预防? - if tab switches before ajax call is complete, it effects other tabs. how can I prevent? 为什么 prop('outerHTML') 会剥离事件,我该如何阻止它? - Why does prop('outerHTML') strip events, and how can I prevent it? 计时器为什么停止? 以及如何预防(JavaScript)-iframe - Why does the timer stop? and how can I prevent it (Javascript) - Iframe JavaScript CSS旋转文字方向 - JavaScript CSS rotate text direction 如何使用js或jquery在一个页面中使用多个css切换开关 - How to use multiple css toggle switches in one page with js or jquery 达到一定值后如何反转该正方形的方向? - How can I reverse the direction of this square after it reaches a certain value? 如何编写一个 javascript web 应用程序在移动设备 safari 上查看时不会旋转? - How can I write a javascript web app that doesn't rotate when viewed on mobile safari? 更改背景后如何防止thext褪色? CSS \\ HTML - How can I prevent my thext from fading after changing background? CSS\HTML 如何在画布上旋转图像以面对它的运动方向? - How would i rotate a image on a canvas to face it's direction of movement? 防止移动Safari在x方向上滚动 - prevent mobile safari scroll on x direction
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM