Scroll div content horizontally using left and right arrow in jquery

前端 未结 2 1282
暖寄归人
暖寄归人 2020-12-30 17:27

I Want to scroll div contents using two buttons \"enter

HTML Coding is given below:

相关标签:
2条回答
  • 2020-12-30 18:14

    It's just a simple example, but you can see the point - how to do it.

    HTML:

    <div class="bstimeslider">
        <div id="rightArrow"></div>
            <div id="viewContainer">
                <div id="tslshow">
                    <div class="bktibx"> 12:00   </div>
                    <div class="bktibx"> 12:30   </div>
                    <div class="bktibx"> 13:00   </div>
                    <div class="bktibx"> 13:30   </div>
                    <div class="bktibx"> 14:00   </div>
                    <div class="bktibx"> 14:30   </div>
                    <div class="bktibx"> 15:00   </div>
                    <div class="bktibx"> 15:30   </div>
                    <div class="bktibx"> 16:00   </div>
                    <div class="bktibx"> 16:30   </div>
                    <div class="bktibx"> 17:00   </div>
                    <div class="bktibx"> 17:30   </div>
                 </div>
            </div>
            <div id="leftArrow"></div>
    </div>
    

    CSS:

    .bstimeslider {
    
    width:500px;
    height:40px;
    background:#ccc;
    position:relative;    
    }
    
    .bktibx {
    
    float:left;
    margin:0 40px 0 0 ;
    font-size:18px;
    width:60px;
    display:block;
    background:#000;
    color:#fff;
    
    }
    
    #tslshow {
    position:absolute;
    left:0;
    width:1200px;
    
    }
    
    #leftArrow {
    
    width:40px;
    height:40px;
    background:#ff0000; 
    position:absolute;
    left:0px;
    }
    
    #rightArrow {
    
    width:40px;
    height:40px;
    background:#ff0000; 
    position:absolute;
    right:0px;
    }
    
    #viewContainer {
    width:360px;
    height:100%;
    background:#00ff00;
    position:absolute;
    left:50%;
    margin-left:-180px;
    overflow:hidden; 
    }
    

    JavaScript:

    var view = $("#tslshow");
    var move = "100px";
    var sliderLimit = -750;
    
    $("#rightArrow").click(function(){
    
        var currentPosition = parseInt(view.css("left"));
        if (currentPosition >= sliderLimit) view.stop(false,true).animate({left:"-="+move},{ duration: 400})
    
    });
    
    $("#leftArrow").click(function(){
    
        var currentPosition = parseInt(view.css("left"));
        if (currentPosition < 0) view.stop(false,true).animate({left:"+="+move},{ duration: 400});
    
    });
    

    Fiddle: http://jsfiddle.net/yfqyq9a9/2/

    0 讨论(0)
  • 2020-12-30 18:27

    You can alter the style of the scrollbar using regular old CSS:

    ::-webkit-scrollbar {
        width: 20px;
    }
    
    ::-webkit-scrollbar-track {
            box-shadow: inset 0 0 5px grey;
            border-radius: 10px;
    }
    
    ::-webkit-scrollbar-thumb {
        background: red;
        border-radius: 10px;
    }
    
    ::-webkit-scrollbar-thumb:hover {
        background: #b30000;
    }
    
    0 讨论(0)
提交回复
热议问题