<script type="text/javascript">
function carousel_bg(id) {
var bgimgs = ['1920x625_Sonata_homepage_image.jpg', '1920x625_Equus_homepage_image.jpg', '5_home_hero_1920x625_CF_background.jpg']; // add images here..
var img = bgimgs[id];
var cnt = 3; // change this number when adding images..
$('#body').css("background-image", "url(http://www.pitstopmotors.com.ph/images/" + img + ")");
id = id + 1;
if (id == cnt) id = 0;
setTimeout("carousel_bg(" + id + ")", 10000);
}
$(document).ready(function() {
carousel_bg(0);
});
</script>
</head>
<body id="body">
我正在使用上面的代码将我的背景设置为旋转木马,但图像并不完美。谁能帮我在脚本中添加一个函数,让我可以添加这些样式 width: 100%; position:absolute; 顶部:0; 左:0;谢谢
最佳答案
只需在将 css 添加到 #body
元素的地方扩展这一行:
$('#body').css({
"background-image": "url(http://www.pitstopmotors.com.ph/images/" + img + ")",
"position": "absolute",
"top": 0,
"left": 0});
关于javascript - js调整图片大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7116231/