<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>漂浮</title> </head> <style> *{ margin: 0; padding: 0; } .a{ width:100%; height: 50px; background-color: black; /*font-size: 10px;*/ display: block; } .b{ position:fixed; top:0; bottom:0; left:0; right:0; background-color: cornflowerblue; opacity: 0.3; display: none; } .c{ position:fixed; width:300px; height:200px; top:50%; left: 50%; background-color: aliceblue; margin-left: -200px; margin-top: -50px; display: none; } .v{ display: inline-block; } </style> <body> <div class="a"> <button οnclick="push()">push</button> </div> <div class="b"></div> <div class="c"> <button οnclick="cl()">close</button> </div> <script> var ele=document.getElementsByClassName("b")[0]; var ele2=document.getElementsByClassName("c")[0]; function push() { ele.classList.add("v"); ele2.classList.add("v"); } function cl() { ele.classList.remove("v"); ele2.classList.remove("v"); } </script> </body> </html>
js 窗口漂浮练习
最新推荐文章于 2023-05-15 23:08:07 发布