如何使HTML / CSS幻灯片背景褪色? [英] How to make HTML/CSS slideshow background fade?

查看:208
本文介绍了如何使HTML / CSS幻灯片背景褪色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道你如何做一个背景幻灯片淡出到其他照片像一个普通的幻灯片。我试过很多codeS和尚未成功。

I was wondering how you make a background slideshow fade into other photos like a regular slideshow. I've tried many codes and have yet to be successful.

现在,我有一个code使背景更改为不同的照片效果很好,但它不褪色。反正有添加此?

Now, I have a code to make the background change to different photos which works well, but it doesn't fade. Is there anyway to add this?

下面是code

<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的线索,所以请解释一下该怎么做。

If you have any suggestions please let me know. Also, I am not the greatest at coding and don't have a clue about JavaScript, so please explain what to do.

推荐答案

工作的jsfiddle例子。

使用此code来代替:(请注意,您需要加载 jQuery的为了这个code工作)

Use this code instead: (note that you'll need to load jQuery in order for this code to work)

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的

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>

这篇关于如何使HTML / CSS幻灯片背景褪色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆