zoukankan      html  css  js  c++  java
  • 元素拖放

     1             // 获取节点
     2             var block = document.getElementById("right");
     3             var oW, oH;
     4             // 绑定touchstart事件
     5             block.addEventListener("touchstart", function (e) {
     6                 var touches = e.touches[0];
     7                 oW = touches.clientX - block.offsetLeft;
     8                 oH = touches.clientY - block.offsetTop;
     9                 //阻止页面的滑动默认事件
    10                 document.addEventListener("touchmove", defaultEvent(event), false);
    11             }, false);
    12             block.addEventListener("touchmove", function (e) {
    13                 var touches = e.touches[0];
    14                 var oLeft = touches.clientX - oW;
    15                 var oTop = touches.clientY - oH;
    16                 if (oLeft < 0) {
    17                     oLeft = 0;
    18                 } else if (oLeft > document.documentElement.clientWidth - block.offsetWidth) {
    19                     oLeft = (document.documentElement.clientWidth - block.offsetWidth);
    20                 }
    21                 block.style.left = oLeft + "px";
    22                 block.style.top = oTop + "px";
    23             }, false);
    24             block.addEventListener("touchend", function () {
    25                 document.removeEventListener("touchmove", defaultEvent(event), false);
    26             }, false);
    27             function defaultEvent(event) {
    28                 event.preventDefault();
    29             };
  • 相关阅读:
    hdu 4302 Holedox Eating 夜
    poj 1947 Rebuilding Roads 夜
    hdu 4303 Hourai Jeweled 夜
    poj 1286 Necklace of Beads 夜
    poj 2057 The Lost House 夜
    hdu 4301 Divide Chocolate 夜
    poj 3140 Contestants Division 夜
    BOM(二)
    Str的方法
    求出字符窜的字母的个数
  • 原文地址:https://www.cnblogs.com/NB-JDzhou/p/8664105.html
Copyright © 2011-2022 走看看