将光标问题集中在Internet Explorer

时间:2017-10-17 11:48:33

标签: javascript html css fade

我有以下代码来自动更新背景图片。

function changeBackground() {
    currentBackground++;
    if(currentBackground > 3) currentBackground = 0;

    $('body').fadeOut(0, function() {
        $('body').css({
            'background-image' : "url('" + backgrounds[currentBackground] + "')"
        });
        $('body').fadeIn(0);
    });


    setTimeout(changeBackground, 3000);

前面有一个简单的表格。在Internet Explorer中,每次图像更改时,此表单焦点似乎都会在Chrome和Firefox中正常运行

1 个答案:

答案 0 :(得分:1)

jQuery的fadeOut将不透明度设置为0 ,然后设置display: none

我认为Internet Explorer在display: none容器内部时会将焦点从表单中移开。

您可以尝试使用animate()代替:

$('body').animate({ opacity: 0}, 0, function() {
    $('body').css({
        'background-image' : "url('" + backgrounds[currentBackground] + "')"
    });
    $('body').animate({ opacity: 1 }, 0);
});

一个问题:你正在使用即时转换(传递持续时间为0),那你为什么要调用fadeIn / fadeOut? (看起来css()调用就足够了)