我正在用 jQuery 做全屏背景更改系统。当进入站点时,将全屏大小设为默认背景,当单击按钮时必须更改背景。在歌剧上一切正常!但是FireFox没有发生。我认为问题出在 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");
仍然适用于歌剧,但不适用于 Firefox / IE