ScrollTop计算不正确

时间:2019-03-05 01:05:59

标签: javascript jquery html css

一段时间以来,我一直在拔头发,感谢您的帮助。当您尝试转到以下链接时,医师的详细信息会显示并正确滚动:https://artesiageneral.com/our-staff/#gallery-details-william-j-baggs-md

但是,当您转到其中一位高级从业人员的同一页面上的链接时。 https://artesiageneral.com/our-staff/#gallery-details-ron-haugen-dnp,它会打开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);
        }

0 个答案:

没有答案
相关问题