我在页面上有一个介绍div,用于计算窗口高度,以便填充窗口:
resizeWindow();
$(window).resize(resizeWindow);
function resizeWindow() {
var ww = $(window).width();
var bh = $(document).height();
var wh = $(window).height();
featureHeight = wh - 0;
$('#intro').css({'height':featureHeight+'px'});
}
我想设置它,一旦用户滚过此div,向上滚动到该介绍div被禁用。
这可能吗?任何帮助将不胜感激。
更新
将找到的函数here结合起来,这就是诀窍:
resizeWindow();
$(window).resize(resizeWindow);
function resizeWindow() {
var ww = $(window).width();
var bh = $(document).height();
var wh = $(window).height();
featureHeight = wh - 0;
$('#intro').css({'height':featureHeight+'px'});
var scrollPoint = featureHeight;
var scrolledPast = false;
$(window).scroll(function() {
$(window).scrollTop() > scrollPoint ? scrolledPast = true : '';
$(window).scrollTop() < scrollPoint && scrolledPast == true ? $(window).scrollTop(scrollPoint) : '';
}).scroll();
}
答案 0 :(得分:1)
将找到的函数here结合起来,这就是诀窍:
resizeWindow();
$(window).resize(resizeWindow);
function resizeWindow() {
var ww = $(window).width();
var bh = $(document).height();
var wh = $(window).height();
featureHeight = wh - 0;
$('#intro').css({'height':featureHeight+'px'});
var scrollPoint = featureHeight;
var scrolledPast = false;
$(window).scroll(function() {
$(window).scrollTop() > scrollPoint ? scrolledPast = true : '';
$(window).scrollTop() < scrollPoint && scrolledPast == true ? $(window).scrollTop(scrollPoint) : '';
}).scroll();
}
答案 1 :(得分:0)
首先,给你的div一个ID - 例如dvid,并假设另一个div(你想要检测后滚动)有一个ID otherdiv。然后你可以做这样的事情:
$(document).ready( function() {
$("#dvid").hide(); //hide your div initially
var topOfOthDiv = $("#othdiv").offset().top;
$(window).scroll(function() {
if($(window).scrollTop() > topOfOthDiv) { //scrolled past the other div?
//reached the desired point -- validate here or whatever you want
}
});
});