How to animate scrollLeft using jQuery?

jQueryWeb DevelopmentFront End Technology

To animate scrollLeft using jQuery, use the animate() method with scrollLeft.


You can try to run the following code to learn how to animate scrollLeft using jQuery:

Live Demo

<!DOCTYPE html>
<script src=""></script>
    $('#scrollme').click(function() {
        scrollLeft: $('#demo').css('left')
    }, 500, function() {

        $('html, body').animate({
            scrollLeft: 0
        }, 500);

#demo {
    width: 100px;
    height: 100px;
    background: green;
    position: relative;
    left: 800px;
<p><button id="scrollme">Click to scroll left</button></p>

<div id="demo"></div>

Updated on 17-Dec-2019 07:43:36