I've tried changing a style using JS.
The first method is JQuery, it did work. N.B. I have multiple .slider__content
divs.
$(window).scroll(function() {
var wScroll = $(this).scrollTop();
$('.slider__content').css({
'transform' : 'translate(0px, -'+ wScroll /2 +'%)'
});
});
But this second syntax returns 'slideBG.style is undefined' on the browser console.
$(document).ready(function() {
.
.
.
window.addEventListener('scroll', function() {
var wScroll = this.pageYOffset;
var slideBG = document.querySelectorAll('.slider__content');
slideBG.style["transform"] = 'translateY(' + window.pageXOffset /2 + "%)";
});
});
Why does this happen?