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

admin3年前云主机30

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如何实现轮播(轮播图怎么实现)》来自互联网同行内容,若有侵权,请联系我们删除!

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

相关文章

游戏服务器怎么设置防护?泉州BGP高防物理机有什么应用场景?

游戏服务器怎么设置防护?确保服务器系统安全1、确保服务器的系统文件是最新的版本,并及时更新系统补丁2、管理员需对所有主机进行检查,知道访问者的来源3、过滤不必要的服务和端口,可以使用工具来过滤不必要的...

winrar免费版

WinRAR免费版——给您多重压缩体验WinRAR是一款知名的压缩软件,在压缩文件的效率及功能上得到了广泛的认可。对于用户来说,选择一款好用的压缩软件非常重要。在使用的过程中,如果你需要经常压缩文件,...

便宜vps租用怎么看性能好不好(如何评估便宜VPS租用的性能?)

一、CPU性能在选择便宜vps时,需要优先考虑其CPU性能,因为CPU是运行服务器应用程序的核心组件。CPU性能可以通过核心数量、主频和架构来评估。在相同价格范围内,选择拥有多个核心和更高主频的CPU...

服务器错误500的原因有哪些

什么是服务器错误500?当我们在浏览器中输入网址访问某个网站时,如果遇到了“服务器错误500”的提示,这意味着我们无法正常连接到该网站,因为服务器在处理我们的请求时出现了错误。服务器错误500的可能原...

centos7如何查看cpu利用率

如何查看CentOS 7的CPU利用率在CentOS 7中,可以通过多种方式查看CPU利用率。以下是其中几种常用的方法。使用top命令top命令是一个可以实时查看系统资源占用情况的工具。其中包括CPU...

centos7系统中端口无法访问怎么办

问题:centos7.3系统,已经关闭firewalld,但是除了22端口,其余端口无法被外界访问,本地访问正常。解决步骤:(inhv.cn)1、先开启firewalld:systemctl star...