zoukankan      html  css  js  c++  java
  • 关于窗口高度于浏览器高度问题

    <!DOCTYPE html>
    <html lang="en">
    <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">
    <title>Document</title>
    <style>
    .shi{
    200px;
    height:200px;
    background:yellow;
    box-shadow: #ccc 0px 0px 10px;
    position:absolute;
    display: none;
    }
    </style>
    </head>
    <body>
    <div class="shi">
    <p>若不是你突然闯进 我生活</p>
    <p>我怎会把死守的寂寞 放任了</p>
    </div>
    <script>
    window.oncontextmenu = function ()
    {
    return false;
    }
    document.onmousedown = function(e){
    let mouse = document.querySelector('.shi');
    let winHeight = document.documentElement.clientHeight; //////窗口高度
    let winWidth = document.documentElement.clientWidth; //////窗口宽度
    let mouseHeight = e.clientY; ////鼠标距离浏览器高度
    let mouseLeft = e.clientX; /////鼠标距离浏览器左侧宽度
    if(e.button == '2'){
    mouse.style.display = 'block';
    if(winHeight - mouseHeight < 200){
    mouse.style.left = mouseLeft - 200 + 'px';
    mouse.style.top = mouseHeight-200 + 'px';
    }else if(winWidth - mouseLeft < 200){
    mouse.style.top = mouseHeight + 'px';
    mouse.style.left = mouseLeft - 200 + 'px'
    }else if(winWidth - mouseLeft > 200){
    mouse.style.left = mouseLeft+'px';
    mouse.style.top = mouseHeight+'px';
    }else if(mouseHeight > 0 && mouseHeight < 200){
    mouse.style.left = mouseLeft - 200 + 'px';
    mouse.style.top = mouseHeight - 200 + 'px';
    }
    }else{
    console.log(winHeight,mouseHeight);
    }
    }
    </script>
    </body>
    </html>
    上下左右都不会有bug的点击弹窗
  • 相关阅读:
    今天同事给介绍了一个LINQ的工具,LINQPad
    wordpress为不同的category添加不同的模板
    robotframework之使用cookies登陆
    robotframework的变量的使用
    robotframework之用户关键字的用法
    robot framework UI自动化之登录
    用U盘完成win10系统的安装
    robot framework 接口自动化之登录
    postman通过引入外部文件实现参数化
    postman连接mysql执行操作
  • 原文地址:https://www.cnblogs.com/MDGE/p/10639098.html
Copyright © 2011-2022 走看看