Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery window resizing
    primarykey
    data
    text
    <pre><code>$(document).ready(function(){ WinSize = $(window).width(); var currentPosition = 0; var slideWidth = WinSize; $(function(){ $(window).resize(function(){ slideWidth = WinSize = $(window).width(); }); }); var slides = $('.slide'); var numberOfSlides = slides.length; // Remove scrollbar in JS $('#slidesContainer').css('overflow', 'hidden'); // Wrap all .slides with #slideInner div slides .wrapAll('&lt;div id="slideInner"&gt;&lt;/div&gt;') // Float left to display horizontally, readjust .slides width .css({ 'float' : 'left', 'width' : slideWidth }); // Set #slideInner width equal to total width of all slides $('#slideInner').css('width', slideWidth * numberOfSlides); // Insert controls in the DOM $('#PageBG') .prepend('&lt;a href="#" class="control" id="previous"&gt;&lt;span&gt;Previous&lt;/span&gt;&lt;/a&gt;') .append('&lt;a href="#" class="control" id="next"&gt;&lt;span&gt;Next&lt;/span&gt;&lt;/a&gt;'); // Hide left arrow control on first load manageControls(currentPosition); // Create event listeners for .controls clicks $('.control') .bind('click', function(){ // Determine new position currentPosition = ($(this).attr('id')=='next') ? currentPosition+1 : currentPosition-1; // Hide / show controls manageControls(currentPosition); // Move slideInner using margin-left $('#slideInner').animate({ 'marginLeft' : slideWidth*(-currentPosition) },800, 'linear'); }); $('.SlideSelect') .bind('click', function(){ // Move slideInner using margin-left $('#slideInner').animate({ 'marginLeft' : slideWidth*(-$(this).attr('id')) },800, 'linear'); </code></pre> <p>});</p> <p>I want slideWidth to change based on the window size so when the window is resized the slideWidth changes but I don't seem to be able to get this to work.</p> <p>Does anyone know why?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload