1

window.resize の後に現在の高さの値を取得するにはどうすればよいですか?

$(window).resize(function(){
    currHeight = $('#window-fixed').height();        
});

console.log( currHeight );
//Uncaught ReferenceError: currHeight is not defined

$('a.stp').click(function(e){
    e.preventDefault();

    var href = $(this).data('id');        

    $('html, body').animate({
        scrollTop: ( $(href).offset().top ) - currHeight
    }, 1200);        

});

ありがとう

4

2 に答える 2

0

currHeight次のようにグローバル変数として宣言します。

var currHeight = 0;

$(window).resize(function(){
    currHeight = $('#window-fixed').height();        
}).resize();    //  Calling resize() method on page load only

console.log( currHeight );  // You will get the `window-fixed` height here now
于 2013-11-14T08:08:46.700 に答える