溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何實現(xiàn)phpcms輪播

發(fā)布時間:2020-07-23 09:20:23 來源:億速云 閱讀:242 作者:Leah 欄目:建站服務器

今天就跟大家聊聊有關如何實現(xiàn)phpcms輪播,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據(jù)這篇文章可以有所收獲。

phpcms實現(xiàn)輪播的方法:首先在想要加輪播圖的位置加入“<div id="flowDiagram" >...</div>”;然后根據(jù)自己的需求對css樣式進行更改;最后在需要實現(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>

由于這個焦點幻燈比較特殊,圖片和文字需要兩次調用,另外,后臺添加內容時要勾選首頁焦點圖推薦,就可以添加到首頁

2.當然,這里面的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(){//當right鍵被觸發(fā)時響應
        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();
}

最終效果

如何實現(xiàn)phpcms輪播

看完上述內容,你們對如何實現(xiàn)phpcms輪播有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI