博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用jq深入研究轮播图特性
阅读量:4552 次
发布时间:2019-06-08

本文共 1705 字,大约阅读时间需要 5 分钟。

  网站轮播图 太耳熟的词了  基本上做pc端的 主页绝壁会来一个轮播图的特效

轮播图他一个页面页面的切换,其实的原理是通过css的定位 ,定位到一起,第一张首先显示,其余默认隐藏。

今天我实现的这个轮播仅是一个下面带数字的简单轮播,先搭好框架,以后遇到实际项目可根据这个的原有的基础上,进行调试

第一步

写好html

<div id="banner">

<ul>

<li class="on">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<div id="banner_list">
<a href="#" target="_blank"><img src="imgs/p1.jpg" /></a>
<a href="#" target="_blank"><img src="imgs/p5.jpg" /></a>
<a href="#" target="_blank"><img src="imgs/p3.jpg" /></a>
<a href="#" target="_blank"><img src="imgs/p4.jpg" /></a>
</div>
</div>

第二步写好对应的css

#banner {position:relative; width:478px; height:286px; overflow:hidden;}

#banner ul {position:absolute;list-style-type:none; border:1px solid #fff;z-index:1002;
margin:0; padding:0; bottom:3px; right:5px;}
#banner ul li {float:left;width: 10px;height: 10px;;
display:block;color:#FFF;border:#e5eaff 1px solid;background:red;cursor:pointer}
#banner ul li.on { background:#900}
#banner_list a{position:absolute;}

下面即是javascript的内容了

var t = n = 0, count;

$(document).ready(function(){
count=$("#banner_list a").length;
$("#banner_list a:not(:first-child)").hide();
$("#banner li").click(function() {
var i = $(this).text() - 1;//获取Li元素内的值,即1,2,3,4
n = i;
if (i >= count) return;
$("#banner_list a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
document.getElementById("banner").style.background="";
$(this).toggleClass("on");
$(this).siblings().removeAttr("class");
});
t = setInterval("showAuto()", 4000);
$("#banner").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 4000);});
})

function showAuto()

{
n = n >=(count - 1) ? 0 : ++n;
$("#banner li").eq(n).trigger('click');
}

转载于:https://www.cnblogs.com/guxiaosao/p/4950756.html

你可能感兴趣的文章
第二次作业——个人项目实战
查看>>
HighCharts图表控件在ASP.NET WebForm中的使用
查看>>
C#汉字转拼音
查看>>
Remote Service 和 Local App的交互
查看>>
mysql删除重复数据
查看>>
文件下载工具类
查看>>
Python 定义自己的常量类
查看>>
C++读取文本文件
查看>>
Python 字典排序
查看>>
sql中写标量函数生成大写拼音首字母
查看>>
ASP.NET Core 2.1 : 十五.图解路由(2.1 or earler)
查看>>
服务器返回状态码说明
查看>>
GitHub for Windows提交失败“failed to sync this branch”
查看>>
linux 安装 git
查看>>
Margin
查看>>
完成登录与注册页面的前端
查看>>
centos 源码安装php7
查看>>
Log4j详细教程
查看>>
UVa-1368-DNA序列
查看>>
ConfigParser模块
查看>>