2017-08-07 62 views
0

我想要更改var screenWidth;当调整窗口到手机。当我加载时它正在工作,但在调整大小时没有。我在这里错过了什么?我正在使用jssor滑块。我可以在控制台中看到screenWidthFunction()正在工作。Javascript - 更改变量的大小不工作与JSSOR滑块

JS:

var screenWidth; 

    function screenWidthFunction() { 

     if($(window).innerWidth() < 768) {    
      screenWidth = 960; 
      console.log(screenWidth); 
     } else { 
      screenWidth = 1920; 
      console.log(screenWidth); 
     } 

    } 

    //var screenWidth = 1920; 

    screenWidthFunction(); 

    function ScaleSlider_home_1() { 
     var refSize_home_1 = jssor_home_1_slider.$Elmt.parentNode.clientWidth; 
     if (refSize_home_1) { 
      refSize_home_1 = Math.min(refSize_home_1, screenWidth); 
      jssor_home_1_slider.$ScaleWidth(refSize_home_1); 
     } 
     else { 
      window.setTimeout(ScaleSlider_home_1, 30); 
     } 
    } 
    ScaleSlider_home_1(); 

    $(window).bind('load',function(){ 
     //screenWidthFunction(); 
     ScaleSlider_home_1(); 
    });    

    $(window).bind('resize',function(){ 
     screenWidthFunction(); 
     ScaleSlider_home_1(); 
    });    

    $(window).bind('orientationchange',function(){ 
     //screenWidthFunction(); 
     ScaleSlider_home_1(); 
    }); 

这是我的小提琴:http://jsfiddle.net/df58scsk/1/

+0

显示你的HTML和CSS – ewwink

+0

请看这里:http://jsfiddle.net/df58scsk/1/ –

+0

它与全宽大小,你的意思是固定的宽度,如果'<768' – ewwink

回答

0

你可以试试这个

$(window).resize(function() { 
    screenWidthFunction(); 
    ScaleSlider_home_1(); 
}); 

你并不需要绑定事件

+0

不幸的是没有区别。 JSSOR仍然由于某种原因而忽略变量变化... –

+0

你能为它设置小提琴吗?所以我检查你的代码? –

+0

请看这里:jsfiddle.net/df58scsk/1 –