我知道标题不是最具描述性的,还有更多类似问题的主题,但我找不到任何答案。事实上,多亏了你们,我才走到这一步,这就是我想要做的。
我有一个 DIV,我想在页面滚动到某个位置(触发器)时显示它,标记为#othdiv。当您向下滚动到标记为#othdiv2的下一个位置(触发器)时,此 DIV 会消失。
感觉这是一个非常简单的解决方案,但我就是想不通。我尝试过条件 if 语句、重复代码、删除行、新变量……叹息……请帮忙。
$(document).ready(function() {
$("#dvid").hide(); //hide your div initially
var topOfOthDiv = $("#othdiv").offset().top;
var topOfOthDiv2 = $("#othdiv2").offset().top;
$(window).scroll(function() {
if($(window).scrollTop() > topOfOthDiv) { //scrolled past the other div?
$("#dvid").show(); //reached the desired point -- show div
}
else
if($(window).scrollTop() < topOfOthDiv) { //scrolled past the other div?
$("#dvid").hide(); //reached the desired point -- show div
}
});
});
当前代码示例:http: //jsfiddle.net/DnJ2z/124/
底线:我正在尝试做类似的事情: http: //mailchimp.com/2012/ (注意标题[应用程序、支持、操作等])