帮忙看看 谢谢了
IE是可以的,FF不行,哪里错了<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>drag</title><script type="text/javascript">var neverOnlineMap =
{
_wrapper: null,
_viewer: null,
_X: 0,
_Y: 0,
_width: "100px",
_height: "100px",
_moved: false,
_mapimage: "http://destpic.ctrip.com/Resources/china/hangzhou/map/map_6.gif",init: function(o)
{
this._wrapper=o.wrapper;
this._width=o.width;
this._height=o.height;
this._X=o.x;
this._Y=o.y;
this._mapimage=o.map;
this._viewer=o.viewer;
var x=this._wrapper.style;
x.height=this._height; x.width=this._width; x.cursor="move";
x.backgroundImage="url("+this._mapimage+")";
x.backgroundPositionX=this._X;
x.backgroundPositionY=this._Y;
x.backgroundRepeat="no-repeat";
this._wrapper.onmousedown=this.start;
this._wrapper.onmousemove=this.move;
this._wrapper.onmouseup=this.end;
},start: function(o)
{
var x=neverOnlineMap._wrapper.style;
neverOnlineMap._moved=true;
neverOnlineMap._wrapper.X = event.clientX-parseInt(x.backgroundPositionX);
neverOnlineMap._wrapper.Y = event.clientY-parseInt(x.backgroundPositionY);
neverOnlineMap.view_coordinate({x:x.backgroundPositionX,y:x.backgroundPositionY});
},move: function()
{
if (!neverOnlineMap._moved) return;
var x=neverOnlineMap._wrapper.style;
x.backgroundPositionX=event.clientX-neverOnlineMap._wrapper.X;
x.backgroundPositionY=event.clientY-neverOnlineMap._wrapper.Y;
neverOnlineMap.view_coordinate({x:x.backgroundPositionX,y:x.backgroundPositionY});
neverOnlineMap._wrapper.setCapture();
},end: function()
{
neverOnlineMap._wrapper.releaseCapture();
neverOnlineMap._moved=false;
},view_coordinate: function(o)
{
neverOnlineMap._viewer.innerHTML="坐标 - x:"+o.x+",y:"+o.y;
}}
//]]>
</script>
<body id="www.never-online.net">
<div id="mapwrapper"></div>
<div id="coordinateViewer"></div>
<script type="text/javascript">
//<![CDATA[
(function foo()
{
function getElById(idStr) {
return document.getElementById(idStr);
}
neverOnlineMap.init({
viewer:getElById("coordinateViewer"),
wrapper:getElById("mapwrapper"),
x:0,y:0,width:"150px",
height:"200px",
map:"http://destpic.ctrip.com/Resources/china/hangzhou/map/map_6.gif"
})
}())
//]]>
</script>
</body>
</html>
IE是可以的,FF不行,哪里错了<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>drag</title><script type="text/javascript">var neverOnlineMap =
{
_wrapper: null,
_viewer: null,
_X: 0,
_Y: 0,
_width: "100px",
_height: "100px",
_moved: false,
_mapimage: "http://destpic.ctrip.com/Resources/china/hangzhou/map/map_6.gif",init: function(o)
{
this._wrapper=o.wrapper;
this._width=o.width;
this._height=o.height;
this._X=o.x;
this._Y=o.y;
this._mapimage=o.map;
this._viewer=o.viewer;
var x=this._wrapper.style;
x.height=this._height; x.width=this._width; x.cursor="move";
x.backgroundImage="url("+this._mapimage+")";
x.backgroundPositionX=this._X;
x.backgroundPositionY=this._Y;
x.backgroundRepeat="no-repeat";
this._wrapper.onmousedown=this.start;
this._wrapper.onmousemove=this.move;
this._wrapper.onmouseup=this.end;
},start: function(o)
{
var x=neverOnlineMap._wrapper.style;
neverOnlineMap._moved=true;
neverOnlineMap._wrapper.X = event.clientX-parseInt(x.backgroundPositionX);
neverOnlineMap._wrapper.Y = event.clientY-parseInt(x.backgroundPositionY);
neverOnlineMap.view_coordinate({x:x.backgroundPositionX,y:x.backgroundPositionY});
},move: function()
{
if (!neverOnlineMap._moved) return;
var x=neverOnlineMap._wrapper.style;
x.backgroundPositionX=event.clientX-neverOnlineMap._wrapper.X;
x.backgroundPositionY=event.clientY-neverOnlineMap._wrapper.Y;
neverOnlineMap.view_coordinate({x:x.backgroundPositionX,y:x.backgroundPositionY});
neverOnlineMap._wrapper.setCapture();
},end: function()
{
neverOnlineMap._wrapper.releaseCapture();
neverOnlineMap._moved=false;
},view_coordinate: function(o)
{
neverOnlineMap._viewer.innerHTML="坐标 - x:"+o.x+",y:"+o.y;
}}
//]]>
</script>
<body id="www.never-online.net">
<div id="mapwrapper"></div>
<div id="coordinateViewer"></div>
<script type="text/javascript">
//<![CDATA[
(function foo()
{
function getElById(idStr) {
return document.getElementById(idStr);
}
neverOnlineMap.init({
viewer:getElById("coordinateViewer"),
wrapper:getElById("mapwrapper"),
x:0,y:0,width:"150px",
height:"200px",
map:"http://destpic.ctrip.com/Resources/china/hangzhou/map/map_6.gif"
})
}())
//]]>
</script>
</body>
</html>
是得不到event.clientX的位置的,解决办法就是将event传入。
ff没有setcapture,也需要自行处理下document的事件
此代码是纯的ie 代码,mozilla的标准中没有。其实说实话,也不怪IE搞另类,其实是W3C太简陋。
ent=ent||window.event;
ent.clientX这样就OK了
楼主不会不知道吧???
some.style.backgroundPosition = "left center";
或者some.style.backgroundPosition = "50% center";
等等这些形式设置