zoukankan      html  css  js  c++  java
  • 拖拽

    var box = document.getElementById('d_box');
    var drop = document.getElementById('drop');
    var box_close = document.getElementById('box_close');

    drop.onmousedown = function(e) {
    e = e || event;
    var x = e.clientX - box.offsetLeft;
    var y = e.clientY - box.offsetTop;
    document.onmousemove = function(e) {
    var boxLeft = e.clientX - x;
    var boxTop = e.clientY - y;
    if(boxLeft < 0) {
    boxLeft = 0;
    } else if(boxLeft > (document.documentElement.clientWidth - box.offsetWidth)){
    boxLeft = document.documentElement.clientWidth - box.offsetWidth;
    }

    if(boxTop < 0) {
    boxTop = 0;
    } else if(boxTop > (document.documentElement.clientHeight - box.offsetHeight)){
    boxTop = document.documentElement.clientHeight - box.offsetHeight;
    }
    box.style.left = boxLeft + "px";
    box.style.top = boxTop + "px";
    }

    document.onmouseup = function (e){
    document.onmousemove = null;

    }
    }
    box_close.onclick = function(){
    this.parentNode.parentNode.style.display = "none";
    }

  • 相关阅读:
    HDOJ 450题留念
    有关VIM的一些笔记
    hdu 2715
    POJ 1004
    链表的创建,添加结点,打印...
    C++ 静态数据成员小谈
    自定义String类
    sizeof/strlen小论
    多态之重载多态运算符重载那些事
    01背包问题
  • 原文地址:https://www.cnblogs.com/pxxdbk/p/12652386.html
Copyright © 2011-2022 走看看