創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!

今天就跟大家聊聊有關(guān)如何實現(xiàn)phpcms輪播,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
phpcms實現(xiàn)輪播的方法:首先在想要加輪播圖的位置加入“<div id="flowDiagram" >...</div>”;然后根據(jù)自己的需求對css樣式進(jìn)行更改;最后在需要實現(xiàn)輪播的地方加入js代碼即可。
phpcms首頁實現(xiàn)輪播圖
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>由于這個焦點幻燈比較特殊,圖片和文字需要兩次調(diào)用,另外,后臺添加內(nèi)容時要勾選首頁焦點圖推薦,就可以添加到首頁
2.當(dāng)然,這里面的css樣式根據(jù)自己的需求做更改,在這里就不貼出css代碼了,實現(xiàn)輪播需要加入以下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(){//當(dāng)right鍵被觸發(fā)時響應(yīng)
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();
}最終效果

看完上述內(nèi)容,你們對如何實現(xiàn)phpcms輪播有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝大家的支持。
網(wǎng)頁標(biāo)題:如何實現(xiàn)phpcms輪播-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://chinadenli.net/article38/hhgsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、域名注冊、外貿(mào)建站、商城網(wǎng)站、虛擬主機、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容