使用 JavaScript 设置元素是否在未面向屏幕时可见?


使用 JavaScript backfaceVisibility 属性设置元素是否在未面向屏幕时可见。

示例

尝试运行以下代码,以了解如何在 JavaScript 中实现 backfaceVisibility 属性 −

演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 200px;
            height: 300px;
            background: blue;
            color: black;
            animation: mymove 2s infinite linear alternate;
         }
         @keyframes mymove {
            to {transform: rotateY(180deg);}
         }
      </style>
   </head>
   <body>
      <p>Check below to display backface</p>
      <div id="box">
         <h1>Demo</h1>
      </div>
      <input type="checkbox" onclick="display(this)" checked>backfaceVisibility Property
      <script>
         function display(x) {
            if (x.checked === true) {
               document.getElementById("box").style.backfaceVisibility = "visible";
            } else {
               document.getElementById("box").style.backfaceVisibility = "hidden";
            }
         }
      </script>
   </body>
</html>

更新日期:23-6-2020

142 次访问

开启你的 职业

完成课程即可获得认证

开始
广告