练习:javascript轮播图效果
javascript轮播自动播放切换滑过停止,上一页/下一页
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>javascript焦点图</title>
<style>
*{margin:0;padding:0;}
li{list-style: none;}
#container{position:relative;width:680px;height:344px;overflow:hidden;margin:50px auto;font-size:13px;}
#container img{width:680px;height:344px;}
#tabs li{width:20px;height:20px;background:#000;color:#fff;float:left;margin-right:5px;text-align:center;line-height:20px;cursor: pointer;}
#tabs{position:absolute;right: 10px;bottom:10px;}
#tabs .active{background:#d75509;}
#arrow{left:5px;bottom:5px;position:absolute;}
#arrow span{width: 20px;height: 20px;display: inline-block;background: #000;color: #fff;text-align: center;cursor:pointer;}
#content div{width: 680px;height: 344px;display:none;}
#content .active{display:block;}
#container ul li.active {background:yellow;}
</style>
</head>
<body> <div id="container">
<ul id="tabs">
<li data-index ="0" class="active">1</li>
<li data-index ="1">2</li>
<li data-index ="2">3</li>
<li data-index ="3">4</li>
</ul>
<div id="content">
<div class="active"><img src="data:images/1.jpg" alt=""></div>
<div><img src="data:images/2.jpg" alt=""></div>
<div><img src="data:images/3.jpg" alt=""></div>
<div><img src="data:images/4.jpg" alt=""></div>
</div>
<div id="arrow">
<span><</span>
<span>></span>
</div>
</div>
<script>
var aLi = document.querySelectorAll('#tabs li');//arr,图索引
var oContainer = document.querySelector('#container');
var aDiv = document.querySelectorAll('#content div');
var aSpan = document.querySelectorAll('#arrow span');
var index=0;//上下图
var timer=null;
for(var i=0;i<aLi.length;i++){
//循环时就存索引,js中没有属性index,自定义的
aLi[i].index = i;
//进入onclick前for已经循环到4
aLi[i].onclick=function(){
index=this.index;
switchImg(this.index);
}
}
//图片切换函数
function switchImg(idx){
//去掉所有高亮
for(var j=0;j<aLi.length;j++){
aLi[j].className='';
aDiv[j].className='';
}
//this.index =this.getAttribute('data-index')//或在html中加入自定义索引data-index属性
aLi[idx].className='active';
aDiv[idx].className='active';
} //切换右测图片<
aSpan[0].onclick=function(){
index--;
if(index<0){
index=aLi.length-1;
}
switchImg(index);
}
//>
aSpan[1].onclick=function(){
index++;
if(index==aLi.length){
index=0;
}
switchImg(index);
}
//自动播放,调用点击>事件
timer = setInterval(function(){
aSpan[1].onclick();
},1000) oContainer.onmouseover = function(){
clearInterval(timer);
timer =null;
}
oContainer.onmouseout = function(){
timer = setInterval(function(){
aSpan[1].onclick();
},1000)
}
</script>
</body>
</html>
练习:javascript轮播图效果的更多相关文章
- JavaScript实现轮播图效果
我又来了,同志们.老想你们了 捕获小可爱一枚. 下面进入正题:用JavaScript原生代码写轮播图效果. 具体效果就不多说了,网站上面的轮播效果我们都知晓.下面是展示代码 html代码: <d ...
- 云南农职《JavaScript交互式网页设计》 综合机试试卷②——实现轮播图效果
一.语言和环境 实现语言:HTML,CSS,JavaScript,JQuery. 开发环境:HBuilder. 二.题目(100分): 使用JQuery淡入淡出动画,实现轮播图效果 每隔2秒钟切换一张 ...
- HTML+CSS+Javascript实现轮播图效果
HTML+CSS+Javascript实现轮播图效果 注意:根据自己图片大小来更改轮播图大小. <!doctype html> <html> <head> < ...
- js实现轮播图效果(附源码)--原生js的应用
1.js实现轮播图效果 <!DOCTYPE html><html lang="en"><head> <meta charset=" ...
- 纯CSS实现轮播图效果,你不知道的CSS3黑科技
前言 轮播图已经是一个很常见的东西,尤其是在各大App的首页顶部栏,经常会轮番显示不同的图片. 一提到轮播图如何实现时,很多人的第一反应就是使用Javascript的定时器,当然这种方法是可以实现的. ...
- 高仿阴阳师官网轮播图效果的jQuery插件
代码地址如下:http://www.demodashi.com/demo/12302.html 插件介绍 这是一个根据阴阳师官网的轮播效果所扒下来的轮播插件,主要应用于定制个性化场景,目前源码完全公开 ...
- 用html +js+css 实现页面轮播图效果
html 页面 <html lang="en"> <head> <meta charset="UTF-8"> <met ...
- 小程序实践(二):swiper组件实现轮播图效果
swiper组件类似于Android中的ViewPager,实现类似轮播图的效果,相对于Android的Viewpager,swiper实现起来更加方便,快捷. 效果图: 首先看下swiper支持的属 ...
- Android项目实战(四十七):轮播图效果Viewpager
简易.常用的轮播图效果ViewPager ,老技术了,记一笔留着以后ctrl C + ctrl V 需求如下: 不定张个数的ImagView轮播,右下角显示轮播点图标,每隔固定时间切换下一张,最 ...
随机推荐
- qemu 系列
一.. qemu uboot 1. 首先安装交叉编译器,执行: sudo apt-get install gcc-arm-linux-gnueabi 2. 下载U-Boot源文件: ht ...
- window.loaction.href 不自动跳转的问题
window.location.href无效/不跳转的原因分析 1.源代码: <a href="javascript:void(0);" onclick="mo ...
- kernel笔记——内核编译与进程管理
内核与操作系统 由于一些商业操作系统设计上的缺陷以及日益庞杂,“操作系统”的概念对很多人而言变得含糊不清.在进一步讨论Linux内核的话题前,我们先区分“内核”与“操作系统”这两个概念. 操作系统:指 ...
- golang http自动转为https 如何跳过证书检查
func SendReq(req *http.Request,result interface{}) error { tr := &http.Transport{ TLSClientConfi ...
- ubuntu 16.04 LTS - 谷歌拼音输入法
https://blog.csdn.net/chengyq116/article/details/78638249 1. installation1.1 汉语语言包 sudo apt-get inst ...
- 8个Python高效数据分析的技巧
一行代码定义List 下面是使用For循环创建列表和用一行代码创建列表的对比. x = [1,2,3,4] out = [] for item in x: out.append(item**2) pr ...
- 将arguments转换成数组的方法
将函数里的arguments,转换成一个真正的数组的方法,arguments是个类数组,除了有实参所组成的类似数组以外,还有自己的属性,如callee,arguments.callee就是当前正在执行 ...
- left join inner join 区别
left 以左表为准,左表在右表没有对应的记录,也为显示(右表字段填空). inner 需要满足两张表都有记录. 不管哪种join 一对多最终的结局 只会是多条记录
- SpringCloud(4)熔断器 Hystrix
在微服务架构中,根据业务来拆分成一个个的服务,服务与服务之间可以相互调用(RPC),在Spring Cloud可以用RestTemplate+Ribbon和Feign来调用.为了保证其高可用,单个服务 ...
- core dump文件的生成
#include <stdio.h> int main(int argc, char *argv[]) { char * p = "abcdefg"; p[] = '; ...