2016-05-16 40 views
0

我有一個腳本(https://github.com/SubZane/flyPanels)應該只能在小型設備上執行。媒體查詢/匹配媒體上的腳本

<script> 
document.addEventListener("DOMContentLoaded", function(event) { 
    FastClick.attach(document.body); 
    flyPanels.init({ 
      treeMenu: { 
       init: true 
      }, 
      search: { 
       init: true, 
       saveQueryCookie: true 
      } 
    }) 
}); 

</script> 

我如何做到這一點:

的腳本由叫什麼名字?

+1

[如何識別屏幕大小]的可能重複(http://stackoverflow.com/questions/12195371/how-to-identify-screen-size) –

回答

0

請參閱本link

所以基本上你可以檢查一個if語句像

if(screen.width == 768){ 
    //your code here 

} 

...然後有它在你的事件代碼。 只需詢問您希望代碼工作的屏幕尺寸並檢查。 PS:js的屏幕對象在px中有規範....所以一定要檢查px。