• js 解决图片不能自由拖动


    <!DOCTYPE html>
    <html lang="">

    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Title Page</title>

        <!-- Bootstrap CSS -->
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
                <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.3/html5shiv.js"></script>
                <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
            <![endif]-->
        <!-- jQuery -->
        <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
        <!-- Bootstrap JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <style>
        div {
            position: absolute;
            left: 0;
            top: 0;
            background: red;
             100px;
            height: 100px;
        }
    </style>

    <body>
        <div><img src="https://www.baidu.com/img/flexible/logo/pc/result.png" ondragstart=true></div>
    </body>
    <script>
        $('div').mousedown(function () {
            e = window.event;

            
            // 重点重点重点重点重点重点重点重点重点重点重点
            if (e.stopPropagation) e.stopPropagation();
            if (e.preventDefault) e.preventDefault();
            e.cancelBubble = true;
            e.returnValue = false;



            $('img').dragstart = false
            x = e.screenX
            y = e.screenY
            left = $('div').css('left')
            tops = $('div').css('top')
            document.onmousemove = function () {
                e = window.event;
                var newx = e.screenX
                var newy = e.screenY
                nowLeft = parseInt(left) + parseInt(newx) - parseInt(x)
                nowTop = parseInt(tops) + parseInt(newy) - parseInt(y)
                $('div').css('left', nowLeft + "px")
                $('div').css('top', nowTop + "px")


            }
            document.onmouseup = function () {
                document.onmousemove = null
                document.mousedown = null
            }


        })
    </script>

    </html>
  • 相关阅读:
    老王python博客
    python中文分词
    python 字典(dict)get方法应用
    python yield和generators(生成器)
    python ASCII返回对应的值(chr)
    python 字符串特点
    python 包的定义,结构,导入过程
    fabric的安装和配置
    python 正则表达式re findall
    python unittest单元测试方法和用例
  • 原文地址:https://www.cnblogs.com/chengfengchi/p/13731488.html
Copyright © 2020-2023  润新知