2017-07-22 49 views

回答

0

鏈接http://api.jquery.com/width/

// Returns width of browser viewport 
$(window).width(); 

// Returns width of HTML document 
$(document).width(); 
+0

否否 我想定義窗口寬度的代碼中只有一個變量..然後,如果窗口被調整大小,讓我在同一個變量的寬度..就像編碼調用引用! –

0

我覺得這answeeeeeeeeeeeeeerrrrrrr

每個人都可以使用它::::

<span class="output"></span> 
<script src="js/vendor/jquery.js"></script> 
<script> 

var window_width; 
var call; 
function get_width(window_width){ 
    window_width = $(window).width(); 
    return window_width; 
}; 
jQuery(document).ready(function($) { 
    $(window).resize(function() { 
     call = get_width(); 
     console.log("on resize: "+call); 
     $('.output').text(call); 
    }); 
    call = get_width(); 
    console.log("on load: "+call); 
    // show output 
    $('.output').text(call); 
}); 


</script> 
相關問題