zoukankan      html  css  js  c++  java
  • 鼠标托动图片移动代码

    <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style type="text/css"> #showdiv{ position:relative; cursor:pointer; }

    </style> <script type="text/javascript"> var ie=document.all;

    var notie=document.getElementById && !document.all;

    var isdrag=false; var x,y;

    var dobj;

    function selectmouse(e){   

    var obj       = notie ? e.target : event.srcElement;

      var topelement = notie ? "HTML" : "BODY";  

    while (obj.tagName != topelement  &&  obj.id != "showdiv")  

    {     obj = notie ? obj.parentNode : obj.parentElement;   }  

    if (obj.id=="showdiv")   {    

    isflag = true;   

      dobj = obj;

        tx = parseInt(dobj.style.left+0);   

      ty = parseInt(dobj.style.top+0);    

    x = notie ? e.clientX : event.clientX;  

       y = notie ? e.clientY : event.clientY;  

       document.onmousemove=move;   

      return false;   } }

    function move(e) {

     if (isflag)  

    {  dobj.style.left = notie ? tx + e.clientX - x : tx + event.clientX - x;  

    dobj.style.top  = notie ? ty + e.clientY - y : ty + event.clientY - y;   return false;

     } } document.onmousedown=selectmouse;

    document.onmouseup=new Function("isflag=false");

    </script> </head>

    <body > <div><img src="images/adver3.jpg" id="showdiv"></div>

    </body> </html>

  • 相关阅读:
    IntelliJIDEA永久注册使用
    并行设计模式(二)-- Master-Worker模式
    Guava之CaseFormat
    solr6.3.0升级与IK动态词库自动加载
    算法思维
    并发库应用之一 & ThreadLocal实现线程范围的共享变量
    filecoin里程碑事件
    博客园 增加打赏功能
    session-token-cookie讲解
    golang原生的RPC实现
  • 原文地址:https://www.cnblogs.com/sunrise/p/3303383.html
Copyright © 2011-2022 走看看