2011-02-12 36 views
0

我正在用jQuery做全屏幕背景更改系統。 當進入網站製作全屏大小的默認背景時,點擊按鈕時必須更改背景。一切正常的歌劇作品!但是FireFox並沒有發生。我認爲問題是與attr函數,請幫助找到問題。火狐上的jquery attr

所有這一切都可以在http://www.hiphopdance.lt

$(document).ready(function(){ 
//default actions 
var now_img="images/bg.jpg"; 
resize(1600,900,"#bgimg",now_img); 
$(window).bind("resize", function() { resize(1600,900,"#bgimg"); }); 
//default actions end 

//clicks 
$('li#red').click(function(){ 
$("img#bgimg").attr({src:'http://www.hiphopdance.lt/images/redbg.jpg'}); 
resize(1024,683,"#bgimg"); 
$(window).bind("resize", function() { resize(1024,683,"#bgimg"); }); 
}); 
//end clicks 

//resize function start 
function resize(img_width,img_height,img_id) 
{ 
    var ratio = img_height/img_width;  
    // Get browser window size 
    var browserwidth = $(window).width(); 
    var browserheight = $(window).height(); 
    // Scale the image 
    if ((browserheight/browserwidth) > ratio){ 
     $(img_id).height(browserheight); 
    $(img_id).width(browserheight/ratio); 
    } else { 
    $(img_id).width(browserwidth); 
    $(img_id).height(browserwidth * ratio); 
    } 
    // Center the image 
    $(img_id).css('left', (browserwidth - $(img_id).width())/2); 
    $(img_id).css('top', (browserheight - $(img_id).height())/2); 
}; 
//resize function end   

}); 

感謝的回答看,我一直試圖

$("img#bgimg").attr("src","http://www.hiphopdance.lt/images/redbg.jpg"); 

$("img#bgimg").attr({src:'http://www.hiphopdance.lt/images/redbg.jpg'}); 

變化仍然工作在歌劇,但不在firefo上X/IE

+0

順便說一句,你可以使用$(function(){});而不是$(document).ready(function(){}); –

回答

0
$("img#bgimg").attr("src","http://www.hiphopdance.lt/images/redbg.jpg"); 

鍵,值

您還可以使用Firefox的Firebug,它有一個JavaScript控制檯將返回任何JS錯誤。

+0

謝謝你的回答,但仍然是圖像src不會改變點擊。 – Tomas

+0

@Tomas,讓我們看看你的html。 –

+0

MY SITE
也可以訪問的htt://www.hiphopdance.lt看看;) – Tomas

0

我發現問題了!問題出現在css文件中,因爲後臺有z-index:-1,所有站點z-index:5。我chnaget從5到0.和