0

嗨,请有人指出我正确的方向,我需要传递height到我的窗口滚动功能

$(window).scroll(function() {       
    var scrolled = $(window).scrollTop();

    //Content
    if(scrolled >= 0 && scrolled < 342) {
             $('#intro h2, #intro .down').stop().animate({ opacity: 1 }, {queue: true, duration:250, easing:"easeOutQuad"});
        } else if (scrolled >= 342 && scrolled < 560) {
             $('#intro h2, #intro .down').stop().animate({ opacity: 0 }, {queue: true, duration:250, easing:"easeOutQuad"});
        } else if (scrolled >= 560) {
             $('#intro h2, #intro .down').stop().css({ opacity: 0 });
        }




        //Navigation
        if(scrolled >= 0 && scrolled < 342) {
             $('#header h1 a:link').stop().css({ width: 101 });
             $('#header li .service').stop().css({ background: 'none', color: '#ccc'}, {queue: true, duration:50, easing:"easeOutQuad"});
        } else if (scrolled >= 342 && scrolled < 560) {
             $('#header h1 a:link').stop().css({ width: 42 });
             $('#header li .service').stop().css({background: '#54C2D9', color: '#fff'}, {queue: true, duration:50, easing:"easeOutQuad"});
        } else if (scrolled >= 560) {
             $('#header h1 a:link ').stop().css({ width: 42 });
        }



console.log(scrolled);  
});

function jqUpdateSize(){
    // Get the dimensions of the viewport
    var height = $(window).height();

    $('#intro').css({height: height});

    console.log(height);// Display the height
};
$(document).ready(jqUpdateSize);    // When the page first loads
$(window).resize(jqUpdateSize);     // When the browser changes size
4

2 回答 2

2

使你的变量全局然后你可以使用,如下所示

window.height = "This is global!";
于 2013-02-22T12:01:00.463 回答
1

您需要在函数 jqUpdateSize 的末尾返回高度

于 2013-02-22T12:01:56.427 回答