<div id="drag">拖动我</div>
#drag{width: 100px; height: 100px; background: red; position: absolute; top: 0; left: 0;cursor:move;}
function addCookie(name, value, iDay) {
var oDate = new Date();
oDate.setDate(oDate.getDate() + iDay);
document.cookie = name + '=' + value + '; path=/; expires=' + oDate;
}
function getCookie(name) {
var arr = document.cookie.split('; ');
for (var i = 0; i < arr.length; i++) {
var arr2 = arr[i].split('=');
return (arr2[0] == name) && arr2[1]
}
return '';
}
window.onload = function () {
var oDiv = document.getElementById('drag');
drag(oDiv);
var move_by = getCookie('move_cood');
if (move_by) {
var str = eval('(' + move_by + ')');
oDiv.style.left = str[0] + 'px';
oDiv.style.top = str[1] + 'px';
}
function drag(obj) {
obj.onmousedown = function (ev) {
var oEvent = ev || event;
var disX = oEvent.clientX - obj.offsetLeft,
disY = oEvent.clientY - obj.offsetTop;
document.onmousemove = function (ev) {
var oEvent = ev || event;
obj.style.left = oEvent.clientX - disX + 'px';
obj.style.top = oEvent.clientY - disY + 'px';
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
obj.releaseCapture && obj.releaseCapture();
addCookie('move_cood', '[' + obj.offsetLeft + ',' + obj.offsetTop + ']', 10);
};
obj.setCapture && obj.setCapture();
return false;
};
}
};
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有