Search code examples
jqueryresizewidth

re-query window size upon resizing


I'm a bit stuck here. I have the following script which takes the window width and created a beautiful 100% width slider. However, when I refresh, it uses the original window width, so it will e.g. show the original 600px instead of the new 700px width. Any idea how I can query the window upon resizing? I can't seem to get it to work.

//current position
var pos = 0;
//number of slides
var totalSlides = $('#slider-wrap ul li').length;
//get the slide width
var sliderWidth = $('#slider-wrap').width();


$(document).ready(function(){


/*****************
 BUILD THE SLIDER
*****************/
//set width to be 'x' times the number of slides
$('#slider-wrap ul#slider').width(sliderWidth*totalSlides);

Solution

  • I ended up adding a $(window).resize(function(){location.reload();});