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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM