How to change config on the fly ?
Closed this issue · 2 comments
I'm using the plugin and it working just fine, the scroll is triggered using two button :
// track right arrows event
$(self.arrows.right)[self.triggerEvent](function () {
$(self.scrollContainer).trigger('forward');
});
// track left arrows event
$(self.arrows.left)[self.triggerEvent](function () {
$(self.scrollContainer).trigger('backward');
});
where arrows.left and arrows.right are the button and triggerEvent the event that I'm associated with each arrows to trigger scrolling events.
By default, as I understand it, the number of items switched per scroll is set to 1.
In my case as a user stretches or narrow the browser's window, the amount of visible items increases or decreases, therefore the variables switchItems needs to be changed accordingly.
Here's my code initially I have switchItems set to 4 (if the window gets bigger then this should increase, or decrease the other way around) :
var scrollboxOutput = $(self.scrollContainer).scrollbox({
direction: 'h',
switchItems : 4,
autoPlay: false
});
I thought I'd be able to use scrollboxOutput.config.switchItems to change the config once my on Window resize function was called. It doesn't work since it doesn't return an object bu a Dom element. What I did instead was to add an extra event named updateConfig which I use to update the config like so :
// in client side javascript
$(self.scrollContainer).trigger('updateConfig', [{
switchItems: switchItems
}]);
// in jquery.scrollbox
container.bind('updateConfig', function (event,options) {
config = $.extend(config, options);
});
I was wondering if there was a better way to achieve this ? I don't think it should be done through an event, perhaps exposing the config variable to the container could be a way ? That way I'll just need to call container.config and the parameter. Let me know your thought on this
Hi @malikov ,
Thanks for reporting this. Currently I think binding an event is the easiest way to achieve this, although it's not really the best way. Exposing the config variable is not very good too, because not every variable could be change and works fine on the fly.
Anyway, if you have better thoughts, feel free to discuss with me or send me a pull request. Thanks.