当前位置: 首页 > news >正文

成都手机网站建设/关键词seo价格

成都手机网站建设,关键词seo价格,滨州正规网站建设价格,wordpress怎样调用分类名称轮播图见下图是移动端,网站上一种非常常见的展示效果,我们在各大app,网站都经常可以看到这种效果。用户可以用手来回选择展示的图片,无点击事件时,控件会依次循环展示图片。 那么本文今天就探究一下如何实现这类效果。…

        轮播图见下图是移动端,网站上一种非常常见的展示效果,我们在各大app,网站都经常可以看到这种效果。用户可以用手来回选择展示的图片,无点击事件时,控件会依次循环展示图片。

那么本文今天就探究一下如何实现这类效果。

展示效果

技术流程

对于这个功能,作者梳理了一下实现流程
1. 需要有一个图片切换功能

2. 能够自动切换图片

3. 鼠标移动到轮播图上,不进行轮回播放,鼠标移动走进行轮回播放

 

图片切换函数的实现

function changePic (curIndex) {for (var i = 0; i < pic.length; ++i) {pic[i].style.display = "none";list[i].className = "";}pic[curIndex].style.display = "block";list[curIndex].className = "on";}};

遍历所有数组中所有图片,然后通过遍历展示切换图片,进而实现效果

 

自动切换图片

自动切换图片就需要让他能够在一定时间内自动调用切换函数

function autoPlay () {if (++index >= pic.length) index = 0;changePic(index);}

同时为了实现过一段时间切换下一张,需要进行时间限制

timer = setInterval(autoPlay, 5000);

 

鼠标悬停控制

鼠标划过整个容器时停止自动播放

wrap.onmouseover = function () 
{      clearInterval(timer);
}
鼠标离开整个容器时继续播放至下一张,设置轮播间隔为5000毫秒(5s)
wrap.onmouseout = function () 
{timer = setInterval(autoPlay, 5000);
}

html文件引入需要轮播的图片

<body>
<div class="wrap" id='wrap'><ul id="pic"><li><img src="res/card1.png" alt=""></li><li><img src="res/card2.png" alt=""></li><li><img src="res/card3.png" alt=""></li><li><img src="res/card4.png" alt=""></li><li><img src="res/card5.png" alt=""></li></ul><ol id="list"><li class="on">1</li><li>2</li><li>3</li><li>4</li><li>5</li></ol>
</div>

 css决定轮播图的样式

<style>*{margin:0;padding:0;list-style:none;}.wrap{height:170px;width:490px;margin:60px auto;overflow: hidden;position: relative;margin:100px auto;}.wrap ul{position:absolute;}.wrap ul li{height:170px;}.wrap ol{position:absolute;right:5px;bottom:10px;}.wrap ol li{height:20px; width: 20px;background:#ccc;border:solid 1px #666;margin-left:5px;color:#000;float:left;line-height:1;text-align:center;cursor:pointer;}.wrap ol .on{background:#E97305;color:#fff;}</style>

 完整代码与演示

<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><title>轮播图demo</title><style>*{margin:0;padding:0;list-style:none;}.wrap{height:170px;width:490px;margin:60px auto;overflow: hidden;position: relative;margin:100px auto;}.wrap ul{position:absolute;}.wrap ul li{height:170px;}.wrap ol{position:absolute;right:5px;bottom:10px;}.wrap ol li{height:20px; width: 20px;background:#ccc;border:solid 1px #666;margin-left:5px;color:#000;float:left;line-height:1;text-align:center;cursor:pointer;}.wrap ol .on{background:#E97305;color:#fff;}</style><script type="text/javascript">window.onload=function(){var wrap=document.getElementById('wrap'),pic=document.getElementById('pic').getElementsByTagName("li"),list=document.getElementById('list').getElementsByTagName('li'),index=0,timer=null;// 定义并调用自动播放函数timer = setInterval(autoPlay, 5000);// 鼠标划过整个容器时停止自动播放wrap.onmouseover = function () {clearInterval(timer);}// 鼠标离开整个容器时继续播放至下一张wrap.onmouseout = function () {timer = setInterval(autoPlay, 5000);}// 遍历所有数字导航实现划过切换至对应的图片for (var i = 0; i < list.length; i++) {list[i].onmouseover = function () {clearInterval(timer);index = this.innerText - 1;changePic(index);};};function autoPlay () {if (++index >= pic.length) index = 0;changePic(index);}// 定义图片切换函数function changePic (curIndex) {for (var i = 0; i < pic.length; ++i) {pic[i].style.display = "none";list[i].className = "";}pic[curIndex].style.display = "block";list[curIndex].className = "on";}};</script>
</head>
<body>
<div class="wrap" id='wrap'><ul id="pic"><li><img src="res/card1.png" alt=""></li><li><img src="res/card2.png" alt=""></li><li><img src="res/card3.png" alt=""></li><li><img src="res/card4.png" alt=""></li><li><img src="res/card5.png" alt=""></li></ul><ol id="list"><li class="on">1</li><li>2</li><li>3</li><li>4</li><li>5</li></ol>
</div>
</body>
</html>

喜欢的朋友点赞收藏啦

 

http://www.jmfq.cn/news/4809313.html

相关文章:

  • wordpress E405/站长之家seo
  • 迷你世界怎么做网站期/搜索引擎查重
  • 东莞网络优化排名/什么是优化
  • 云南网站建设一度科技公司/微信小程序怎么做
  • 做网站还有用/外链屏蔽逐步解除
  • 校园网站建设软件/怎么制作网页页面
  • 做实验学编程的网站/seo管理系统培训
  • wordpress2019主题/北京网站建设东轩seo
  • 白领兼职做网站/谷歌seo站内优化
  • 保定建站软件/外链发布的平台最好是
  • 学vue可以做pc网站/社交网络推广方法有哪些
  • cs4建立网站站点/品牌策划ppt案例
  • b2c网站 架构/互联网推广的好处
  • 课程设计做淘宝网站的目的/网络推广竞价外包
  • 静态网站生成/培训网
  • 网站制作英文版网站/东莞搜索排名提升
  • 兰州做网站企业/网络seo公司
  • 天津公司网站的建设/西安网站关键词优化推荐
  • 简述建设一个商务网站的过程/石家庄网络推广平台
  • logo设计理念简短范文/seo快速推广窍门大公开
  • 在那个网站上做设计赚钱/营销软文范例大全300
  • 荆门网站开发公司/济南网络优化厂家
  • 前端网站做中 英文怎么说/女生做sem专员的工作难吗
  • 软件公司排名100强/武汉seo搜索引擎
  • java调接口做网站/地推网app推广平台
  • 绵阳top唯艺网站建设/网站生成app工具
  • 手机端建站/seo门户网站建设方案
  • 北京好的做网站的公司/成功的软文推广
  • 做购物网站表结构分析/在线科技成都网站推广公司
  • 在日本做网站/域名大全