其他分享
首页 > 其他分享> > html div随着鼠标位置移动而移动

html div随着鼠标位置移动而移动

作者:互联网

{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>covid-19_US_status</title>
    <link rel="stylesheet" href=" {% static 'bootstrap-3.3.7-dist/css/bootstrap.css' %}">
    <script src="{% static 'bootstrap-3.3.7-dist/js/jquery.min.js' %}"></script>
    <script src="{% static 'bootstrap-3.3.7-dist/js/bootstrap.js' %}"></script>
</head>

<body>

   <button id='click-button' class="btn btn-primary" style="position: absolute">
	简单的按钮
    </button>

    <script>
        $(document).on('mousemove', function(e){
            $('#click-button').css({
               left:  e.pageX,
               top:   e.pageY
            });
        });
    </script>

</body>

</html>

  注意点1:

完成功能的代码如下

    <script>
        $(document).on('mousemove', function(e){
            $('#click-button').css({
               left:  e.pageX,
               top:   e.pageY
            });
        });
    </script>

  注意点2:

div的

position: absolute

标签:function,document,top,html,pageY,div,移动,click,css
来源: https://www.cnblogs.com/ramsey/p/13955823.html