CSS3转换在firefox中不触发javascript事件处理程序和函数

CSS3 transform not firing in firefox with javascript event handlers and functions

本文关键字:事件处理 javascript 程序 函数 转换 firefox CSS3      更新时间:2023-09-26

我已经建了一个图库一个月了,布局很简单,左边是缩略图菜单,右边是图库预览。当你点击一个已加载的缩略图时,它会触发一个滑下事件,该事件会折叠缩略图区域并将图库预览扩展到完整尺寸(所有这些都使用CSS3转换)。到目前为止,一切都很完美,除了我创建了一个omouseover事件,当您将鼠标悬停在缩略图上时激活该函数。该函数重新绘制图库预览div ("pics")的内容,并创建三个图像,两个是框架中的上一个图像,一个是框架中的下一个图像(在中心)。在innerHTML中,它将CSS样式"left:"设置为724px或-724px,这取决于它是向前还是向后。然后,当生成所有这些HTML的函数完成后,负责监控开关的函数设置"样式"。Left =" to "0px"。所有这些都适用于safari和chrome浏览器。但是由于某些原因,firefox拒绝动画化这个过渡!我已经研究了这个故障好几天了,什么也没找到,在另一个版本中,我可以在错误的时间切换到fire。但是在firefox中所发生的只是一个从724px到0px的没有过渡的变化。这是我的代码片段。

这将切换缩略图图像并激活转换图像的函数

document.getElementById(thumbid).onmouseover = function() {
    num = parseInt(this.name);
    this.src = image[1][num].src;
    this.style.cursor = "pointer";
    switcher(num, null);
}

这是计算如何切换图像的函数,它设置了一个计时器(在它下面的变量中看到),该计时器接受输入而不更改图像,直到图像完成转换:

function switcher (num, direction) {
    if (direction == 'left') {
        num--;
    } else if (direction == 'right') {
        num++;
    }
    if (num < 0) {
        num = fullcount-1;
    } else if (num == fullcount) {
        num = 0;
    }
    if (intransit == false) {
        drawgallery(num);
        document.getElementById("photos").style.left = "0px";
        intransit = true;
        transittimer = setTimeout("intransit = false; if (transitnumber != null) { switcher(transitnumber, null); transitnumber = null; }", 450);
    } else {
        transitnumber = num;
    }
}
var transittimer = null;
var intransit = false;
var transitnumber = null;

是绘制图库的实际元素start变量变成了left变量。然后afterdrawgallery函数完成自己的切换器将div的"left"设置为0px,在除firefox之外的所有浏览器中,转换转换:

function drawgallery(num) {
    start = 724;
    if (num > curpos) {
    } else {
        start = "-"+start;
    }
    table = "<div id='"photos'" style='"position:absolute; height:470px; top:0px; left:"+start+"px;'">";
    //first square drawn at an X of 0 so that the image remains the same but the drawer can slide over.
    table += "<div id='"i"+orderarr[2][curpos]+"'" style='"overflow:hidden; position:absolute; top:0px; left:-724px; width:724px; height:470px;'">";
    if (curpos <= (totalloaded-1)) {
        table += "<img id='"i"+curpos+"'" src='"image.php?field=pics&id="+orderarr[2][curpos]+"'" style='"border:none; position:relative; top:0px; left:0px;'" />";
    } else {
        table += "<div id='"iloader"+orderarr[2][curpos]+"'" class='"loader'" style='"top:205px;'" ></div>";
    }
    table += "</div>";
    table += "<div id='"i"+orderarr[2][curpos]+"'" style='"overflow:hidden; position:absolute; top:0px; left:724px; width:724px; height:470px;'">";
    if (curpos <= (totalloaded-1)) {
        table += "<img id='"i"+curpos+"'" src='"image.php?field=pics&id="+orderarr[2][curpos]+"'" style='"border:none; position:relative; top:0px; left:0px;'" />";
    } else {
        table += "<div id='"iloader"+orderarr[2][curpos]+"'" class='"loader'" style='"top:205px;'" ></div>";
    }
    table += "</div>";
    /////////////////////////////
    //second square drawn at an X of either negative or positive 724 so that the image remains the same but the drawer can slide over.
    table += "<div id='"i"+orderarr[2][num]+"'" style='"overflow:hidden; position:absolute; top:0px; left:0px; width:724px; height:470px;'">";
    if (curpos <= (totalloaded-1)) {
        table += "<img id='"i"+num+"'" src='"image.php?field=pics&id="+orderarr[2][num]+"'" style='"border:none; position:relative; top:0px; left:0px;'" />";
    } else {
        table += "<div id='"iloader"+orderarr[2][num]+"'" class='"loader'" style='"top:205px;'" ></div>";
    }
    table += "</div>";
    table += "</div>";  
    document.getElementById("pics").innerHTML = table;
    curpos = num;
}

尝试为过渡添加超时。Timeout是transition属性中的最后一个属性。

-moz-transition:all 1s linear 1s;

你的元素应该在那一刻是可见的,所以visibility和display属性应该是block和visible。你可以使用不透明度:0 (filter:alpha(opacity=0) for ie)来隐藏它。