phpcms如何实现轮播(轮播图怎么实现)

admin3年前云主机90

phpcms实现轮播的方法:首先在想要加轮播图的位置加入“<div id="flowDiagram" >...</div>”;然后根据自己的需求对css样式进行更改;最后在需要实现轮播的地方加入js代码即可。

正文内容:

php零基础到就业直播视频课:进入学习
API 文档、设计、调试、自动化测试一体化协作工具:点击使用


phpcms首页实现轮播图

1.在你想要加轮播图的位置加入以下

<div id="flowDiagram" > <div id="button"> <span index="1" class="on"></span> <span index="2"></span> <span index="3"></span> <span index="4"></span> <span index="5"></span> </div> <div id="photo" style="left:-1200px;"> <div> {pc:content action="position" posid="1" thumb="1" order="listorder DESC" num="5"} {loop $data $r} <div ><a href="{$r[url]}" target="_blank" title="{$r[title]}"><img src="{thumb($r[thumb],1200,320)}" style="width:1200px; height:320px;" alt="{$r[title]}" /></a></div> {/loop} {/pc} <ul> {pc:content action="lists" catid="" thumb="1" order="listorder DESC" num="5"} {loop $data $r} <li><a href="{$r[url]}" target="_blank" title="{$r[title]}">{str_cut($r[title],20)}</a></li> {/loop} {/pc} </ul> <div></div> </div> </div><span id="pre" class="arrow"> <</span><span id="next" class="arrow">> </span> </div>

由于这个焦点幻灯比较特殊,图片和文字需要两次调用,另外,后台添加内容时要勾选首页焦点图推荐,就可以添加到首页

(inhv.cn)》

2.当然,这里面的css样式根据自己的需求做更改,在这里就不贴出css代码了,实现轮播需要加入以下js代码

window.onload=function(){//获取元素 var flowDiagram = document.getElementById('flowDiagram');//容器 var photo = document.getElementById("photo"); var button = document.getElementById("button").getElementsByTagName('span'); var pre = document.getElementById("pre"); var next = document.getElementById("next"); var index = 1; var m; function move(){ m = setInterval(next.onclick,3000); } function stop(){ if(m)clearInterval(m); } function buttonlight(){ for (var i = 0; i < button.length; i++) { if(button[i].className == "on"){ button[i].className = ""; break; } } button[index-1].className = "on"; } pre.onclick=function() { if (index == 1) index = 5; else index = index - 1; buttonlight(); photo.style.left = parseInt(photo.style.left) + 1200 + "px"; if (parseInt(photo.style.left) > -1200){ photo.style.left = -6000 + "px"; } } next.onclick = function(){//当right键被触发时响应 if (index == 5) index = 1; else index = index + 1; buttonlight(); photo.style.left = parseInt(photo.style.left) - 1200 + "px"; if (parseInt(photo.style.left) < -6000){ photo.style.left = -1200 + "px"; } } for (var i = 0; i < button.length; i++){ button[i].onclick = function() { if(this.className=="on") return; var currentindex = parseInt(this.getAttribute("index"));//getAttribute能获取自定义的属性值,也可以获取自带的属性值 var distance = currentindex - index; photo.style.left = parseInt(photo.style.left) - 1200 * distance + "px"; index = currentindex; buttonlight(); } } flowDiagram.onmouseover = stop; flowDiagram.onmouseout = move; move();}

最终效果

正文内容:

本文从互联网转载,来源地址:inhv.cn/phpcmsjc/207850.html,原作者保留一切权利,若侵权或引用不当,请联系测速网(inhv.cn)删除。【测速网,优质云服务器提供商】

《phpcms如何实现轮播(轮播图怎么实现)》来自互联网同行内容,若有侵权,请联系我们删除!

免责声明:本文内容来自用户上传并发布,站点仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。请核实广告和内容真实性,谨慎使用。

相关文章

南充云主机

南充云主机什么是南充云主机?南充云主机是一种基于云计算的虚拟主机服务。与传统虚拟主机不同的是,南充云主机是将服务器资源分配成云主机实例供使用,这意味着用户可以根据实际需求弹性地分配和管理自己的计算资源...

青岛服务器租用费用大概多少钱?

青岛服务器租用费用大概多少钱?青岛服务器租用费用会受到以下因素的影响:服务器配置-不同的服务器配置以及硬件规格会有不同的价格。一般来说,处理器、内存、存储和带宽等越高的服务器,租用费用就越高。租用时长...

teamviewer入门版

什么是TeamViewer入门版?TeamViewer入门版是一款功能齐全且易于使用的远程访问软件,它可以远程连接到另一个计算机并控制那台计算机。无论您是要在家里或在远程办公,都可以使用TeamVie...

企业怎么租用佛山游戏服务器

什么是佛山游戏服务器?佛山游戏服务器是一种专门为游戏开发者和玩家提供游戏服务的远程服务器。它们提供了各种功能,包括存储、运行游戏软件、处理游戏逻辑、托管游戏数据以及支持多人在线游戏等。佛山游戏服务器可...

start主题

从实际出发,如何开启好的局面?在生活和工作中,每个人都希望自己能够取得好的成绩。但是,有时候我们可能会遇到困难,甚至遇到挫折。此时,怎样才能够从实际出发,开启好的局面呢?下面,笔者将为大家一一讲解。明...

BGP多线高防服务器的优点?扬州多线高防服务器租用地址是多少?

BGP多线高防服务器的优点?1.BGP服务器只必须设定一个IP地址,最好浏览路由器是由互联网上的技术骨干无线路由器依据路由器跳数与其他性能指标来明确的,不容易占有网络服务器的一切服务器资源。网络服务器...