Now you want to define the options object and pass the object instead of the variable speedand extend the default values with user-defined options
:
jQuery.fn.extend({
objectParallax: function(options) {
var defaults = {
speed: '.5',
};
options = options ? options : {};
var settings = $.extend({}, defaults, options);
if (settings.speed < -2 || settings.speed > 2) {
console.error('Speed not in limits');
return;
}
var $window = $(window);
return this.each(function() {
var elem = $(this);
var defaultTop = parseInt(elem.css('top'));
$window.on('scroll', function() {
var scrolled = $window.scrollTop();
elem.css('top', (defaultTop - (scrolled * settings.speed)) + 'px');
});
});
});
});
pass options, , . /,
var opts = {speed: 1.5 };
$('#floating-parallax-1, #floating-parallax-2').objectParallax(opts);
jQuery Learning Center/Plugins
, jQuery, .