新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

如何用js实现简单的图片轮播功能

这篇文章主要介绍“如何用js实现简单的图片轮播功能”,在日常操作中,相信很多人在如何用js实现简单的图片轮播功能问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何用js实现简单的图片轮播功能”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

成都创新互联公司是一家专注于网站制作、做网站联通服务器托管的网络公司,有着丰富的建站经验和案例。

设计思路:利用js当中的定时器实现图片轮播的效果,将所有图片放入img文件夹下,我当时是存放了三张照片。然后将三张照片分别放入三个div,每一个div显示和隐藏都是靠定时器进行控制,左下角有三个数字的div代表这是第几张图片,一共有三张图片所以是三个div。

代码:







.imgbox{
width: 100%;
height:400px;
background-color: black;
transform: 1s;
}
.img{
width: 100%;
height:100%;
background-image: url(img/37fa7b724f5c49cd8c2d0efad885f1a8.jpeg);
background-repeat:no-repeat;
background-size:cover ;
}
.img0{
width: 100%;
height:100%;
background-image: url(img/37fa7b724f5c49cd8c2d0efad885f1a8.jpeg);
background-repeat:no-repeat;
background-size:100% ;
}
.img1{
width: 100%;
height:100%;
background-image: url(img/5572568_110213373115_2.jpg);
background-repeat:no-repeat;
background-size:100% ;
}
.img2{
width: 100%;
height:100%;
background-image: url(img/5875f5fb7a8f8.jpg);
background-repeat:no-repeat;
background-size:100% ;
}
.img3{
width: 100%;
height:100%;
background-image: url(img/980.jpg);
background-repeat:no-repeat;
background-size:100% ;
}
            ul{
margin-left:-30px ;
list-style-type: none;
position: relative;
margin-top: -100px;
line-height: 50px;
}
ul li{
float: left;
width: 50px;
height:50px;
border:1px solid #000000;
text-align: center;
background-color: aliceblue;
}
.div{
background-color: orange;
line-height: 50px;
}
.div1{
background-color: gainsboro;
line-height: 50px;
}


var i=0;
function imgbox(){
   i++;
  if(i<4){
  document.getElementById("img").className="img"+i;
  if(i==1){
  document.getElementById("one").className="div";
  document.getElementById("two").className="div1";
  document.getElementById("three").className="div1";
  }
  if(i==2){
     document.getElementById("one").className="div1";
     document.getElementById("two").className="div";
     document.getElementById("three").className="div1";
  }
  if(i==3){
     document.getElementById("one").className="div1";
     document.getElementById("two").className="div1";
     document.getElementById("three").className="div";
  } 
}
if(i==4){
i=0;
clearInterval('imgbox()');
}
}
setInterval('imgbox()',1000);




1 2 3

认识HTML

HTML,就是我们所说的网页,网页的文件格式就是.html格式。在我们眼里,它是一种超文本语言,不需要额外的编译或者处理,写好,打开,就是一个网页。

Html组成由许多标签组成如

......,还有一些语义化标签如

Img为大的div盒子,img为图片,

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP