How to refresh single Javascript Function when window.resize is called
I'm stucked once again;
I've got a jQuery-Function in the Tag of a php-File, which gets the Screenwidth for a Gallery. It's called when the page loads and works pretty well. But now I want the function to be called again, everytime the window 开发者_如何转开发is resized in order to get the new Screenwidth right. One possibility is to use window.location.href to reload the whole page when window.resize is called, but that's not what I want.
Is there a way to only reload the function (or the entire javascript Code Block written in the ) without reloading linked js-files and the html-Structure?? I just want to reload this single function:
jqSlider(function(){
var container = jqSlider('div.sliderGallery');
var ul = jqSlider('ul', container);
var fensterBreite = jqSlider("#preloader").outerWidth();
var itemsWidth = 2559 - fensterBreite;
jqSlider('.slider', container).slider({
min: 0,
max: itemsWidth,
handle: '.handle',
stop: function (event, ui) {
ul.animate({'left' : ui.value * -1}, 500, 'linear');
},
slide: function (event, ui) {
ul.css('left', ui.value * -1);
}
});
I admit I'm a bit confused by your syntax and I apologize if I'm not spot on here so let me know if this isn't what you needed and I'll do my best to modify the code to meet your needs. You appear to be passing an anonymous function to the method jqSlider, so working on that assumption:
- Move your anonymous function to a stored memory location
- Pass the function reference to your jqSlider method
- Bind the function reference to the window's resize event
var mySliderFunc = function () {
var container = jqSlider('div.sliderGallery');
var ul = jqSlider('ul', container);
var fensterBreite = jqSlider("#preloader").outerWidth();
var itemsWidth = 2559 - fensterBreite;
jqSlider('.slider', container).slider({
min: 0,
max: itemsWidth,
handle: '.handle',
stop: function (event, ui) {
ul.animate({ 'left': ui.value * -1 }, 500, 'linear');
},
slide: function (event, ui) {
ul.css('left', ui.value * -1);
}
});
};
jqSlider(mySliderFunc);
$(window).resize(mySliderFunc);
精彩评论