首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

JavaScript拖拽图片3

2012-08-17 
JavaScript拖拽图片三现在来解决兼容性问题。首先测试IE6,不通过。:(网上流传的IE不支持事件函数的event参数

JavaScript拖拽图片三

现在来解决兼容性问题。首先测试IE6,不通过。:(

网上流传的IE不支持事件函数的event参数,改用window.event。

经过测试,我的IE6 sp3是支持event参数的。所以类似代码

var ev = e || window.event

并不需要。


但是IE并不支持从div对象中获取currentTarget,而是支持srcElement。所以下面的代码修改一下:

/*global window */function mouseDown(e) {'use strict';window.dragObj = e.currentTarget || e.srcElement;if (window.dragObj !== null) {window.clickLeft = window.event.x - parseInt(window.dragObj.style.left, 10);window.clickTop = window.event.y - parseInt(window.dragObj.style.top, 10);window.dragObj.style.zIndex += 1;}}function mouseStop() {'use strict';window.event.returnValue = false;}function mouseMove() {'use strict';if (window.dragObj !== null) {window.dragObj.style.left = window.event.x - window.clickLeft;window.dragObj.style.top = window.event.y - window.clickTop;}}function mouseUp() {'use strict';window.dragObj = null;}function init() {'use strict';window.dragObj = null;window.document.onmousemove = mouseMove;window.document.onmouseup = mouseUp;window.document.ondragstart = mouseStop;}

现在IE6也支持了。



热点排行