var homeMove = (function () {

//touch自适应
var k = "ontouchend" in window ? "touchend" : "click";

var isdrag = false;
var moveid = document.getElementById("moveid");
var sWidth = document.body.clientWidth;
var sHeight = document.documentElement.clientHeight; //window.screen.height;
var width = moveid.offsetWidth;
var height = moveid.offsetHeight;
var tx, x;
var ty, y;
var i = 0, j = 0; ;

function movemousex(e) {

  e.preventDefault();

  if (isdrag) {
    var n = tx + e.touches[0].pageX - x;
    var maxWidth = sWidth - width;
    if (n > maxWidth) {
      n = maxWidth;
    } else if (n < 0) {
      n = 0;
    }
    $('#moveid').css("left", n);
    return false;
  }
}

function selectmousex(e) {

  isdrag = true;
  tx = parseInt(moveid.offsetLeft + 0);
  x = e.touches[0].pageX;
  return false;
}

function movemousey(e) {
  e.preventDefault();
  if (isdrag) {
    var n = ty + e.touches[0].pageY - y;
    var maxHeight = sHeight - height;
    if (n > maxHeight) {
      n = maxHeight;
    } else if (n < 0) {
      n = 0;
    }
    $('#moveid').css("top", n);
    return false;
  }
}

function selectmousey(e) {

  isdrag = true;
  ty = parseInt(moveid.offsetTop + 0);
  y = e.touches[0].pageY;
  return false;
}

function addMoveEvent() {
  moveid.addEventListener('touchend', function () {
    isdrag = false;
  });
  moveid.addEventListener('touchstart', selectmousex);
  moveid.addEventListener('touchmove', movemousex, false);
  moveid.addEventListener('touchstart', selectmousey);
  moveid.addEventListener('touchmove', movemousey, false);
  moveid.onclick = function () {
    window.location.href = "/";
  }
}

return { addMoveEvent: addMoveEvent };

} ());

$(function () {
  homeMove.addMoveEvent();
});

最新文章

  1. MVC学习系列8--分页和排序
  2. Android Studio 工具插件
  3. JSP内置对象的解析
  4. CMSIS-DAP调试器
  5. 温习H3C S5500的VLAN配置
  6. Android Studio学习随笔-基本事件(点击)
  7. Windows 7下 搭建 基于 ssh 的sftp 服务器
  8. Swift中文教程(二)--简单值
  9. Android Bitmap 常见的几个操作:缩放,裁剪,旋转,偏移
  10. 介绍一个轻量级iOS安全框架:SSKeyChain
  11. emacs 配置.emacs
  12. 枚举专项练习_Uva725(Division)_Uva11059(Maximun Product)
  13. sublime text 3配置c/c++编译环境
  14. [Database]各数据库连接配置:Oracle:thin 数据库连接/MySQL 连接配置
  15. IE 8 下sharepoint 2013 难看的字体的解决方案
  16. DB2创建function(二)
  17. Linux source命令
  18. EasyGui 学习文档【超详细中文版】
  19. SQL中的函数以及实例
  20. hdu 2031 进制转换(栈思想的使用)

热门文章

  1. ArchLinux安装开源VMware Tools
  2. Web服务器排行:Nginx超越Apache 成为全球
  3. oracle的exp、imp命令
  4. uboot环境变量(设置bootargs向linux内核传递正确的参数)
  5. 添加iis的wolf、wolf2、json支持
  6. 【原】Scala学习资料
  7. 转移python
  8. SIP SDP RTSP RTP RTCP webrtc
  9. oc学习之路----代理模式2-使用步骤
  10. DevExpress GridControl 显示行号、设置行号宽