【问题标题】:How can I scroll to specific element using the waypoint scrolling?如何使用航点滚动滚动到特定元素?
【发布时间】:2019-09-25 08:44:43
【问题描述】:

元素的#2 id 仅在向下滚动后加载,因为我无法使用getElementById("#2") 获取它。

//JS代码

$(document).ready(function() {
  $('html, body').animate({
    scrollTop: $("#2").offset().top
  }, 'slow');
});

// waypoint code:
var infinite = new Waypoint.Infinite({
  element: $('.infinite-container')[0],
  context: document.getElementById('#16'),
  onBeforePageLoad: function() {
    $('.loading').show();
  },
  onAfterPageLoad: function($items) {
    $('.loading').hide();
  }
});

示例: 在页面加载时只显示 1,6,3,4,5

 1
 6
 3
 4
 5

向下滚动后,我只得到 2,

 2

我想在第一次加载年龄时直接滚动到'2'元素。

【问题讨论】:

  • 根本不清楚您要做什么或问题出在哪里。您能否编辑问题以提供更多详细信息。
  • @RoryMcCrossan 现在知道了吗?

标签: javascript python jquery jquery-waypoints waypoint


【解决方案1】:

您应该使用不带“#”的getElementById([id]) 函数。

对于你的情况:

document.getElementById('#16')这一行改为document.getElementById('16')

更多信息可以在这里找到:Document.getElementById()

【讨论】:

    猜你喜欢
    • 2014-09-04
    • 2011-03-14
    • 1970-01-01
    • 2019-10-08
    • 2013-02-28
    • 2022-10-14
    • 2020-01-26
    • 2021-04-24
    • 1970-01-01
    相关资源
    最近更新 更多