Javascript没有';不能只在firefox中工作
我有一个脚本,悬停在缩略图上,它将显示一个放大的图像。这项工作在IE、Chrome和Safari中都很好。但是在Firefox中,它不能正常工作。它将显示图像,但不会正确地悬停在图像旁边。它将停留在页面上的绝对位置,而不遵循真正的正文值。它应该在一个固定的位置,就像在IE或chrome中一样 我想知道我是否需要添加Mozilla或Firefox特定的异常。这是我的密码:Javascript没有';不能只在firefox中工作,javascript,firefox,mozilla,onmouseover,Javascript,Firefox,Mozilla,Onmouseover,我有一个脚本,悬停在缩略图上,它将显示一个放大的图像。这项工作在IE、Chrome和Safari中都很好。但是在Firefox中,它不能正常工作。它将显示图像,但不会正确地悬停在图像旁边。它将停留在页面上的绝对位置,而不遵循真正的正文值。它应该在一个固定的位置,就像在IE或chrome中一样 我想知道我是否需要添加Mozilla或Firefox特定的异常。这是我的密码: // Simple Image Trail script- By JavaScriptKit.com var offsetf
// Simple Image Trail script- By JavaScriptKit.com
var offsetfrommouse = [15, 10]; //image x,y offsets from cursor position in pixels.
var myimageheight = 250;
var myimagewidth = 250;
if (document.getElementById || document.all) {
document.write('<div id="DynPreviewPlace"></div>');
}
function gettrailobj() {
if (document.getElementById)
return document.getElementById("DynPreviewPlace").style
else if (document.all)
return document.all.DynPreviewPlace.style
}
function gettrailobjnostyle() {
if (document.getElementById)
return document.getElementById("DynPreviewPlace")
else if (document.all)
return document.all.DynPreviewPlace
}
function truebody() {
if (window.getComputedStyle && !window.globalStorage && !window.opera) {
return (!window.chrome && window.getComputedStyle && document.compatMode != "CSS1Compat") ? document.documentElement : document.body
} else if () {} else {
return (!window.chrome && document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}
}
function showtrail(imagename, title, width, height) {
document.onmousemove = followmouse;
(height == 0) ? height = myimageheight : '';
width += 15
height += 30
myimageheight = height
myimagewidth = width
newHTML = '<div class="DynPreviewWraper" style="width:' + width + 'px;"><div id="DynPreviewContainer"><div class="DynPreviewLoader"><div align="center">Loading preview...</div><div class="DynPreviewLoaderBg"><div id="DynProgress"> </div></div></div></div>';
newHTML = newHTML + '<h2 class="DynPreviewTitle">' + ' ' + title + '</h2>'
newHTML = newHTML + '<img onload="javascript:remove_loading();" src="' + imagename + '" class="DynPreviewTempLoad" alt="" />';
newHTML = newHTML + '<!--[if lte IE 6.5]><iframe></iframe><![endif]--></div>';
gettrailobjnostyle().innerHTML = newHTML;
gettrailobj().display = "block";
}
function hidetrail() {
gettrailobj().innerHTML = " ";
gettrailobj().display = "none"
document.onmousemove = ""
gettrailobj().left = "-500px"
}
function followmouse(e) {
var xcoord = offsetfrommouse[0]
var ycoord = offsetfrommouse[1]
var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
var docheight = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
if (typeof e != "undefined") {
if (docwidth - e.pageX < myimagewidth + 2 * offsetfrommouse[0]) {
xcoord = e.pageX - xcoord - myimagewidth;
} else {
xcoord += e.pageX;
}
if (docheight - e.pageY < (myimageheight + 110)) {
ycoord += e.pageY - Math.max(0, (110 + myimageheight + e.pageY - docheight - truebody().scrollTop));
} else {
ycoord += e.pageY;
}
} else if (typeof window.event != "undefined") {
if (docwidth - event.clientX < myimagewidth + 2 * offsetfrommouse[0]) {
xcoord = event.clientX + truebody().scrollLeft - xcoord - myimagewidth;
} else {
xcoord += truebody().scrollLeft + event.clientX
}
if (docheight - event.clientY < (myimageheight + 110)) {
ycoord += event.clientY + truebody().scrollTop - Math.max(0, (110 + myimageheight + event.clientY - docheight));
} else {
ycoord += truebody().scrollTop + event.clientY;
}
}
var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
var docheight = document.all ? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
if (ycoord < 0) {
ycoord = ycoord * -1;
}
gettrailobj().left = xcoord + 'px';
gettrailobj().top = ycoord + 'px';
}
var t_id = setInterval(animate, 20);
var pos = 0;
var dir = 2;
var len = 0;
function animate() {
var elem = document.getElementById('DynProgress');
if (elem != null) {
if (pos == 0) len += dir;
if (len > 32 || pos > 79) pos += dir;
if (pos > 79) len -= dir;
if (pos > 79 && len == 0) pos = 0;
}
}
function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('DynPreviewContainer');
targelem.style.display = 'none';
targelem.style.visibility = 'hidden';
var t_id = setInterval(animate, 60);
}
//简单图像跟踪脚本-由JavaScriptKit.com编写
var offsetfrommouse=[15,10]//图像x、y与光标位置的偏移量(像素)。
var myimageheight=250;
var myimagewidth=250;
if(document.getElementById | | document.all){
文件。写(“”);
}
函数gettrailobj(){
if(document.getElementById)
return document.getElementById(“DynPreviewPlace”).style
else if(document.all)
return document.all.DynPreviewPlace.style
}
函数gettrailobjnostyle(){
if(document.getElementById)
返回文档.getElementById(“DynPreviewPlace”)
else if(document.all)
返回文档.all.DynPreviewPlace
}
函数truebody(){
if(window.getComputedStyle&&!window.globalStorage&&!window.opera){
返回(!window.chrome&&window.getComputedStyle&&document.compatMode!=“CSS1Compat”)?document.documentElement:document.body
}else if(){}else{
返回(!window.chrome&&document.compatMode&&document.compatMode!=“BackCompat”)?document.documentElement:document.body
}
}
函数showtrail(图像名称、标题、宽度、高度){
document.onmousemove=跟随鼠标;
(高度==0)?高度=myimageheight:“”;
宽度+=15
高度+=30
myimageheight=高度
myimagewidth=宽度
newHTML='正在加载预览…';
newHTML=newHTML+''+''+标题+''
newHTML=newHTML+'';
newHTML=newHTML+'';
gettrailobjnostyle().innerHTML=newHTML;
gettrailobj().display=“block”;
}
函数hidetrail(){
gettrailobj().innerHTML=“”;
gettrailobj().display=“无”
document.onmousemove=“”
gettrailobj().left=“-500px”
}
功能跟随鼠标(e){
var xcoord=offsetfrommouse[0]
var ycoord=offsetfrommouse[1]
var docwidth=document.all?truebody().scrollLeft+truebody().clientWidth:pageXOffset+window.innerWidth-15
var docheight=document.all?Math.min(truebody().scrollHeight,truebody().clientHeight):Math.min(window.innerHeight)
如果(类型e!=“未定义”){
if(docwidth-e.pageX32 | | pos>79)pos+=dir;
如果(位置>79)len-=dir;
如果(pos>79&&len==0)pos=0;
}
}
函数remove_loading(){
这个.clearInterval(t_id);
var targetlem=document.getElementById('DynPreviewContainer');
targetlem.style.display='none';
targetlem.style.visibility='hidden';
var t_id=设置间隔(动画,60);
}
这让我快发疯了。我什么都试过了。您可以在此处看到问题所在的页面:
您的truebody函数在不同的环境中运行不同的代码
浏览器。你试过不这样做吗?-Boris Zbarsky 15小时前
我一直在想在那里写些什么。我只是不知道该为firefox/mozilla放些什么。这是唯一有问题的浏览器
我看到Firefox中没有读取truebody,我只是不知道为什么或者如何修复它。如果必须添加扩展,那么所有用户都会这样做。你有任何控制台错误吗?放大的图像在FireFox中对我来说很好。这里也一样。不过,我确实收到了一个错误:“NetworkError:404未找到”-我刚刚编辑了我的条目。图像会显示出来,只是如果你向下滚动页面,它们不会停留在图像旁边。请在IE或chrome中试用。它不计入页面滚动。那将是你的问题。我继续,决定用jquery重写整个过程。这样做会更容易,最终寿命也会更长。