Reputation: 389
I've some raw JavaScript code and I want them to be re-written in jquery. So how do I do it?
(function(){
var parallax = document.querySelectorAll(".parallax"),
speed = 0.1;
window.onscroll = function(){
[].slice.call(parallax).forEach(function(el,i){
var windowYOffset = window.pageYOffset,
elBackgrounPos = "100% " + (windowYOffset * speed) + "px";
el.style.backgroundPosition = elBackgrounPos;
});
};
})();
Upvotes: 0
Views: 60
Reputation: 768
Here's a jsfiddle:
https://jsfiddle.net/mckinleymedia/d3qt5p94/2/
And the code:
var parallax = $(".parallax"),
speed = 0.1;
window.onscroll = function(){
parallax.css('backgroundPosition','0 ' + (window.pageYOffset * speed) + "px");
};
Upvotes: 1