..." where you want to add a carousel image; then change the css style according to your own needs; finally, add it when needed Just add js code where carousel is implemented."/> ..." where you want to add a carousel image; then change the css style according to your own needs; finally, add it when needed Just add js code where carousel is implemented.">

Home >CMS Tutorial >PHPCMS >How to implement carousel in phpcms

How to implement carousel in phpcms

藏色散人
藏色散人Original
2020-07-21 09:58:163345browse
How to implement carousel in phpcms: First, add "
...
" where you want to add a carousel image; then adjust the css style according to your own needs Make changes; finally add js code where you need to implement carousel.

How to implement carousel in phpcms

phpcms home page to implement carousel images

1. Add the following

where you want to add carousel images
<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="max-width:90%" 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>

Because this focus slideshow is special, pictures and text need to be called twice. In addition, when adding content in the background, you must check the homepage focus picture recommendation, and you can add it to the homepage

Recommendation: " phpcms tutorial

2. Of course, the css style here can be changed according to your own needs. I will not post the css code here. To implement the carousel, you need to add the following js code

window.onload=function(){//获取元素
    var flowDiagram = document.getElementById(&#39;flowDiagram&#39;);//容器
    var photo = document.getElementById("photo");
    var button = document.getElementById("button").getElementsByTagName(&#39;span&#39;);
    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();
}

Final effect

How to implement carousel in phpcms

The above is the detailed content of How to implement carousel in phpcms. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn