Targetting the background of a div for a jquery parrallax scroller

50 views Asked by At

I'm trying to edit a wordpress plugin which targets the background image of the body which makes it scroll with the page. The code from the plugin is quoted below.

I want the same effect to target the background images of other divs but I can't get it to work using the

$(".class").style.backgroundPosition = "0px " + (0 - 
            (Math.max(document.documentElement.scrollTop, 
             document.body.scrollTop) / 4)) + "px";

but its not working. I've also tried to use the DOM path to target the div with document.div.class.style.backgroundPosition = .....

Can anyone shed some light on why this isn't working?

    $(window).scroll(function () {
      document.body.style.backgroundPosition = 
         "0px " + 
            (0 - 
               (Math.max(document.documentElement.scrollTop, document.body.scrollTop) / 4)
            ) + "px";
    });
0

There are 0 answers