【问题标题】:Is elmnt.scrollIntoView usable with CSS class name or otherwise to scroll SharePoint calendarelmnt.scrollIntoView 是否可用于 CSS 类名称或以其他方式滚动 SharePoint 日历
【发布时间】:2019-12-27 19:55:35
【问题描述】:

我正在尝试自动滚动扩展的 SharePoint 日历,以便在分辨率有限的显示器上显示当前日期/周。

我没有JS知识,但尝试使用JS通过参考今天的日期CSS类名来滚动。它似乎没有完成这项工作。

我尝试的是:

function myFunction() {
  var elmnt = document.getElementsByClassName("ms-acal-today");
  elmnt.scrollIntoView();
}

我推断该脚本实际上适用于元素的 ID。不幸的是,SharePoint 日历中没有特定元素的 id,也不能放在那里。 所以我希望 CSS 类名可以解决问题,但无济于事。

如果在 Sharepoint 日历中,当前日期为:

<div class="ms-acal-today">
        <nobr>21</nobr>
    </div>

(如果今天是 2019 年 8 月 21 日)

【问题讨论】:

    标签: javascript sharepoint scroll


    【解决方案1】:

    没有人回答,但我设法用 jQuery 解决了这个问题,这里适合任何可能需要它的人:

        $(document).ready(function() { 
    var $container = $("html,#s4-workspace");
    var $scrollTo = $('.ms-acal-today');
    
    $container.animate({scrollTop: $scrollTo.offset().top - $container.offset().top + $container.scrollTop(), scrollLeft: 0},600);
    });
    

    当然,必须首先在 SharePoint 中启动 jQuery。 我通过在站点资产中上传 jquery-3.4.1.min.js 并在 Web 部分中引用它来做到这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      相关资源
      最近更新 更多