Element scrollLeft Property - Scroll the contents of <body> by 30 pixels horizontally and 10 pixels vertically: - Javascript DOM

Javascript examples for DOM:Element scrollLeft

Description

Element scrollLeft Property - Scroll the contents of <body> by 30 pixels horizontally and 10 pixels vertically:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
body {//ww w.j a  va 2 s.com
    height: 2000px;
    width: 2000px;
}

button {
    position: fixed;
}
</style>
</head>
<body>

<button onclick="myFunction()">Scroll contents of body</button><br><br>

<script>
function myFunction() {
    var body = document.body; // For Chrome, Safari and Opera
    var html = document.documentElement; // Firefox and IE 
    body.scrollLeft += 30;
    body.scrollTop += 10;
    html.scrollLeft += 30;
    html.scrollTop += 10;
}
</script>

</body>
</html>

Related Tutorials