我正在用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
順便說一句,你可以使用$(function(){});而不是$(document).ready(function(){}); –