0

我正在尝试使用此功能设置背景图像:

$('#frame').css('background-image','url(floorplans/img/selectors/floorplates-bg/'+floor+'.png)');

其中 floor 是一个包含 1-7 数字的变量。

它适用于 Chrome、Safari 和 Firefox。但是在 IE 上它没有设置背景图像。.css();在 IE 上可以用吗?

编辑:这是整个脚本:

$('#secondary-nav li').click(function(){
    var floor = $(this).attr('id').replace('f','');


    $('#frame').fadeOut(200);
    $('#secondary-nav li').removeClass('current');

    var currentFloor = '';

    setTimeout(function() {
        currentFloor = '#f' + floor;

        $(currentFloor).addClass('current');

        $('.units').css('display','none');

        var image = 'url(floorplans/img/selectors/floorplates-bg/'+floor+'.png)';


        $('#frame').css('background-image', image);


        $('#frame').fadeIn(200);
        $('#floor'+floor).fadeIn(200);
    }, 500);
});

// highlight on mouseover
 $(".units div a").hover(
        function(){
            $('img',this).stop().animate({'opacity':0},200);
         }, 
        function(){
            $('img',this).stop().animate({'opacity':1},200);
         }
 ); 




// display floorplan
$('.units div').each(function(i){
    var floor = $(this).parent().attr('id').replace('floor','');

    var unit = floor + $(this).attr('class').replace('u','');

    var details = $('a',this).attr('title');

    var group = $('a',this).attr('class').replace('i','');


    $(this).click(function(){
        $('#details .info h1').html('Unit '+unit);
        $('#details .info h2').html(details);
        $('#details .info a').attr('href','floorplans/downloads/'+group+'.pdf');
        $('#details .floorplate img').attr('src','floorplans/img/floorplans/floorplates/Unit-'+unit+'.png');
        $('#details .floorplan img').attr('src','floorplans/img/floorplans/'+group+'.png');
    });
    $(this).fancybox({'href':'#details'});
});
4

2 回答 2

0

Your problem is really unpredictable.

But following are my assumptions:

(1) Never use console.log when you go for production IE, console object is only exposed when the developer tools are opened for a particular tab.

so Remove your console.log.

(2) Are you referring to right folder path?

(3) Usually file path is prefixed with /. So maybe that cause the issue.

(4) Better have something like this:

var imageUrl = 'floorplans/img/selectors/floorplates-bg/'+floor+'.png';   
$('#frame').css('background-image',imageUrl);

Hope within this your problem should exist.

于 2013-07-24T15:47:13.890 回答
0

尝试将该toString()功能添加到您的可变楼层。当我遇到完全相同的问题时,它对我有用;-)

于 2014-01-15T21:23:14.547 回答