Arockiaraj
Arockiaraj

Reputation: 353

Scroll div content horizontally using left and right arrow in jquery

I Want to scroll div contents using two buttons enter image description here

HTML Coding is given below:

<div class="bstimeslider">
    <a href="#"> <img src="images/left.png" ></a>
        <div class="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>
    <a href="#"><img src="images/right.png"></a>

Now only 15:00 is displaying when i scroll right button it should show from 15:30 to 17:30..

Similarly when i click left arrow it should scroll left..

Using Jquery i want to perform this. Any opensource plugin is available.

Upvotes: 5

Views: 64456

Answers (2)

Colin
Colin

Reputation: 1836

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;
}

Upvotes: 0

Marian Gibala
Marian Gibala

Reputation: 884

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/

Upvotes: 12

Related Questions