//初始化需要拖拽的列initDrags() {var arr = document.querySelectorAll(".dragged");for (var i = 0, len = arr.length; i < len; i++) {var a = arr[i];this.drag(a);}},// js原生实现拖拽效果drag(sel) {var dragged = typeof sel === "string" ? document.querySelector(sel) : sel;dragged.draggable = true; //开启拖拽属性(不加这句话拖不动)// 开始拖拽dragged.ondragstart = function(event) {var event = event || window.event; //兼容IE浏览器// 鼠标点击物体那一刻相对于物体左侧边框的距离=点击时的位置相对于浏览器最左边的距离-物体左边框相对于浏览器最左边的距离this.diffX = event.clientX - this.offsetLeft;this.diffY = event.clientY - this.offsetTop;};//拖拽中…dragged.ondrag = function(event) {this.setAttribute("dragging", "true"); //拖拽过程变成虚线的样子var event = event || window.event;var x = event.clientX - this.diffX;var y = event.clientY - this.diffY;if (x < 0) {x = 0;} else if (x > innerWidth - this.offsetWidth) {x = innerWidth - this.offsetWidth;}if (y < 0) {y = 0;} else if (y > innerHeight - this.offsetHeight) {y = innerHeight - this.offsetHeight;}this.style.left = x + "px"; //左右拖拽this.style.top = y + "px"; //上下拖拽};//拖拽结束dragged.ondragend = function(event) {this.removeAttribute("dragging"); //取消虚线样式};},
.dragged { transition: none !important;/*禁止选中文本*/-moz-user-select: none;-webkit-user-select: none;-ms-user-select: none;-khtml-user-select: none;user-select: none;cursor: grab !important;&:active {z-index: 1;cursor: grabbing !important;opacity: .618;}&[dragging] {cursor: grabbing !important;background: white !important;border: 1px dashed gray !important;color: gray !important;opacity: 0.9 !important;transform: translate(-3px, -3px);box-shadow: 5px 10px 0 rgba(0, 0, 0, 0.05);}&[animate] {transition: 0.618s ease;}
}
0.1 http://1.metrowin8.sinaapp.com/Code/index.html 拖拽重排实现思路 : 1.初始化拖拽对象时,上传拖拽对象中心点信息(包括id,className) 2.鼠标按下时,制造一个假的拖拽对象 3.鼠标放开时,计算鼠标与拖拽对象中心点的距离,来得到放下元素 4.交换两个元素a,b 克隆a...
//获取某一个cookie的值 const getCookie = key => {var k = key, dc = document.cookie;if (dc.length > 0) {var s = dc.indexOf(k + "=");if (s != -1) {s = s + k.length + 1;var e = d...
var SGheadMapPoints = {/*obj={ maxLng: minLng: maxLat: minLat: maxCount:最大人数 minCount:最小人数 total:点位数量 }*/get: function (obj) {var arr = [];obj.maxCount || (obj.maxCount...
创建index.html代码如下
//自动搜索指定的请柬 var alertTipText = "请柬找到了,就在这个网页里面,自己仔细看吧"; var delay = 1 * 1000;//1秒后循环下一页寻找 /*获取子DOM元素在父元素里面的索引位置(是第几个元素)*/ function getNodeListIndex(childNode) {return c...
获取天气情况(不支持跨域) /*json原生获取*/ function getJSON() {var XML;var url = "http://wthrcdn.etouch.cn/weather_mini?city=杭州";if (window.XMLHttpRequest) {XML = new XMLHttpRequest(...