user2891660
user2891660

Reputation: 1

How to convert this jquery code into javascript DOM code?

Hi everyone I was just wondering if anyone know how to convert this css/jquery code into javascript DOM code?

I started coding my entire code using javascript DOM for a project but then I found this code which will make the background image move upwards in an infinite loop.

I just need some help in figuring out how to convert the code since I know nothing about jquery.

    $(function(){
            var x = 0;
            setInterval(function(){
                $('body').css('background-position','0'+--x + 'px');
            }, 10);
    })
    html,body {    height: 100%; overflow: hidden;}
    body {
        background-image: url('http://lorempixel.com/1900/1200/');
        background-repeat: repeat-y;
        background-size: 100% 100%;
    }

html,body {    height: 100%; overflow: hidden;}
body {
    background-image: url('http://lorempixel.com/1900/1200/');
    background-repeat: repeat-y;
    background-size: 100% 100%;
}

$(function(){
        var x = 0;
        setInterval(function(){
            $('body').css('background-position','0'+--x + 'px');
        }, 10);
})

Upvotes: 0

Views: 46

Answers (1)

Ry-
Ry-

Reputation: 224904

$('body') selects the body element; .css(prop, value) sets the CSS property prop to value. With the plain DOM API, you can get the body using document.body and assign styles by assigning to properties on the element’s style, noting that hyphenated-names become camelCase.

var x = 0;

setInterval(function () {
    document.body.style.backgroundPosition = '0 ' + --x + 'px';
}, 10);

Upvotes: 1

Related Questions