I'm trying to set up a function so that when the user resizes their window, the slider is emptied and then re-implemented based on the size of the window.
The problem that I have is that the slider IS being re-implemented, but with without slides.
The code I'm using is:
var newdiv = $('<div class="slider1" />');
$(window).resize(function(){
$("#featured").empty();
$("#featured").append(newdiv);
if($(window).width() > 640){
$('.slider1').bxSlider({
slideWidth: 1200,
minSlides: 4,
maxSlides: 4,
slideMargin: 10,
pager: false
});
}else if($(window).width() > 480 && $(window).width() < 640){
$('.slider1').bxSlider({
slideWidth: 800,
minSlides: 3,
maxSlides: 3,
slideMargin: 10,
pager: false
});
}else if($(window).width() < 480){
$('.slider1').bxSlider({
slideWidth: 500,
minSlides: 2,
maxSlides: 2,
slideMargin: 10,
pager: false
});
}
});
If someone can either tell me what I'm doing wrong, or show me a better way of making this work, that'd be great. Thanks!