HTML轮播图片代码,带解释

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HTML轮播图片代码,带解释相关的知识,希望对你有一定的参考价值。

参考技术A <!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>五图三屏轮播js特效代码</title>

<meta name="Keywords" content="五图三屏轮播js特效代码" />

<meta name="description" content="五图三屏轮播js特效代码" />

<link href="http://img.chinaz.com/max-templates/passport/styles/topbar.css" type="text/css" rel="Stylesheet" />

<link href="/style/style_kj.css" type="text/css" rel="stylesheet" />

<link href="/style/demo.css" type="text/css" rel="stylesheet" />

<script type="text/javascript" src="/style/js/jquery-1.2.pack.js"></script>

<script type="text/javascript">

var theme_list_open = false;

$(document).ready(function ()

function fixHeight()

var headerHeight = $("#switcher").height();

$("#iframe").attr("height", $(window).height()-84 + "px");



$(window).resize(function ()

fixHeight();

).resize();

//响应式预览

$('.icon-monitor').addClass('active');

$(".icon-mobile-3").click(function ()

$("#by").css("overflow-y", "auto");

$('#iframe-wrap').removeClass().addClass('mobile-width-3');

$('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');

$(this).addClass('active');

return false;

);

$(".icon-mobile-2").click(function ()

$("#by").css("overflow-y", "auto");

$('#iframe-wrap').removeClass().addClass('mobile-width-2');

$('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');

$(this).addClass('active');

return false;

);

$(".icon-mobile-1").click(function ()

$("#by").css("overflow-y", "auto");

$('#iframe-wrap').removeClass().addClass('mobile-width');

$('.icon-tablet,.icon-mobile,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');

$(this).addClass('active');

return false;

);

$(".icon-tablet").click(function ()

$("#by").css("overflow-y", "auto");

$('#iframe-wrap').removeClass().addClass('tablet-width');

$('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');

$(this).addClass('active');

return false;

);

$(".icon-monitor").click(function ()

$("#by").css("overflow-y", "hidden");

$('#iframe-wrap').removeClass().addClass('full-width');

$('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');

$(this).addClass('active');

return false;

);

);

</script>

<script type="text/javascript">

function Responsive($a)

if ($a == true) $("#Device").css("opacity", "100");

if ($a == false) $("#Device").css("opacity", "0");

$('#iframe-wrap').removeClass().addClass('full-width');

$('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');

$(this).addClass('active');

return false;

;

</script>

</head>

<body id="by" style="overflow-y: hidden" >

<div id="switcher">

<div class="center">

<ul>

<li class="logoTop">在线预览!</li>

<div id="Device">

<li class="device-monitor"><a href="javascript:"><div class="icon-monitor"></div></a></li>

<li class="device-mobile"><a href="javascript:"><div class="icon-tablet"> </div></a></li>

<li class="device-mobile"><a href="javascript:"><div class="icon-mobile-1"> </div></a></li>

<li class="device-mobile-2"><a href="javascript:"><div class="icon-mobile-2"> </div></a></li>

<li class="device-mobile-3"><a href="javascript:"><div class="icon-mobile-3"> </div></a></li>

</div>

</ul>

<div class="muen_top">

<a href="/" class="indexactive">首页</a>

<a href="/tupian/" class="l11active" target="_blank">高清图片</a>

<a href="/moban/" class="l12active" target="_blank">模板</a>

<a href="/ppt/" class="l726active" target="_blank">ppt模板</a>

<a href="/tubiao/" class="l49active" target="_blank">图标</a>

<a href="/kuzhan/" class="l713active" target="_blank">酷站</a>

<a href="http://font.chinaz.com/" class="l13active" target="_blank">字体</a>

<a href="/psd/" class="l713active" target="_blank">PSD素材</a>

<a href="/shiliang/" class="l15active" target="_blank">矢量图</a>

<a href="/yinxiao/" class="l713active" target="_blank">音效</a>

<a href="/biaoqing/" class="l560active" target="_blank">表情</a>

<a href="http://desk.chinaz.com/" class="l713active" target="_blank">壁纸</a>

<a href="/donghua/" class="l653active" target="_blank">动画</a>

<a href="/jiaoben/" target="_blank">脚本</a>

<a href="/zhuanti/" target="_blank">专题</a>

</div>

<div class="tougao">

<a href="http://sc.chinaz.com/tougao.html" target="_blank">我要投稿</a>

</div>

</div>

</div>

<div id="iframe-wrap">

<iframe id="iframe" src="http://demo.sc.chinaz.com//Files/DownLoad/webjs1/201604/jiaoben4160/" frameborder="0" width="100%"> </iframe>

</div>

<div id="footer-notice" class="kj_bottom">

<div style=" width:980px; margin:0 auto">

<p class="left cut">

<span>名称:</span>

<a href="/jiaoben/160419378420.htm" title="点击下载" class="down" target="_blank">五图三屏轮播js特效代码</a>

<span>类型:</span>

<a href="/jiaoben/" title="脚本" target="_blank">脚本</a>

<span>标签:</span><a href="/tag_jiaoben/js.html" target="_blank">js</a><a href="/tag_jiaoben/JiuGongGe.html" target="_blank">九宫格</a><a href="/tag_jiaoben/TuPianQieHuan.html" target="_blank">图片切换</a><a href="/tag_jiaoben/TuPianLunBo.html" target="_blank">图片轮播</a>

</p>

<p class="left">

<span>分享到:</span>

<a title='分享到新浪微博' href="javascript:void(0)" id="fxwb" class="sn">新浪</a>

<a title='分享到腾讯微博' href='javascript:void(0)' onclick=posttoWb() class="tx">腾讯</a>

<a title="分享到QQ空间" href="javascript:window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+encodeURIComponent(document.location.href));void(0)" class="qq">QQ空间</a>

</p>

<div class="clear"></div>

</div>

</div>

<script type="text/javascript">

var description = '五图三屏轮播js特效代码: 五图三屏轮播js特效代码是一款ZHIME织蜜内衣丝袜五图三屏图片切换特效。';

var sendT =

getHeader: function ()

var g_title = description;

var re = /<[^<>]*?font[^<>]*?>/gi;

g_title = g_title.replace(re, "");

return g_title;

,

getFirstImgSrc: function ()

var allPageTags = document.getElementsByTagName("div");

for (var i = 0; i < allPageTags.length; i++)

if (allPageTags[i].className == 'downtext')

if (allPageTags[i].getElementsByTagName("img")[0] && allPageTags[i].getElementsByTagName("img")[0].width > 200)

return allPageTags[i].getElementsByTagName("img")[0].src;



else

return null;







,

getContent: function ()

var allPageTagss = document.getElementsByTagName("div");

for (var i = 0; i < allPageTagss.length; i++)

if (allPageTagss[i].className == 'downtext')

return allPageTagss[i].innerHTML;









document.getElementById("fxwb").onclick = function ()

(function (s, d, e, r, l, p, t, z, c)

var f = 'http://service.weibo.com/share/share.php?appkey=872996044&', u = z || d.location, p = ['url=', e(u), '&title=', e(sendT.getHeader()), '&source=', e(r), '&sourceUrl=', e(l), '&content=', c || 'gb2312', '&pic=', e(p || '')].join('');

function a()

if (!window.open([f, p].join(''), 'mb', ['toolbar=0,status=0,resizable=1,width=440,height=430,left=', (s.width - 440) / 2, ',top=', (s.height - 430) / 2].join(''))) u.href = [f, p].join('');

;

if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a();

)(screen, document, encodeURIComponent, 'CHINAZ', 'http://sc.chinaz.com/', sendT.getFirstImgSrc(), null, null, null);



function posttoWb()

var _tt = description;

var _t = encodeURI(_tt.replace(/\s+$/, ''));

var _url = encodeURI(window.location);

var _appkey = encodeURI("258efff116d2466da9b7513cbae7de0b");

var _site = encodeURI('sc.chinaz.com');

var _pic = sendT.getFirstImgSrc();

var _u = 'http://v.t.qq.com/share/share.php?title=' + _t + '&url=' + _url + '&appkey=' + _appkey + '&site=' + _site + '&pic=' + _pic;

window.open(_u, '转播到腾讯微博', 'width=700, height=580, top=320, left=180, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no');



</script>

<script type="text/javascript" src="/js/softinfo.js.aspx?id=534084" defer="defer" charset="UTF-8"></script>

<div style="display:none">

<script src="http://s4.cnzz.com/stat.php?id=300636&web_id=300636" language="JavaScript"></script>

</div>

</body>

</html>
自己修改一下就可以了本回答被提问者和网友采纳

带箭头和圆点的轮播

功能:图片轮播,当鼠标移入图片、圆点和方向键时,停止轮播,移除恢复。

1.首先建立div,并放入图片

css代码
#wai{
	width:300px;
	height: 300px;
	border: 1px solid red;
}	
img{
	width: 100%;
	height: 100%;
	display: none;
}
html代码
<div id="wai" onmouseover="qing()" onmouseout="hui()">
	<img src="timg.jpg"/style="display: block;">
	<img src="timg1.jpg"/>
	<img src="timg2.jpg"/>
	<img src="timg3.jpg"/>
</div>

 技术分享图片

2.添加4个圆点和左右方向

	css代码		
              #dianbox{ height: 15px; width: 70px; position: absolute; border: 1px solid red; left: 120px; top: 270px; } .dian{ width: 10px; height: 10px; border-radius: 50%; margin-left: 4px; border: 1px solid red; float: left; } #lbox{ width: 25px; height: 75px; border: 1px solid red; position: relative; top: -185px; left: 10px; } #rbox{ width: 25px; height: 75px; border: 1px solid red; position: relative; top: -260px; right: -260px; } #l{ width: 25px; height: 25px; border: 2px solid red; border-right: hidden; border-top: hidden; transform: rotate(45deg); margin:20px 10px; } #r{ width: 25px; height: 25px; border: 2px solid red; border-left: hidden; border-bottom: hidden; transform: rotate(45deg); margin:20px -10px; }
    html代码
<!--四个点的div-->
        <div id="dianbox" >
            <div class="dian"style="border-color: green;" onclick="yuan(this,‘0‘)" onmouseover="qing()" onmouseout="hui()">
                
            </div>
            <div class="dian" onclick="yuan(this,‘1‘)" onmouseover="qing()" onmouseout="hui()">
                
            </div>
            <div class="dian" onclick="yuan(this,‘2‘)" onmouseover="qing()" onmouseout="hui()">
                
            </div>
            <div class="dian" onclick="yuan(this,‘3‘)" onmouseover="qing()" onmouseout="hui()">
                
            </div>
        </div>
<!--左箭头div-->
        <div id="lbox" onclick="zuoyou(-1)"onmouseover="qing()" onmouseout="hui()">
            <div id="l">
                
            </div>
        </div>
<!--右箭头div-->
        <div id="rbox" onclick="zuoyou(1)"onmouseover="qing()" onmouseout="hui()">
            <div id="r">
                
            </div>
        </div>

 技术分享图片

3.写js

先定义计时器、写清除计时器函数和恢复计时器函数

定义计时器
var timer = setInterval("lun()",2000);
清除计时器函数
function qing(){
	window.clearInterval(timer);
}
恢复计时器函数
function hui(){
	timer = setInterval("lun()",2000);
}

 写轮播函数并且换图时圆点变色

function lun(){	
//	图片轮播
	bs++;
	var img = document.getElementsByTagName("img");
	if(bs>= img.length){
		bs=0;
	}
	for (i = 0;i<img.length;i++) {
		img[i].style.display="none";
	}
	img[bs].style.display="block";
//	圆点变色
	var dian = document.getElementsByClassName("dian");
	for (j = 0;j < img.length;j++) {
		dian[j].style.borderColor="red";
	}
	dian[bs].style.borderColor="green";
}

 鼠标点击圆点实现圆点变色并切换到相应图片

//点圆换图清除定时器
	function yuan(x,y){
		bs=y;
		var img = document.getElementsByTagName("img");
		for(i = 0;i<img.length;i++){
			img[i].style.display="none";
		}
		img[y].style.display="block";
		var dian = document.getElementsByClassName("dian");
		for (j = 0;j<dian.length;j++) {
			dian[j].style.borderColor="red";
		}
		x.style.borderColor="green";
	}

 鼠标点击方向实现切换到上一张或下一张图片并实现圆点的变化

function zuoyou(z){
	bs=bs+z;
	if(bs==4){
		bs=0;
	}
	if(bs<0){
		bs=3;
	}
	var img = document.getElementsByTagName("img");
	for(i = 0;i<img.length;i++){
		img[i].style.display="none";
	}
	img[bs].style.display="block";
	var dian = document.getElementsByClassName("dian");
	for (j=0;j<dian.length;j++) {
		dian[j].style.borderColor="red";
	}
	dian[bs].style.borderColor="green";
}

 




























以上是关于HTML轮播图片代码,带解释的主要内容,如果未能解决你的问题,请参考以下文章

带箭头和圆点的轮播

jQuery带缩略图轮播效果图片切换带缩略图

淘宝首页宽屏图片轮播代码

用jquery实现带左右按键的轮播图

谁会弄那种12345轮播图片 带链接的 用HTML语言能实现吗. 反正不能用JS.万恶的TX不让用JS. CSS好像可以

淘宝首页的带箭头的轮播海报代码怎么弄