h5+css 实现悬浮框,简单demo

<!DOCTYPE html>
<html>
    <style type="text/css">
        .bigshowbutton {
            display: block;
            position: fixed;
            top: 80%;
            left: 80%;
            border: 1px solid blue;

        }

        .showbutton {
            width: 6.25rem;
            height: 6.25rem;
            border-radius: 50%;
            background-color: skyblue;
            text-align: center;
            cursor: pointer;
            float: right;
            vertical-align: middle;

        }
    </style>
    <head>
        <meta charset="utf-8">
        <title></title>

    </head>
    <body>

        <div id="touchMove" class="bigshowbutton">
            <div id="showDiv"  style="display: inline-block;"></div>
            <!-- <img id="showButton" class="showbutton" src="movePush.gif" /> -->
            <div id="showButton" class="showbutton">
                <div id=""
                style="width: 50px;height: 50px; background-color: aliceblue;margin-top: 25px;margin-left: 25px;border-radius: 10px; border: 1px solid aliceblue;">
                    <div id=""
                    style="width: 40px;height: 40px; background-color: white;  margin-top: 5px; margin-left: 5px;border-radius: 8px; border: 1px solid white;">
                    </div>
                </div>
            </div>

    </body>
</html>
<script>
    window.onload = function() {

        let disx = 0;
        let disy = 0;

        var oDiv = document.getElementById('touchMove');
        var showDiv = document.getElementById("showDiv");
    
        oDiv.onclick = function(e) {
            var aa = document.getElementsByClassName("menu-01");
            console.log(aa.length);
            if(aa.length>0){
                showDiv.innerHTML = "";
            }else{
                showDiv.innerHTML = "";
                html = "<div style='cursor: pointer;' class='menu-01' >aa</div>";
                html = html +"<div style='cursor: pointer;' class='menu-02' >bb</div>";
                html = html +"<div style='cursor: pointer;' class='menu-03' >cc</div>";
                showDiv.innerHTML =  html;
            }
            
            
        };
        
        oDiv.onmousedown = function(e) {
            disx = e.pageX - oDiv.offsetLeft;
            disy = e.pageY - oDiv.offsetTop;
            document.onmousemove = function(e) {
                console.log("move")
                oDiv.style.left = e.pageX - disx + 'px';
                oDiv.style.top = e.pageY - disy + 'px';

            };
            //释放鼠标按钮,将事件清空,否则始终会跟着鼠标移动
            document.onmouseup = function() {
                console.log("up2")
                document.onmousemove = null;
                document.onmousedown = null;

            };
        };


    }
</script>

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值