zoukankan      html  css  js  c++  java
  • 跟随鼠标的DIV和一连串跟随鼠标的DIV

    1. 跟随鼠标的DIV

     1     window.onmousemove = function(ev) {
     2         //浏览器兼容
     3         var oEvent = ev || event;
     4         var oDiv = document.getElementById("div1");
     5 
     6         //页面滚动的距离
     7         var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
     8         var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
     9         
    10         oDiv.style.top = scrollTop + oEvent.clientY + "px";
    11         oDiv.style.left = scrollLeft + oEvent.clientX + "px";
    12     };

    2. 一连串跟随鼠标的DIV

     1     window.onload = function() {
     2         var divs = document.getElementsByTagName("div");
     3 
     4         window.onmousemove = function(ev) {
     5             var oEvent = ev || event;
     6 
     7             for (var i = divs.length - 1; i > 0; i--) {
     8                 divs[i].style.left = divs[i - 1].style.left;
     9                 divs[i].style.top = divs[i - 1].style.top;
    10             }
    11 
    12             divs[0].style.left = oEvent.clientX + "px";
    13             divs[0].style.top = oEvent.clientY + "px";
    14         }
    15     };
  • 相关阅读:
    javafx DragDropped file
    javafx style and cssFile
    javafx ComboBox Event and change cell color
    javafx clipboard
    javafx Cursor
    javafx DropShadow
    javafx checkbox
    javafx image button
    GNS3连接虚拟机
    cain使用教程
  • 原文地址:https://www.cnblogs.com/HuoAA/p/5074184.html
Copyright © 2011-2022 走看看