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

admin3年前云主机120

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

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

相关文章

深入探究Java虚拟机规范的内在实现机制

Java虚拟机(JVM)是现代编程语言中极为重要的组成部分之一,Java程序员通过虚拟机平台的构建轻松实现跨平台编译,实现Java程序的跨平台运行。本文旨在深入探究Java虚拟机规范的内在实现机制,详...

什么是域名解析服务器(什么是域名解析服务)

域名解析服务器通常由一台服务器系统构成,它可以接收来自外部 Internet 中众多域名解析请求,并将其转发到域名解析服务器上的域名解析数据库中进行查询,根据查询结果返回给对应的客户端,以实现域名到...

wordpress官网主题

WordPress官网主题介绍WordPress是目前最受欢迎的开源博客系统之一,它拥有丰富的功能和强大的可扩展性。而在WordPress上,主题则起到了很重要的作用,不仅可以美化博客,还可以提供更好...

北京虚拟主机租用价格是多少

虚拟主机租用价格是多少?虚拟主机是指将一台服务器分割成多个虚拟的主机,每个虚拟主机都可以作为一个独立的主机来使用。对于想要搭建个人博客、小型企业展示网站等只需要低成本的网站运营者来说,选择虚拟主机可以...

comodo ssl证书

什么是Comodo SSL证书?Comodo SSL证书是一种数字证书,旨在保护您的网站和用户数据安全。它是由Comodo CA签发的,Comodo是全球领先的数字证书颁发机构之一,拥有超过20年的数...

shopee怎么切换语言

Shopee怎么切换语言Shopee是东南亚地区最大的在线购物平台之一,目前已经覆盖了七个国家和地区。Shopee致力于通过提供安全,可靠的购物体验和无与伦比的选择,为消费者带来愉悦的购物体验。Sho...