相思资源网 Design By www.200059.com
手动轮播图,为轮播图中的一种,轮播图主要有无缝轮播,手动轮播,延迟轮播,切换轮播等等。。。
轮播图主要用于展现图片,新出商品,词条,又能美观网页。給网页中增加动态效果。
手动轮播,是小编认为最简单的一种轮播方式,既能左右翻页,还能通过悬浮按钮,快速预览图片,所以今天就给大家写一个原生js手动轮播图。
一,利用JavaScript制作手动轮播图,首先排版。
引入默认样式表(可以手写);
<link rel="stylesheet" href="css/Default style sheet.css" rel="external nofollow" rel="external nofollow" />//本博客有css默认样式表可以下载。
div排版布局:
<body> <div id="box"> <div id="lunbo"><img src="/UploadFiles/2021-04-02/1.jpg">二,定义div的CSS样式,给div设置宽高,定位。
<style> body{ background: darkturquoise; } #box{ height:320px; width:480px; margin: 3px auto; border: 2px solid red; } #lunbo{ height: 292px; width:453px; border: 1px solid yellow; margin: 0px auto; position: relative; } #left{ height: 60px; width: 60px; font-size: 60px; text-align: center; line-height: 60px; position: absolute; top:150px; left: 440px; color: black; } #right{ height: 60px; width: 60px; font-size: 60px; text-align: center; line-height: 60px; position: absolute; top:150px; left: 880px; color: black; } #radiu{ height: 30px; width: 240px; text-align: center; margin: 0px auto; } #radiu li{ float: left; background: white; height: 30px; width: 30px; line-height: 30px; border-radius:50% ; margin-right:6px; } .active{ background: orange; color: ; } </style> 原生js代码: <script> window.onload=function(){ var ridiu=document.getElementById("radiu") var right=document.getElementById("right"); var left=document.getElementById("left") var img=document.getElementById("img"); var oli=ridiu.getElementsByTagName("li") var arry=['img/1.jpg','img/2.jpg','img/3.jpg','img/4.jpg','img/5.jpg'] var a=null; right.onclick=function(){ a++ if(a>arry.length-1){ a=0; } img.src=arry[a] } left.onclick=function(){ a-- if(a<0){ a=arry.length-1; } img.src=arry[a] } for (var i=0;i<oli.length;i++) { oli[i].onclick=function(){ a++ if(a==arry.length){ a=0; } img.src=arry[a]; } } } </script>HTML全部效果代码:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>手动轮播图</title> <link rel="stylesheet" href="css/Default style sheet.css" rel="external nofollow" rel="external nofollow" /> <style> body{ background: darkturquoise; } #box{ height:320px; width:480px; margin: 3px auto; border: 2px solid red; } #lunbo{ height: 292px; width:453px; border: 1px solid yellow; margin: 0px auto; position: relative; } #left{ height: 60px; width: 60px; font-size: 60px; text-align: center; line-height: 60px; position: absolute; top:150px; left: 440px; color: black; } #right{ height: 60px; width: 60px; font-size: 60px; text-align: center; line-height: 60px; position: absolute; top:150px; left: 880px; color: black; } #radiu{ height: 30px; width: 240px; text-align: center; margin: 0px auto; } #radiu li{ float: left; background: white; height: 30px; width: 30px; line-height: 30px; border-radius:50% ; margin-right:6px; } .active{ background: orange; color: ; } </style> <script> window.onload=function(){ var ridiu=document.getElementById("radiu") var right=document.getElementById("right"); var left=document.getElementById("left") var img=document.getElementById("img"); var oli=ridiu.getElementsByTagName("li") var arry=['img/1.jpg','img/2.jpg','img/3.jpg','img/4.jpg','img/5.jpg'] var a=null; right.onclick=function(){ a++ if(a>arry.length-1){ a=0; } img.src=arry[a] } left.onclick=function(){ a-- if(a<0){ a=arry.length-1; } img.src=arry[a] } for (var i=0;i<oli.length;i++) { oli[i].onclick=function(){ a++ if(a==arry.length){ a=0; } img.src=arry[a]; } } } </script> </head> <body> <div id="box"> <div id="lunbo"><img src="/UploadFiles/2021-04-02/1.jpg">效果图:
body{ background: darkturquoise; } #box{ height:320px; width:480px; margin: 3px auto; border: 2px solid red; } #lunbo{ height: 292px; width:453px; border: 1px solid yellow; margin: 0px auto; position: relative; } #left{ height: 60px; width: 60px; font-size: 60px; text-align: center; line-height: 60px; position: absolute; top:150px; left: 440px; color: black; } #right{ height: 60px; width: 60px; font-size: 60px; text-align: center; line-height: 60px; position: absolute; top:150px; left: 880px; color: black; } #radiu{ height: 30px; width: 240px; text-align: center; margin: 0px auto; } #radiu li{ float: left; background: white; height: 30px; width: 30px; line-height: 30px; border-radius:50% ; margin-right:6px; } .active{ background: orange; color: ; }
标签:
js,手动轮播图,js,轮播图
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无原生JS实现手动轮播图效果实例代码的评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?