您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 贵港分类信息网,免费分类信息发布

phpcms如何实现轮播

2025/5/22 7:04:02发布8次查看
phpcms实现轮播的方法:首先在想要加轮播图的位置加入“4c74d6a10c6bbaa8bf9ee18f30e5e89c...16b28748ea4df4d9c2150843fecfba68”;然后根据自己的需求对css样式进行更改;最后在需要实现轮播的地方加入js代码即可。
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>
由于这个焦点幻灯比较特殊,图片和文字需要两次调用,另外,后台添加内容时要勾选首页焦点图推荐,就可以添加到首页
推荐:《phpcms教程》
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();}
最终效果
以上就是phpcms如何实现轮播的详细内容。
贵港分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product