轮播图

<!DOCTYPE html>
<html>
<head>
	<title>轮播图</title>
</head>
<body>
	<!DOCTYPE html>
<html>
<head>
	<script type="text/javascript"></script>
	<script type="text/javascript" src="/static/jQuery/jquery-5.1.1.min.js"></script>
	<title>视频展示效果实例</title>
</head>
<body>
	<div class="v_show">
    <div class="v_caption">
        <h2 class="cartoon" title="卡通动漫">卡通动漫</h2>
        <div class="highlight_tip">
            <span class="current">1</span><span>2</span><span>3</span><span>4</span>
        </div>
        <div class="change_btn">
            <span class="prev" >上一页</span>
            <span class="next">下一页</span>
        </div>
        <em><a href="#">更多>></a></em>
    </div>
    <div class="v_content">
        <div  class="v_content_list">
            <ul>
                <li>
                	<a href="#">
                	<img src="/static/img/01.jpg" alt="海贼王" /></a><h4>
                	<a href="#">海贼王</a></h4>
                	<span>播放:<em>28,276</em></span>
                </li>
                <li>
                	<a href="#">
                	<img src="/static/img/01.jpg" alt="海贼王" /></a><h4>
                	<a href="#">海贼王</a></h4>
                	<span>播放:<em>28,276</em></span>
                </li>
                <li>
                	<a href="#">
                	<img src="/static/img/01.jpg" alt="海贼王" /></a><h4>
                	<a href="#">海贼王</a></h4>
                	<span>播放:<em>28,276</em></span>
                </li>
                <li>
                	<a href="#">
                	<img src="/static/img/01.jpg" alt="海贼王" /></a><h4>
                	<a href="#">海贼王</a></h4>
                	<span>播放:<em>28,276</em></span>
                </li>
                <li>
                	<a href="#">
                	<img src="/static/img/02.jpg" alt="哆啦A梦" /></a><h4>
                	<a href="#">哆啦A梦</a></h4>
                	<span>播放:<em>33,326</em></span>
                	</li>
                <li>
                	<a href="#">
                	<img src="/static/img/02.jpg" alt="哆啦A梦" /></a><h4>
                	<a href="#">哆啦A梦</a></h4>
                	<span>播放:<em>33,326</em></span>
                </li>
                <li>
                	<a href="#">
                	<img src="/static/img/02.jpg" alt="哆啦A梦" /></a><h4>
                	<a href="#">哆啦A梦</a></h4>
                	<span>播放:<em>33,326</em></span>
                </li>
                <li>
                	<a href="#">
                	<img src="/static/img/02.jpg" alt="哆啦A梦" /></a><h4>
                	<a href="#">哆啦A梦</a></h4>
                	<span>播放:<em>33,326</em></span>
                </li>
                <li>
                	<a href="#">
                	<img src="/static/img/03.jpg" alt="火影忍者" /></a><h4>
                	<a href="#">火影忍者</a></h4>
                	<span>播放:<em>28,276</em></span>
                </li>
                <li>
                	<a href="#">
                	<img src="/static/img/03.jpg" alt="火影忍者" /></a><h4>
                	<a href="#">火影忍者</a></h4>
                	<span>播放:<em>28,276</em></span>
                </li>
                <li>
                	<a href="#">
                	<img src="/static/img/03.jpg" alt="火影忍者" /></a><h4>
                	<a href="#">火影忍者</a></h4>
                	<span>播放:<em>28,276</em></span>
                </li>
                <li>
                	<a href="#">
                	<img src="/static/img/03.jpg" alt="火影忍者" /></a><h4>
                	<a href="#">火影忍者</a></h4>
                	<span>播放:<em>28,276</em></span>
                </li>
                <li>
                	<a href="#">
                	<img src="/static/img/04.jpg" alt="龙珠" /></a><h4>
                	<a href="#">龙珠</a></h4>
                	<span>播放 <em>57,865</em></span></li>
                <li>
                	<a href="#">
                	<img src="/static/img/04.jpg" alt="龙珠" /></a><h4>
                	<a href="#">龙珠</a></h4>
                	<span>播放 <em>57,865</em></span></li>
                <li>
                	<a href="#">
                	<img src="/static/img/04.jpg" alt="龙珠" /></a><h4>
                	<a href="#">龙珠</a></h4>
                	<span>播放 <em>57,865</em></span></li>
                <li>
                	<a href="#">
                	<img src="/static/img/04.jpg" alt="龙珠" /></a><h4>
                	<a href="#">龙珠</a></h4>
                	<span>播放 <em>57,865</em></span></li>
             </ul>
        </div>
    </div>
</div>
</body>
</html>
<style type="text/css">
	* { 
		margin:0;
		padding:0;
		word-break:break-all;
	}
	body { 
		background:#FFF; 
		color:#333; 
		font:12px/1.5em Helvetica, Arial, sans-serif; 
	}
	h1, h2, h3, h4, h5, h6 { 
		font-size:1em; 
	}
	a { 
		color:#2B93D2; 
		text-decoration:none; 
	}
	a:hover { 
		color:#E31E1C; 
		text-decoration:underline; 
	}
	ul, li { 
		list-style:none; 
	}
	fieldset, img { 
		border:none; 
	}
	/* v_show style */
	.v_show { 
		width:595px; 
		margin:20px 0 1px 60px; 
	}
	.v_caption { 
		height:35px; 
		overflow:hidden; 
		background:url(/static/img/btn_cartoon.gif) no-repeat 0 0; 
	}
	.v_caption h2 { 
		float:left; 
		width:84px; height:35px; 
		overflow:hidden; 
		background:url(/static/img/btn_cartoon.gif) no-repeat;
		text-indent:-9999px; 
	}
	.v_caption .cartoon { 
		background-position: 0 -100px; 
	}
	.v_caption .variety {
	 	background-position:-100px -100px; 
	}
	.highlight_tip { 
		display:inline; float:left; 
		margin:14px 0 0 10px; 
	}
	.highlight_tip span { 
		display:inline; 
		float:left; width:7px; 
		height:7px; overflow:hidden; 
		margin:0 2px; 
		background:url(/static/img/btn_cartoon.gif) no-repeat 0 -320px; 
		text-indent:-9999px; 
	}
	.highlight_tip .current { 
		background-position:0 -220px; 
	}
	.change_btn { 
		float:left; 
		margin:7px 0 0 10px; 
	}
	.change_btn span { 
		display:block; float:left; 
		width:30px; height:23px; 
		overflow:hidden; 
		background:url(/static/img/btn_cartoon.gif) no-repeat; 
		text-indent:-9999px; 
		cursor:pointer; 
	}
	.change_btn .prev { 
		background-position:0 -400px;  
	}
	.change_btn .next { 
		width:31px; 
		background-position:-30px -400px; 
	}
	.v_caption em { 
		display:inline; 
		float:right; 
		margin:10px 12px 0 0; 
		font-family:simsun;
	}
	.v_content { 
		position:relative; 
		width:592px; height:160px; 
		overflow:hidden; 
		border-right:1px solid #E7E7E7; 
		border-bottom:1px solid #E7E7E7; 
		border-left:1px solid #E7E7E7;
	}
	.v_content_list { 
		position:absolute; 
		width:2500px;
		top:0px; 
		left:0px;
	}
	.v_content ul {
		float:left;
	}
	.v_content ul li { 
		display:inline; 
		float:left; 
		margin:10px 2px 0; 
		padding:8px; 
		background:url(/static/img/v_bg.gif) no-repeat; 
	}
	.v_content ul li a { 
		display:block; 
		width:128px; 
		height:80px; 
		overflow:hidden; 
	}
	.v_content ul li img {  
		width:128px; 
		height:96px; 
	}
	.v_content ul li h4 { 
		width:128px; 
		height:18px; 
		overflow:hidden; 
		margin-top:12px; 
		font-weight:normal; 
	}
	.v_content ul li h4 a { 
		display:inline !important; 
		height:auto !important; 
	}
	.v_content ul li span { 
		color:#666; 
	}
	.v_content ul li em { 
		color:#888; 
		font-family:Verdana; 
		font-size:0.9em; 
	}
</style>
<script type="text/javascript">
	$(function(){
	    var page = 1;
	    var i = 4; //每版放4个图片
    //向后 按钮
    $("span.next").click(function(){    //绑定click事件
        var $parent = $(this).parents("div.v_show");//根据当前点击元素获取到父元素
        var $v_show = $parent.find("div.v_content_list"); //寻找到“视频内容展示区域”
        var $v_content = $parent.find("div.v_content"); //寻找到“视频内容展示区域”外围的DIV元素
        var v_width = $v_content.width() ;
        var len = $v_show.find("li").length;
        var page_count = Math.ceil(len / i) ;   //只要不是整数,就往大的方向取最小的整数
         if( !$v_show.is(":animated") ){    //判断“视频内容展示区域”是否正在处于动画
            if( page == page_count ){  //已经到最后一个版面了,如果再向后,必须跳转到第一个版面。
               $v_show.animate({ left : '0px'}, "slow"); //通过改变left值,跳转到第一个版面
               page = 1;
            }else{
                $v_show.animate({ left : '-='+v_width }, "slow");  //通过改变left值,达到每次换一个版面   ‘-=’,或者'+=':表示当前位置累加或累减
                page++;
            }
        }
        $parent.find("span").eq((page-1)).addClass("current").siblings().removeClass("current");
    });
    //往前 按钮
    $("span.prev").click(function(){
        var $parent = $(this).parents("div.v_show");//根据当前点击元素获取到父元素
        var $v_show = $parent.find("div.v_content_list"); //寻找到“视频内容展示区域”
        var $v_content = $parent.find("div.v_content"); //寻找到“视频内容展示区域”外围的DIV元素
        var v_width = $v_content.width();
        var len = $v_show.find("li").length;
        var page_count = Math.ceil(len / i) ;   //只要不是整数,就往大的方向取最小的整数
        if( !$v_show.is(":animated")){    //判断“视频内容展示区域”是否正在处于动画
            if( page == 1 ){  //已经到第一个版面了,如果再向前,必须跳转到最后一个版面。
              $v_show.animate({ left : '-='+v_width*(page_count-1) }, "slow");
              page = page_count;
        	}else{
            	$v_show.animate({ left : '+='+v_width }, "slow");
           		page--;
       		}
        }
        $parent.find("span").eq((page-1)).addClass("current").siblings().removeClass("current");
    });
});
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现轮播图图片切换背景根据图片颜色渐变的效果,可以使用CSS和JavaScript来实现。下面是一种实现方式的示例代码: HTML部分: ```html <div class="slideshow"> <div class="slide"> <img src="image1.jpg" alt="Image 1"> </div> <div class="slide"> <img src="image2.jpg" alt="Image 2"> </div> <div class="slide"> <img src="image3.jpg" alt="Image 3"> </div> </div> ``` CSS部分: ```css .slideshow { position: relative; } .slide { position: absolute; top: 0; left: 0; opacity: 0; transition: opacity 1s ease-in-out; } .slide.active { opacity: 1; } .slideshow img { width: 100%; height: auto; } .slideshow::before { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(to right, rgba(0,0,0,0.8), rgba(0,0,0,0)); z-index: -1; } ``` JavaScript部分: ```javascript const slides = document.querySelectorAll('.slide'); let currentIndex = 0; function changeSlide() { slides[currentIndex].classList.remove('active'); currentIndex = (currentIndex + 1) % slides.length; slides[currentIndex].classList.add('active'); } setInterval(changeSlide, 3000); ``` 上述代码中,通过CSS设置了轮播图容器的样式以及背景渐变效果。JavaScript部分实现了切换轮播图的逻辑,并使用setInterval函数定时调用changeSlide函数来切换图片。每次切换图片时,会为当前显示的图片添加active类,从而使其显示出来。 你可以根据实际需要修改CSS样式和JavaScript代码,来适应你的项目需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值