SoFunction
Updated on 2025-02-28

jQuery implements breathing carousel diagram

This article shares the specific code of jQuery to implement breathing carousel diagram for your reference. The specific content is as follows

HTML

<div class="all" id='box'>
        <div class="screen">
            <ul>
                <li><img src="images/" width="500" height="200" /></li>
                <li><img src="images/" width="500" height="200" /></li>
                <li><img src="images/" width="500" height="200" /></li>
                <li><img src="images/" width="500" height="200" /></li>
                <li><img src="images/" width="500" height="200" /></li>
            </ul>
            <ol>
                <li class="current">1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
                <li>5</li>
            </ol>
        </div>
        <div >
            <span >&lt;</span>
            <span >&gt;</span>
        </div>
</div>

CSS

* {
            padding: 0;
            margin: 0;
            list-style: none;
            border: 0;
        }

        .all {
            width: 500px;
            height: 200px;
            padding: 7px;
            border: 1px solid #ccc;
            margin: 100px auto;
            position: relative;
        }

        .screen {
            width: 500px;
            height: 200px;
            overflow: hidden;
            position: relative;
        }

        .screen li {
            width: 500px;
            height: 200px;
            overflow: hidden;
            float: left;
        }

        .screen ul {
            position: absolute;
            left: 0;
            top: 0px;
            width: 2500px;
        }

        .all ol {
            position: absolute;
            right: 10px;
            bottom: 10px;
            line-height: 20px;
            text-align: center;
        }

        .all ol li {
            float: left;
            width: 20px;
            height: 20px;
            background: #fff;
            border: 1px solid #ccc;
            margin-left: 10px;
            cursor: pointer;
        }

        .all ol  {
            background: yellow;
        }

        #arr {
            display: none;
        }

        #arr span {
            width: 40px;
            height: 40px;
            position: absolute;
            left: 5px;
            top: 50%;
            margin-top: -20px;
            background: #000;
            cursor: pointer;
            line-height: 40px;
            text-align: center;
            font-weight: bold;
            font-family: 'Boldbody';
            font-size: 30px;
            color: #fff;
            opacity: 0.3;
            border: 1px solid #fff;
        }

        #arr #right {
            right: 5px;
            left: auto;
        }

JS Code

$(function () {
        var index = 0;
        //Move in        $('#box').mouseenter(function(){
            $('#arr').show();
        })
        //Mouse out        $('#box').mouseleave(function(){
            $('#arr').hide();
        })
        $('#right').click(function(){
            if(index == $('.screen&gt;ul&gt;li').length-1){ //The last one                index = 0;
            }else {
               index++; 
            }
            $('.screen&gt;ul&gt;li').eq(index).fadeIn(200).siblings('li').fadeOut(200);
            //The page number below corresponds to highlight            $('.screen&gt;ol&gt;li').eq(index).addClass('current').siblings('li').removeClass('current')
        })
        $('#left').click(function(){
            if(index == 0){ //The first photo                index = $('.screen&gt;ul&gt;li').length-1;
            }else {
                index--;
            }
            $('.screen&gt;ul&gt;li').eq(index).fadeIn(200).siblings('li').fadeOut(200);
            //The page number below corresponds to highlight            $('.screen&gt;ol&gt;li').eq(index).addClass('current').siblings('li').removeClass('current')
        })
        //Click on the carousel picture on the page number        $('.screen&gt;ol&gt;li').click(function(){
            index = $(this).index()
            $('.screen&gt;ul&gt;li').eq(index).fadeIn(200).siblings('li').fadeOut(200);
            $('.screen&gt;ol&gt;li').eq(index).addClass('current').siblings('li').removeClass('current')
        })
 });

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.