I'm working in my project with the following script:
;(function($, doc, win) {
"use strict";
// cache the window object
var jQuerywindow = $(window);
$('section[data-type="background"]').each(function(){
// declare the variable to affect the defined data-type
var jQueryscroll = $(this);
$(window).scroll(function() {
// HTML5 proves useful for helping with creating JS functions!
// also, negative value because we're scrolling upwards
var yPos = -(jQuerywindow.scrollTop() / jQueryscroll.data('speed'));
// background position
var coords = '50% '+ yPos + 'px';
// move the background
jQueryscroll.css({ backgroundPosition: coords });
}); // end window scroll
}); // end section function
})(jQuery, document, window);
The script allows me to have several sections with parallax background effect. So, I can have one or ten in a page. I'm a bit concern about performance. Can the script be improved?