Animate background position X and Y - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:animate

Description

Animate background position X and Y

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(".btn1").click(function(){
        $("body").animate({
            backgroundPositionX: "+=100px",
            backgroundPositionY: "+=200px"
        });/*from   w  w w. j  a v a 2  s.  c o  m*/
    });
    $(".btn2").click(function(){
        $("body").animate({
            backgroundPositionX: "0px",
            backgroundPositionY: "0px"
        });
    });
});
</script>
</head>

<body style="background-image:url('http://java2s.com/resources/a.png');background-repeat:no-repeat;position:fixed;">

<button class="btn1">Animate</button>
<button class="btn2">Reset</button>

</body>
</html>

Related Tutorials