1. 程式人生 > >簡單彈窗

簡單彈窗

osi cto device AC 大小 hid order oct css

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <script src="../public/jquery-3.3.1.min.js" type="text/javascript
" charset="utf-8"></script> <title>Document</title> <style type="text/css"> #tanchu{ width: 300px; height: 300px; border-radius: 5px; background: rgba(0,0,0,0.3); position: absolute; display: none; } .close{ width:10px; height:10px;
float:right; margin-top: 10px; margin-right: 10px; } .close:hover{ cursor: pointer; } </style> </head> <body> <br /><br /><br /><br /><br /><br /><br /> <br /><br /><br /><br /><br /><br /><br /> <button>彈出</button> <div id="
tanchu"> <div class="close">X</div> </div> <br /><br /><br /><br /><br /><br /><br /> <br /><br /><br /><br /><br /><br /><br /> <br /><br /><br /><br /><br /><br /><br /> </body> </html> <script type="text/javascript"> $(document).ready(function(){ var screenwidth,screenheight,tclleft,tctop,scrolltop; loadwz(); $("button").click(function(){ $("#tanchu").show(); }) $(".close").click(function(){ $("#tanchu").hide(); }) $(window).resize(function(){//對當前窗口大小進行計數: loadwz(); }) $(document).scroll(function(){//對元素滾動的次數進行計數: loadwz(); }) }) function loadwz(){ screenwidth = $(window).width(); screenheight = $(window).height(); scrolltop = $(document).scrollTop();// tcleft = (screenwidth-300)/2; tctop = (screenheight-300)/2; $("#tanchu").css({"left":tcleft,"top":tctop+scrolltop}); } </script>

技術分享圖片

效果圖

簡單彈窗