<script>
if(typeof(qsoft) == "undefined")
qsoft = {};
qsoft.PopBigImage = function (origImageId,dx,dy)
{
this.oim = document.getElementById(origImageId);
this.oim.style.cursor = "crosshair";
this.ow = this.oim.width;
this.oh = this.oim.height;
this.detaX = dx?dx : 30;
this.detaY = dy?dy : 0;
this.getAbsSize = function (obj)
{
return obj.getBoundingClientRect();
};
var rect = this.getAbsSize(this.oim);
this.ol = rect.left + this.detaX + this.ow;
this.ot = rect.top + this.detaY;
this.src = this.oim.src;
this.getImageSize = function (img)
{
var im = new Image();
im.src = img.src;
var size = {};
size.width = im.width;
size.height = im.height;
im = null;
delete im;
return size;
};
var rsize = this.getImageSize(this.oim);
this.w = rsize.width;
this.h = rsize.height;
var qObj = this;
this.createMask = function ()
{
if(typeof(this.mask) == "undefined")
{
this.mask = document.createElement("div");
this.mask.id = this.oim.id + "_mask";
this.mask.style.position = "absolute";
this.mask.style.width = this.ow;
this.mask.style.height = this.oh;
this.mask.style.left = this.ol;
this.mask.style.top = this.ot;
this.mask.style.backgroundImage = "url("+this.src+")";
this.mask.style.backgroundRepeat = "no-repeat";
this.mask.style.display ="none";
document.body.appendChild(this.mask);
//this.mask.style = "position: absolute; ";//left: "+this.ol+"; top: "+this.ot+";width: " + this.ow + "; height: " + this.oh + ";
///*display: none;*/ background: url(" + this.src + ") left top no-repeat;";
}
};
this.regEvent = function ()
{
this.oim.onmousemove = function ()
{
var x = Math.ceil(event.offsetX * qObj.w/qObj.ow) - qObj.ow/2;
var y = Math.ceil(event.offsetY * qObj.h/qObj.oh) - qObj.oh/2;
if(x<0) x = 0;
if(y<0) y = 0;
var maxx = Math.ceil((qObj.w-qObj.ow));
var maxy = Math.ceil((qObj.h-qObj.oh));
if(x>maxx) x = maxx;
if(y>maxy) y = maxy;
qObj.mask.style.backgroundPositionX = -x;
qObj.mask.style.backgroundPositionY = -y;
};
this.oim.onmouseout = function (e)
{
qObj.mask.style.display = "none";
};
this.oim.onmouseenter = function (e)
{
qObj.mask.style.display = "block";
};
};
this.render = function ()
{
this.createMask();
this.regEvent();
};
};
qsoft.version = 0.1;
window.onload = function (){
var pbi = new qsoft.PopBigImage("orig",24,-2);
pbi.render();
var pbi1 = new qsoft.PopBigImage("win7",24,-2);
pbi1.render();
}
</script>
<img width="160" height="120" id="orig" src="room_small.jpg" alt="" />
我想实现的功能是产品图片的局部放大功能,但是在火狐下就不能正常运行,在IE下就能运行,请问如何解决这个问题啊。如何让他能在火狐下运行正常啊。请高手指点
if(typeof(qsoft) == "undefined")
qsoft = {};
qsoft.PopBigImage = function (origImageId,dx,dy)
{
this.oim = document.getElementById(origImageId);
this.oim.style.cursor = "crosshair";
this.ow = this.oim.width;
this.oh = this.oim.height;
this.detaX = dx?dx : 30;
this.detaY = dy?dy : 0;
this.getAbsSize = function (obj)
{
return obj.getBoundingClientRect();
};
var rect = this.getAbsSize(this.oim);
this.ol = rect.left + this.detaX + this.ow;
this.ot = rect.top + this.detaY;
this.src = this.oim.src;
this.getImageSize = function (img)
{
var im = new Image();
im.src = img.src;
var size = {};
size.width = im.width;
size.height = im.height;
im = null;
delete im;
return size;
};
var rsize = this.getImageSize(this.oim);
this.w = rsize.width;
this.h = rsize.height;
var qObj = this;
this.createMask = function ()
{
if(typeof(this.mask) == "undefined")
{
this.mask = document.createElement("div");
this.mask.id = this.oim.id + "_mask";
this.mask.style.position = "absolute";
this.mask.style.width = this.ow;
this.mask.style.height = this.oh;
this.mask.style.left = this.ol;
this.mask.style.top = this.ot;
this.mask.style.backgroundImage = "url("+this.src+")";
this.mask.style.backgroundRepeat = "no-repeat";
this.mask.style.display ="none";
document.body.appendChild(this.mask);
//this.mask.style = "position: absolute; ";//left: "+this.ol+"; top: "+this.ot+";width: " + this.ow + "; height: " + this.oh + ";
///*display: none;*/ background: url(" + this.src + ") left top no-repeat;";
}
};
this.regEvent = function ()
{
this.oim.onmousemove = function ()
{
var x = Math.ceil(event.offsetX * qObj.w/qObj.ow) - qObj.ow/2;
var y = Math.ceil(event.offsetY * qObj.h/qObj.oh) - qObj.oh/2;
if(x<0) x = 0;
if(y<0) y = 0;
var maxx = Math.ceil((qObj.w-qObj.ow));
var maxy = Math.ceil((qObj.h-qObj.oh));
if(x>maxx) x = maxx;
if(y>maxy) y = maxy;
qObj.mask.style.backgroundPositionX = -x;
qObj.mask.style.backgroundPositionY = -y;
};
this.oim.onmouseout = function (e)
{
qObj.mask.style.display = "none";
};
this.oim.onmouseenter = function (e)
{
qObj.mask.style.display = "block";
};
};
this.render = function ()
{
this.createMask();
this.regEvent();
};
};
qsoft.version = 0.1;
window.onload = function (){
var pbi = new qsoft.PopBigImage("orig",24,-2);
pbi.render();
var pbi1 = new qsoft.PopBigImage("win7",24,-2);
pbi1.render();
}
</script>
<img width="160" height="120" id="orig" src="room_small.jpg" alt="" />
我想实现的功能是产品图片的局部放大功能,但是在火狐下就不能正常运行,在IE下就能运行,请问如何解决这个问题啊。如何让他能在火狐下运行正常啊。请高手指点
解决方案 »
- javascript里用ajax
- 如何判断汉字是否GB2312汉字
- 请问应该如何学习JAVASCRIPT,有什么好的书籍或者方法推荐一下吗,谢谢~~~
- 请教两个问题,关于时间
- 关于用javascript将数据库中的TEXT类型数据动态赋值到TEXTAREA中。
- <input type="file" ..>要求弹出的对话框只列出.txt文件 在线等!!!
- 高分相求一个正则表达式的写法,加100分!!!!!!!!
- 入门问题
- 论坛回帖提醒插件
- DW上保存的html文件双击后为什么在浏览器上显示一片空白
- d为什么没有赋值到b函数上???
- IE的选项卡不是当前正在看的页面能否用javascript闪动提醒
IE 向...function GetAbsoluteLocationEx(element)
{
if ( arguments.length != 1 || element == null )
{
return null;
}
var elmt = element;
var offsetTop = elmt.offsetTop;
var offsetLeft = elmt.offsetLeft;
var offsetWidth = elmt.offsetWidth;
var offsetHeight = elmt.offsetHeight;
while( elmt = elmt.offsetParent )
{
// add this judge
if ( elmt.style.position == 'absolute' || elmt.style.position == 'relative'
|| ( elmt.style.overflow != 'visible' && elmt.style.overflow != '' ) )
{
break;
}
offsetTop += elmt.offsetTop;
offsetLeft += elmt.offsetLeft;
}
return { absoluteTop: offsetTop, absoluteLeft: offsetLeft,
offsetWidth: offsetWidth, offsetHeight: offsetHeight };
}
{
if ( arguments.length != 1 || element == null )
{
return null;
}
var elmt = element;
var offsetTop = elmt.offsetTop;
var offsetLeft = elmt.offsetLeft;
var offsetWidth = elmt.offsetWidth;
var offsetHeight = elmt.offsetHeight;
while( elmt = elmt.offsetParent )
{
// add this judge
if ( elmt.style.position == 'absolute' || elmt.style.position == 'relative'
|| ( elmt.style.overflow != 'visible' && elmt.style.overflow != '' ) )
{
break;
}
offsetTop += elmt.offsetTop;
offsetLeft += elmt.offsetLeft;
}
return { absoluteTop: offsetTop, absoluteLeft: offsetLeft,
offsetWidth: offsetWidth, offsetHeight: offsetHeight };
} if(typeof(qsoft) == "undefined")
qsoft = {};
qsoft.PopBigImage = function (origImageId,dx,dy)
{
this.oim = document.getElementById(origImageId);
this.oim.style.cursor = "crosshair";
this.ow = this.oim.width;
this.oh = this.oim.height;
this.detaX = dx?dx : 30;
this.detaY = dy?dy : 0;
this.getAbsSize = function (obj)
{
return GetAbsoluteLocationEx(obj);
};
var rect = this.getAbsSize(this.oim);
this.ol = rect.absoluteLeft + this.detaX + this.ow;
this.ot = rect.absoluteTop + this.detaY;
this.src = this.oim.src;
this.getImageSize = function (img)
{
var im = new Image();
im.src = img.src;
var size = {};
size.width = im.width;
size.height = im.height;
im = null;
delete im;
return size;
};
var rsize = this.getImageSize(this.oim);
this.w = rsize.width;
this.h = rsize.height;
var qObj = this;
this.createMask = function ()
{
if(typeof(this.mask) == "undefined")
{
this.mask = document.createElement("div");
this.mask.id = this.oim.id + "_mask";
this.mask.style.position = "absolute";
this.mask.style.width = this.ow;
this.mask.style.height = this.oh;
this.mask.style.left = this.ol;
this.mask.style.top = this.ot;
this.mask.style.backgroundImage = "url("+this.src+")";
this.mask.style.backgroundRepeat = "no-repeat";
this.mask.style.display ="none";
document.body.appendChild(this.mask);
//this.mask.style = "position: absolute; ";//left: "+this.ol+"; top: "+this.ot+";width: " + this.ow + "; height: " + this.oh + ";
///*display: none;*/ background: url(" + this.src + ") left top no-repeat;";
}
};
this.regEvent = function ()
{
this.oim.onmousemove = function (eventTag)
{
var event = window.event||eventTag;
var x = Math.ceil(event.offsetX||event.pageX * qObj.w/qObj.ow) - qObj.ow/2;
var y = Math.ceil(event.offsetY||event.pageY * qObj.h/qObj.oh) - qObj.oh/2;
if(x<0) x = 0;
if(y<0) y = 0;
var maxx = Math.ceil((qObj.w-qObj.ow));
var maxy = Math.ceil((qObj.h-qObj.oh));
if(x>maxx) x = maxx;
if(y>maxy) y = maxy;
qObj.mask.style.backgroundPosition = (-x + "px") + " " + (-y + "px");
};
this.oim.onmouseout = function (e)
{
qObj.mask.style.display = "none";
};
this.oim.onmouseover = function (e)
{
qObj.mask.style.display = "block";
};
};
this.render = function ()
{
this.createMask();
this.regEvent();
};
};
qsoft.version = 0.1;
window.onload = function (){
var pbi = new qsoft.PopBigImage("orig",24,-2);
pbi.render();
}
</script>
<img width="160" height="120" id="orig" src="bear.jpg" alt="" />
还不止那个函数呢.终于改好了.
this.mask.style.height = this.oh;
this.mask.style.left = this.ol;
this.mask.style.top = this.ot;
后面+"PX"试试ECSHOP是啥?没用过...