2017-07-22 44 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> 
相关问题