特点:
1、兼容 IE6、FF、Opear(IE7还没有机会测试)
2、拖动流畅
3、起点与终点之间有过渡,使移动更平滑(可调)
演示
/*
Author:misshjn
HomePage:http://www.happyshow.org
Date:2007-04-30
拖动开始
*/
function _getStyle(element,styleProp){
if (element.currentStyle){
var y = element.currentStyle[styleProp];
}else if (window.getComputedStyle){
var y = document.defaultView.getComputedStyle(element,null).getPropertyValue(styleProp.replace(/([A-Z])/g,"-$1").toLowerCase());
}
return y;
}
function _elementOnmouseDown(evt,blockID){
var obj, temp;
obj=document.getElementById(blockID);
var x = evt.clientX || evt.pageX;
var y = evt.clientY || evt.pageY;
obj.startX=x-obj.offsetLeft;
obj.startY=y-obj.offsetTop;
var d = document.createElement("div");
d.style.position = "absolute";
d.style.width = obj.clientWidth + parseInt(_getStyle(obj,"borderLeftWidth"),10) + parseInt(_getStyle(obj,"borderRightWidth")) -2 + "px";
d.style.height = obj.clientHeight + parseInt(_getStyle(obj,"borderTopWidth"),10) + parseInt(_getStyle(obj,"borderBottomWidth")) -2 + "px";
d.style.border = "1px dashed #666";
d.style.top = _getStyle(obj,"top");
d.style.left = _getStyle(obj,"left");
d.style.zIndex = "9999";
document.body.appendChild(d);
document.onmousemove=function(evt){
d.style.left= (evt?evt.pageX:event.clientX) - obj.startX + "px";
d.style.top= (evt?evt.pageY:event.clientY) - obj.startY + "px";
};
document.onmouseup=function(){
var objL = parseInt(_getStyle(obj,"left"),10);
var objT = parseInt(_getStyle(obj,"top"),10);
var obj2L = parseInt(d.style.left,10);
var obj2T = parseInt(d.style.top,10);
var todolist = [];
var level = 10; //元素移动从起点到终点之间过渡的级数,大于0的整数
var speed = 10; //毫秒,每次移动的间隔时间,数字越大,动画感越强,但跳跃感也越大
for (i=1; i<=level; i++){
todolist.push(function(t){
setTimeout(function(){
obj.style.left = objL + (obj2L-objL)*(t/level) + "px";
obj.style.top = objT + (obj2T-objT)*(t/level) + "px";
if(t==i)todolist=null;
},speed*arguments[0]);
});
}
for (i=1; i<=level; i++){
todolist[i-1](i);
}
document.body.removeChild(d);
document.onmousemove = null;
document.onmouseup = null;
};
}
/*
拖动结束
*/
1、兼容 IE6、FF、Opear(IE7还没有机会测试)
2、拖动流畅
3、起点与终点之间有过渡,使移动更平滑(可调)
演示
/*
Author:misshjn
HomePage:http://www.happyshow.org
Date:2007-04-30
拖动开始
*/
function _getStyle(element,styleProp){
if (element.currentStyle){
var y = element.currentStyle[styleProp];
}else if (window.getComputedStyle){
var y = document.defaultView.getComputedStyle(element,null).getPropertyValue(styleProp.replace(/([A-Z])/g,"-$1").toLowerCase());
}
return y;
}
function _elementOnmouseDown(evt,blockID){
var obj, temp;
obj=document.getElementById(blockID);
var x = evt.clientX || evt.pageX;
var y = evt.clientY || evt.pageY;
obj.startX=x-obj.offsetLeft;
obj.startY=y-obj.offsetTop;
var d = document.createElement("div");
d.style.position = "absolute";
d.style.width = obj.clientWidth + parseInt(_getStyle(obj,"borderLeftWidth"),10) + parseInt(_getStyle(obj,"borderRightWidth")) -2 + "px";
d.style.height = obj.clientHeight + parseInt(_getStyle(obj,"borderTopWidth"),10) + parseInt(_getStyle(obj,"borderBottomWidth")) -2 + "px";
d.style.border = "1px dashed #666";
d.style.top = _getStyle(obj,"top");
d.style.left = _getStyle(obj,"left");
d.style.zIndex = "9999";
document.body.appendChild(d);
document.onmousemove=function(evt){
d.style.left= (evt?evt.pageX:event.clientX) - obj.startX + "px";
d.style.top= (evt?evt.pageY:event.clientY) - obj.startY + "px";
};
document.onmouseup=function(){
var objL = parseInt(_getStyle(obj,"left"),10);
var objT = parseInt(_getStyle(obj,"top"),10);
var obj2L = parseInt(d.style.left,10);
var obj2T = parseInt(d.style.top,10);
var todolist = [];
var level = 10; //元素移动从起点到终点之间过渡的级数,大于0的整数
var speed = 10; //毫秒,每次移动的间隔时间,数字越大,动画感越强,但跳跃感也越大
for (i=1; i<=level; i++){
todolist.push(function(t){
setTimeout(function(){
obj.style.left = objL + (obj2L-objL)*(t/level) + "px";
obj.style.top = objT + (obj2T-objT)*(t/level) + "px";
if(t==i)todolist=null;
},speed*arguments[0]);
});
}
for (i=1; i<=level; i++){
todolist[i-1](i);
}
document.body.removeChild(d);
document.onmousemove = null;
document.onmouseup = null;
};
}
/*
拖动结束
*/
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“IE/FireFox具备兼容性的拖动代码”评论...
更新动态
2024年11月15日
2024年11月15日
- 永恒英文金曲精选4《TheBestOfEverlastingFavouritesVol.4》[WAV+CUE]
- 群星《国风超有戏 第9期》[320K/MP3][13.63MB]
- 群星《国风超有戏 第9期》[FLAC/分轨][72.56MB]
- P1X3L《P1X3L》[320K/MP3][143MB]
- 群星.2022-良辰好景知几何电视剧原声带【SONY】【FLAC分轨】
- 庾澄庆.1991-管不住自己【福茂】【WAV+CUE】
- 欧倩怡.2001-Cindy(EP)【华星】【WAV+CUE】
- P1X3L《P1X3L》[FLAC/分轨][791.28MB]
- 茵达INDAHKUS《茵 the Blue》[320K/MP3][33.49MB]
- 茵达INDAHKUS《茵 the Blue》[FLAC/分轨][147.57MB]
- 老虎鱼AnneClarkwithUllavanDaelenJustinCiuche-Borderland-HiRes-Files24bit88.2kHz
- 江玲2004-百合盛开2CD[歌林][WAV+CUE]
- 孙露《怕什么孤单3CD》深圳音像[WAV分轨]
- s14全球总决赛目前是什么结果 s14全球总决赛赛程结果图一览
- s2TPA夺冠五人名单都有谁 tpa战队s2夺冠队员名单一览