我想知道如何将背景幻灯片放入其他照片中,例如常规幻灯片。我尝试了很多代码,但还没有成功。
现在,我有一个代码可以将背景更改为不同的照片,这些照片运行良好,但不会褪色。无论如何要加上这个吗?
这是代码
<html>
<head>
<style>
body{
/*Remove below line to make bgimage NOT fixed*/
background-attachment:fixed;
background-repeat: no-repeat;
background-size: cover;
/*Use center center in place of 300 200 to center bg image*/
background-position: 0 0; background-
}
</style>
<script language="JavaScript1.2">
//Background Image Slideshow- © Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com
//Specify background images to slide
var bgslides=new Array()
bgslides[0]="http://i892.photobucket.c…
bgslides[1]="http://i892.photobucket.c…
bgslides[2]="http://i892.photobucket.c…
//Specify interval between slide (in miliseconds)
var speed=2000
//preload images
var processed=new Array()
for (i=0;i<bgslides.length;i++){
processed[i]=new Image()
processed[i].src=bgslides[i]
}
var inc=-1
function slideback(){
if (inc<bgslides.length-1)
inc++
else
inc=0
document.body.background=processed[inc…
}
if (document.all||document.getElementById)
window.onload=new Function('setInterval("slideback()",spee…
</script>
</head>
</html>
如果您有任何建议,请告诉我。另外,我不是最好的编码,也不知道JavaScript,所以请解释一下。
答案 0 :(得分:12)
请改用此代码:(请注意,您需要加载jQuery才能使此代码正常工作)
HTML
<div class="fadein">
<img src="http://farm9.staticflickr.com/8359/8450229021_9d660578b4_n.jpg">
<img src="http://farm9.staticflickr.com/8510/8452880627_0e673b24d8_n.jpg">
<img src="http://farm9.staticflickr.com/8108/8456552856_a843b7a5e1_n.jpg">
<img src="http://farm9.staticflickr.com/8230/8457936603_f2c8f48691_n.jpg">
<img src="http://farm9.staticflickr.com/8329/8447290659_02c4765928_n.jpg">
</div>
CSS
.fadein {
position:relative;
height:320px;
width:320px;
}
.fadein img {
position:absolute;
left:0;
top:0;
}
的JavaScript
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('.fadein img:gt(0)').hide();
setInterval(function () {
$('.fadein :first-child').fadeOut()
.next('img')
.fadeIn()
.end()
.appendTo('.fadein');
}, 4000); // 4 seconds
});
</script>
答案 1 :(得分:-2)
Css内部:
宽度:100%; 身高:100%; 位置:固定;