我有一个 else..if 语句,它根据 为变量赋值window.width
,我想做的是在 a 中使用这个值,window.resize
但现在 get'undefined'
获取currentSize
该值。我应该怎么做才能获得价值?
JS
//Code ran onload
if(windowWidth >= 924) {
incrementValue = 3;
currentSize = 'desktop';
}
else if(windowWidth > 615 && windowWidth < 924) {
incrementValue = 2;
currentSize = 'tablet';
}
else {
incrementValue = 1;
currentSize = 'mobile';
}
$(window).resize(function() {
windowWidth = $(window).width();
if(windowWidth >= 924) {
incrementValue = 3;
var newSize = 'desktop';
}
else if(windowWidth > 615 && windowWidth < 924) {
incrementValue = 2;
var newSize = 'tablet';
}
else {
incrementValue = 1;
var newSize = 'mobile';
}
console.log(currentSize); //'undefined'
if (currentSize !== newSize) {
var currentSize = newSize;
incrementTotal = 0;
slideIndex = 0;
//Reset slider to start
$carouselSlides.css( 'left', 0 );
}
});