2017-07-22 14 views
-1

変数の読み込みページの幅を取得したい場合、ページのサイズを変更したときに、定義したのと同じ変数で幅を取得します。私が書く 任意のコードが、私はページの読み込みとサイズ変更時の幅の取得

誰もがそれを使用することができ、このansweeeeeeeeeeeeeerrrrrrrを見つけるjqueryの言語

+0

あなたがすでに書いたコードを表示してください:) –

答えて

0

リンクhttp://api.jquery.com/width/

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

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

いいえいいえ 私は定義したいウィンドウ幅のコード内に1つの変数しかない。その後、ウィンドウのサイズが変更された場合、同じ変数で幅を取得する..コーディングで参照するように! –

0

で、このコードを実装したい に答えていない::::

<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> 
関連する問題