轮播图

  1. 图片自动切换(定时器);
  2. 鼠标悬停在图片上图片不切换(清除定时器)
  3. 鼠标悬停在按钮上时显示对应的图片(鼠标悬停事件)
  4. 鼠标悬停在图片上是现实左右箭头
  5. 点击左键切换到上一张图片,但图片为第一张时,点击切换到最后一张图片
  6. 点击右键切换到下一张图片,但图片为最后一张时,点击切换到第一张图片

jquery版本3.4.1

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="css/reset.css" />
<style>
.big{ position: relative;
width: 450px;
height: 270px;
}
#ulimg{
width: 450px;
height: 270px;
overflow: hidden;
}
#ulimg li{float: left;}
#ulimg ul{
width: 500%;
height: 270px;
display: block;
clear: both;
}
#arrows{
position: absolute;
top:90px;
z-index: 5;
width: 100%;
}
.arrow{
width: 30px;
height: 60px;
background-color: #191E2B;
font-size: 25px;
text-align: center;
line-height: 60px;
border-radius: 10px;
color: #FFFFFF;
float: left;
}
#rarrow{
float: right; }
.big #arrows{
position: absolute;
z-index: -1;
transition: z-index 1s;
opacity: 1;
cursor: pointer;
}
.btn{
width: 20px;
height: 20px;
background-color: whitesmoke;
font-size: 18px;
text-align: center;
float: left;
margin: 10px;
border-radius: 5px;
}
#btns{
position: absolute;
z-index: 5;
top: 220px;
left: 220px;
cursor: pointer; }
#btns .btn2{
background: orange;
}
</style>
</head>
<body>
<div class="big">
<div id="ulimg">
<ul>
<li class="now"><img src="img/01.jpg" alt=""/></li>
<li><img src="img/02.jpg" alt=""/></li>
<li><img src="img/03.jpg" alt=""/></li>
<li><img src="img/04.jpg" alt=""/></li>
<li><img src="img/05.jpg" alt=""/></li>
</ul>
</div>
<div id="arrows">
<div class="arrow"><</div>
<div class="arrow" id="rarrow">></div>
</div>
<div id="btns">
<div class="btn btn2">1</div>
<div class="btn">2</div>
<div class="btn">3</div>
<div class="btn">4</div>
<div class="btn">5</div>
</div>
</div>
<script type="text/javascript" src="js/jquery-3.4.1.min.js" ></script>
<script>
var timer=setInterval(change,3000);
var index=1;
function change(){
index++;
if(index>=6){
index=1;
}
$(".btn").removeClass("btn2");
$(".btn").eq(index-1).addClass("btn2");
$("#ulimg ul").animate({
"marginLeft":"-450px"
},1000,function(){
$("#ulimg li:eq(0)").appendTo($(this));
$(this).css("marginLeft",0);
})
}
function lchange(){
$(".btn").removeClass("btn2");
index--;
if(index<=0){
index=5;
}
$(".btn").eq(index-1).addClass("btn2");
$("#ulimg li:eq(4)").prependTo($("#ulimg ul"));
}
function rchange(){
$(".btn").removeClass("btn2");
index++;
if(index>=6){
index=1;
}
$(".btn").eq(index-1).addClass("btn2");
$("#ulimg li:eq(0)").appendTo($("#ulimg ul"));
}
$(".arrow:eq(0)").click(function(){
lchange();
});
$(".arrow:eq(1)").click(function(){
rchange();
});
$(".big").mouseover(function(){
clearInterval(timer);
$("#arrows").css("zIndex",3);
})
$(".big").mouseout(function(){
clearInterval(timer);
timer=setInterval(change,3000);
$("#arrows").css("zIndex",-1);
})
$(".btn").click(function(){
$(".btn").removeClass("btn2");
$(this).addClass("btn2");
var now=$(this).html();
// console.log(now);
// console.log(index);
var btw=now-index;
if(btw<0){
btw=Math.abs(btw);
for(let i=0;i<btw;i++){
lchange();
}
}else if(btw>0){
for(let i=0;i<btw;i++){
rchange();
}
}else{ }
})
</script>
</body>
</html>

javascript版本

html+css

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>轮播图</title>
<link rel="stylesheet" href="css/reset.css" />
<style>
.big{
position: absolute;
width: 450px;
height: 270px;
}
#ulimg li{
position: absolute;
z-index: 1;
opacity: 0;
transition: opacity 1s;
}
#ulimg .now{
position: absolute;
z-index: 2;
opacity: 1;
}
#arrows{
position: absolute;
top:90px;
z-index: 3;
width: 100%;
}
.arrow{
width: 30px;
height: 60px;
background-color: #191E2B;
font-size: 25px;
text-align: center;
line-height: 60px;
border-radius: 10px;
color: #FFFFFF;
float: left;
}
#rarrow{
float: right; }
.big #arrows{
position: relative;
z-index: 1;
transition: z-index 1s;
opacity: 0;
cursor: pointer;
}
.btn{
width: 20px;
height: 20px;
background-color: whitesmoke;
font-size: 18px;
text-align: center;
float: left;
margin: 10px;
border-radius: 5px;
}
#btns{
position: relative;
z-index: 3;
margin-top: 220px;
margin-left: 220px;
cursor: pointer; }
#btns .btn2{
background: orange;
}
</style>
</head>
<body>
<div class="big">
<ul id="ulimg">
<li class="now"><img src="img/01.jpg" alt=""/></li>
<li><img src="img/02.jpg" alt=""/></li>
<li><img src="img/03.jpg" alt=""/></li>
<li><img src="img/04.jpg" alt=""/></li>
<li><img src="img/05.jpg" alt=""/></li>
</ul>
<div id="arrows">
<div class="arrow"><</div>
<div class="arrow" id="rarrow">></div>
</div>
<div id="btns">
<div class="btn btn2">1</div>
<div class="btn">2</div>
<div class="btn">3</div>
<div class="btn">4</div>
<div class="btn">5</div>
</div>
</div>
<script src="js/imgs.js"></script>
</body>
</html>

js

var imgs=document.querySelectorAll("#ulimg li");
var big=document.querySelector(".big");
var index=0;
var timer=setInterval(change,1000);
var arrows=document.getElementById("arrows");
var arrowsbtns=document.getElementsByClassName("arrow");
var btns=document.getElementsByClassName("btn");
function resetbtns(){
for(var i=0;i<imgs.length;i++){
imgs[i].className="";
btns[i].className="btn";
btns[i].setAttribute("onclick","changeimg(this)");
}
}
function change(){
resetbtns();
index++;
if(index>=5){
index=0;
}
imgs[index].className="now";
btns[index].className="btn btn2";
}
big.onmouseover=function stop(){
clearInterval(timer);
arrows.style.zIndex=3;
arrows.style.opacity=1;
}
big.onmouseout=function start(){
clearInterval(timer);
timer=setInterval(change,1000);
arrows.style.zIndex=1;
arrows.style.opacity=0;
}
arrowsbtns[0].onclick=function leftChange(){
resetbtns();
index--;
if(index<=-1){
index=4;
}
imgs[index].className="now";
btns[index].className="btn btn2";
}
arrowsbtns[1].onclick=function rightChange(){
resetbtns();
index++;
if(index>=5){
index=0;
}
imgs[index].className="now";
btns[index].className="btn btn2";
} function changeimg(obj){
resetbtns();
index=obj.innerHTML*1-1;
imgs[index].className="now";
btns[index].className="btn btn2";
}

【jQuery】全功能轮播图的实现(本文结尾也有javascript版)的更多相关文章

  1. jQuery淡入淡出轮播图实现

    大家好我是 只是个单纯的小白,这是人生第一次写博客,准备写的内容是Jquery淡入淡出轮播图实现,在此之前学习JS写的轮播图效果都感觉不怎么好,学习了jQuery里的淡入淡出效果后又写了一次轮播图效果 ...

  2. 用jQuery写的轮播图

    效果图: GitHub地址:https://github.com/123456abcdefg/Javascript 大家可以下载源码查看. 与前一篇写的轮播图实现的效果一致,这个是用jQuery写的, ...

  3. jQuery实现简易轮播图的效果

    (图片素材取自于小米官网) 刚开始接触jQuery的学习,个人觉得如果为了实现多数的动态效果,jQuery的确很简易方便. 下面简易的轮播图效果,还请前辈多多指教~ (努力学习react vue an ...

  4. 用纯css、JavaScript、jQuery简单的轮播图

    完成一个可以自动切换或点击数字的轮播图 HTML代码只需要一个div 包含着一个图片和一个列表,我们主要的思路就是通过点击相应的数字,改变图片的 路径. 有4张图片都在img文件夹里,名称为  img ...

  5. JQuery实现一个轮播图

    1.HTML <div class="banner"> <div class="b_main"> <div class=" ...

  6. 记录一下自己用jQuery写的轮播图

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. jquery淡入淡出轮播图

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. 使用JQuery制作幻灯片(轮播图)

    1.首先看一下目录结构 images文件夹放所需要播放的图片. js文件夹放jquery库和main.js 2.html代码: <!DOCTYPE html> <html lang= ...

  9. jquery 移动端轮播图

    <div class="slide"> <div class="slide-box"> <ul class="slide ...

随机推荐

  1. Spring杂谈 | Spring中的AutowireCandidateResolver

    接口定义 用于推断一个特定的beanDefinition是否能作为指定依赖的候选者的策略接口 public interface AutowireCandidateResolver { // 默认情况下 ...

  2. 【x64软路由】OpenWrt(LEDE) 20200329编译 反追踪 抗污染 加速 PSW 无缝集成 UPnP NAS

    固件说明 基于Lede OpenWrt R2020.3.19版本(源码更新截止20200329)Lienol Feed及若干自行维护的软件包 结合家庭x86软路由场景需要定制 按照家庭应用场景对固件及 ...

  3. 假如用王者荣耀的方式学习webpack

    英雄介绍 崴博.派克诞生于遥远西方的勇士之地,拥有着高超的机械技艺,善于运用各种工具来实现一些看似不可能完成的事.游历王者大陆时机缘巧合遇到了年轻的墨子,与之成为好友.后协助大宗师墨子建造了大陆第一雄 ...

  4. 通过PAML中的CODEML模块计算dnds的过程以及踩坑

    最近帮女朋友做毕业设计的时候用到了 PAML这个软件的codeml功能,发现网上相关的资料很少,于是把自己踩的一些坑分享一下,希望能帮到其他有相同困难的人 一.下载与安装 PAML软件下载地址 htt ...

  5. A~Z;26个字母美式

    26个字母美式读法 音频下载地址: 链接:https://pan.baidu.com/s/1KOlxNCydgtsODQZMT9JFJg 提取码:8a9g

  6. python --error整理(不定时更新)

    1.TabError: inconsistent use of tabs and spaces in indentation Python 中需要用tab 键来空格 2.SyntaxError: in ...

  7. Universalimageloader 原图片大小获取

    Universalimageloader1.9.5上还没有对外提供获取图片的原大小功能,如果需要获取图片的源大小,可参考stackoverflow上的解决办法 stackoverflow地址 主要实现 ...

  8. python 利用 for ... else 跳出双层嵌套循环

    背景 周末在写一个爬虫时,遇到这样一种场景:从搜索结果中下载指定数量的文件 例如:搜索结果中共分为10页展示,加起来一共50条数据,现在要做的是从50条数据中下载指定数量的数据 为了实现这个功能,开始 ...

  9. 14.6 kafka

    14.6 kafka 为什么用消息队列 举例 比如在一个企业里,技术老大接到boss的任务,技术老大把这个任务拆分成多个小任务,完成所有的小任务就算搞定整个任务了. 那么在执行这些小任务的时候,可能有 ...

  10. Java开发架构篇:领域驱动设计架构基于SpringCloud搭建微服务

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言介绍 微服务不是泥球小单体,而是具备更加清晰职责边界的完整一体的业务功能服务.领域驱动 ...