Rodolfo Bandeira

Rodolfo Bandeira

software, electronics, security, devops, thoughts

How to scroll window to the left or right using jQuery

Hey

I’m posting this information because I spent some hours to make this working fine in Firefox and Safari. We can find on google a lot of examples to scroll window or div elements up or down. But left or right isn’t so easy.

<script type="text/javascript">  
        $(function() 
                {
                $("#moveLeft").click(function() {
                    $("html, body").animate({ scrollLeft: '-=500px' }, "slow");
                });

                $("#moveRight").click(function() { 
                    $("html, body").animate({ scrollLeft: '+=500px' }, "slow");
                });
        });            
</script>

Last modified:

LinkedIn
WhatsApp