Javascript 使脚本从特定div的顶部开始
因此,我基本上希望脚本从“mini”div的顶部开始,但无法使其正常工作。Javascript 使脚本从特定div的顶部开始,javascript,jquery,html,css,Javascript,Jquery,Html,Css,因此,我基本上希望脚本从“mini”div的顶部开始,但无法使其正常工作。 完整脚本: $(window).scroll(checkY); function checkY() { //save this value so we dont have to call the function everytime var top = $(window).scrollTop(); $(".title").each(function () {
完整脚本:
$(window).scroll(checkY);
function checkY() {
//save this value so we dont have to call the function everytime
var top = $(window).scrollTop();
$(".title").each(function () {
var target = $(this).closest(".content");
var tTop = $("#mini").outerHeight(true);
var tBottom = target.offset().top + target.outerHeight();
if (top >= tTop && top <= tBottom) {
console.log("Show");
$(this).show();
} else {
console.log("Hide");
$(this).hide();
}
});
}
checkY();
$(窗口)。滚动(选中);
函数checkY(){
//保存该值,这样我们就不必每次都调用该函数
var top=$(window.scrollTop();
$(“.title”)。每个(函数(){
var target=$(this).closest(“.content”);
var tTop=$(“#mini”).outerHeight(真);
var tBottom=target.offset().top+target.outerHeight();
如果(顶部>=tTop&&top为什么不将迷你样式设置为
position:relative;
和内部div到
position: absolute;
top:0
position: absolute;
top:0