简体   繁体   English

IE7,8调用所有错误的功能?

[英]IE7,8 calling all the wrong functions?

Okay, so I'm trying to do some animation. 好吧,所以我想做一些动画。 Here is the test page. 是测试页。

There's a fair quantity of code and I think it's all relevant, so pasting it here might not be worthwhile. 有大量的代码,我认为它们都相关,因此将其粘贴在这里可能不值得。 I can post the function definitions: 我可以发布函数定义:

var ImageLoader = function(c,imagelist,oncomplete) {
    var l = 0, imgs = [], i, loaded = 0;
    for( i in imagelist) {
        l++;
        imgs[i] = new Image();
        imgs[i].style.position = "absolute";
        imgs[i].style.left = "100%";
        c.appendChild(imgs[i]);
        imgs[i].onload = function() {
            loaded++;
            if( loaded == l) oncomplete(imgs);
        };
        imgs[i].onerror = function() {
            alert("Failed to load "+this.src);
        };
        imgs[i].src = imagelist[i];
    }
};
var img2bg = function(c,img) {
    var d = document.createElement('div');
    d.style.width = img.width+"px";
    d.style.height = img.height+"px";
    d.style.backgroundImage = "url('"+img.src+"')";
    d.style.position = "absolute";
    d.style.left = "100%";
    c.appendChild(d);
    return d;
};
var Animate = function(callback,time,thenwhat) {
    var start = new Date().getTime();
    var timer = window.setInterval(function() {
        var now = new Date().getTime();
        var pos = Math.min(1,(now-start)/time);
        if( callback) callback(pos);
        if( pos == 1) {
            clearInterval(timer);
            if( thenwhat) thenwhat();
        }
    },25);
};

However, as I mentioned, this probably isn't very useful on its own. 但是,正如我提到的那样,这本身并不是很有用。

Anyway, on to the point, this animation works perfectly in IE9, IE10, Chrome, Firefox... But in IE8 and 7 it fails miserably. 无论如何,到目前为止,该动画可以在IE9,IE10,Chrome,Firefox中完美运行……但是在IE8和7中,它却失败了。

In the callback function for ImageLoader , I call img2bg on two specific images. ImageLoader的回调函数中,我在两个特定的图像上调用img2bg But for some reason the function is getting called twice for one of the images, and four or five times with no second argument at all. 但是由于某种原因,该函数对于一张图像被调用了两次,而四次或五次都被调用而根本没有第二个参数。 There is literally no other call to img2bg in the entire script, so what gives? 在整个脚本中,实际上没有其他对img2bg调用,那有什么用呢?

Are you sure all the features you are trying to use work in IE7/8? 您确定要在IE7 / 8中使用的所有功能都能正常工作吗? You use opacity which does not. 您使用的不透明度不。 I know background-position was buggy at best. 我知道背景位置充其量是越野车。 You use the html5 doctype so I don't know if that means you might be using html5 elements or APIs, too. 您使用的是html5文档类型,所以我不知道这是否意味着您可能也在使用html5元素或API。 This is what makes me think the problems lie there. 这就是让我认为问题出在这里的原因。

该问题的“解决方案”是对特征进行检测并使动画可选,以便旧的浏览器可以跳过动画或播放更简单的动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM