嗨,请有人指出我正确的方向,我需要将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
答案 0 :(得分:2)
将您的变量设为全局,然后您可以使用,如下所示
window.height = "This is global!";
答案 1 :(得分:1)
您需要在函数jqUpdateSize
的末尾返回高度