Javascript ScrollTop计算不正确

Javascript ScrollTop计算不正确,javascript,jquery,html,css,Javascript,Jquery,Html,Css,这件事我已经操心了一段时间了,非常感谢你的帮助。当您尝试转到以下链接时,将显示医生的详细信息并正确滚动: 但是,当您转到某个高级从业者的同一页面上的链接时,例如,它会打开details元素,但不会正确滚动到该元素 就我所知,这两个部分的标记是相同的 我检查了适用的代码。我认为galleryItemDetailsOffset的计算不正确(大约12000px),但我不知道这是为什么。如蒙协助,将不胜感激。多谢各位 else if(location.hash.substr(1,15)=="galler

这件事我已经操心了一段时间了,非常感谢你的帮助。当您尝试转到以下链接时,将显示医生的详细信息并正确滚动:

但是,当您转到某个高级从业者的同一页面上的链接时,例如,它会打开details元素,但不会正确滚动到该元素

就我所知,这两个部分的标记是相同的

我检查了适用的代码。我认为galleryItemDetailsOffset的计算不正确(大约12000px),但我不知道这是为什么。如蒙协助,将不胜感激。多谢各位

else if(location.hash.substr(1,15)=="gallery-details")
    {
        var detailsBlock = $('[id="' + location.hash.substr(1) + '"]');
        $(".gallery_item_details_list .gallery_item_details").css("display", "none");
        detailsBlock.css("display", "block");
        var galleryItem = $('[id="gallery-item-' + location.hash.substr(17) + '"]');
        detailsBlock.find(".prev").attr("href", (galleryItem.prevAll(":not('.isotope-hidden')").first().length ? galleryItem.prevAll(":not('.isotope-hidden')").first().find(".open_details").attr("href") : $(".mc_gallery").children(":not('.isotope-hidden')").last().find(".open_details").attr("href")));
        detailsBlock.find(".next").attr("href", (galleryItem.nextAll(":not('.isotope-hidden')").first().length ? galleryItem.nextAll(":not('.isotope-hidden')").first().find(".open_details").attr("href") : $(".mc_gallery").children(":not('.isotope-hidden')").first().find(".open_details").attr("href")));
        var visible=parseInt($(".gallery_item_details_list").height())==0 ? false : true;
        var galleryItemDetailsOffset;
        var parentDetailsList = $(detailsBlock).closest(".gallery_item_details_list");

        if(!visible)
        {
            parentDetailsList.css("display", "block").animate({height:detailsBlock.height()}, 500, 'easeOutQuint', function(){
                $(this).css("height", "100%");
                $(window).trigger("resize");
            });
            galleryItemDetailsOffset = parentDetailsList.offset();
            if(typeof(galleryItemDetailsOffset)!="undefined")
                $("html, body").animate({scrollTop: galleryItemDetailsOffset.top-10}, 400);
        }

这是因为在解析哈希时,图像仍然没有加载。当他们会的时候,他们会把你的目标推到下面,让你觉得计算不正确。但它在制作时是正确的。因此,要解决这个问题,请等待页面完全加载,然后再执行此脚本。