• 自作拖拽事件


    varbox=document.getElementById("box");
        box.style.position="absolute";
        box.style.width="160px";
        box.style.height="120px";
        box.style.background="red";
        box.style.left="0px";
        box.style.top="0px";
        //标准化事件
        var mx,my,ox,oy,o;
        function e(event){
                if(!event){
                         event=window.event;
                         event.target=event.srcElement;
                         event.layerX=event.offsetX;
                         event.layerY=event.offsetY;
                }
                event.mx=event.pageX||event.clientX+document.body.scrollLeft;
                event.my=event.pageY||event.clientY+document.body.scrollTop;
                return event;
        }
        document.onmousedown=function(event){
                event=e(event);
                o=event.target;
                ox=parseInt(o.offsetLeft);
                oy=parseInt(o.offsetTop);
                mx=event.mx;
                my=event.my;
                document.onmousemove=move;
                document.onmouseup=stop;
     
        }
        function move(event){
                event=e(event);
                o.style.left=ox+event.mx-mx+"px";
                o.style.top=oy+event.my-my+"px";
        }
        function stop(event){
                event=e(event);
                ox=parseInt(o.offsetLeft);
                oy=parseInt(o.offsetTop);
                mx=event.mx;
                my=event.my;
                o=document.ommousemove=document.onmouseup=null;
        }


  • 相关阅读:
    java 输出质数
    各大OJ
    使用css让图片居中
    poj 1250 Tanning Salon
    Struts2 中整合DWR3实现文件上传
    C语言I博客作业02
    The first essay.
    tar命令
    wBox Demo
    缓存记录
  • 原文地址:https://www.cnblogs.com/blfshiye/p/5170522.html
Copyright © 2020-2023  润新知