滚动以使 div 可见

Scrolling to make div visible

我正在努力让全日历调度程序滚动到人们点击的区域,这段代码有些工作,但根据屏幕尺寸,它应该缩放到的实际区域通常会滚动过去,并且在 window.

中不可见

有没有办法确保 table header 单元格的左边框与 window 的左边框对齐?

在视图中,在 div $('.fc-time-area.fc-widget-header .fc-scroller') 中有一个水平滚动 table,我想要可见的单元格可以通过这样的东西找到:$(".fc-time-area.fc-widget-header .fc-content th[data-date='2017-2-11T10:00:00']")

var centerTime = function (day) {
    $('.fc-time-area.fc-widget-header .fc-scroller').animate({
        scrollLeft: $(".fc-time-area.fc-widget-header .fc-content").find("th[data-date='" + day + "']").offset().left
    }, 750);
};

我明白了。显然使用 offset()position() 是有区别的。通过改变这个简单的东西,它现在工作得很好。

var centerTime = function (day) {
    $('.fc-time-area.fc-widget-header .fc-scroller').animate({
        scrollLeft: $(".fc-time-area.fc-widget-header .fc-content").find("th[data-date='" + day + "']").offset().left
    }, 750);
};