【问题标题】:Allow scrolling beyond bottom of page允许滚动超出页面底部
【发布时间】:2019-03-28 00:46:40
【问题描述】:

我正在为这样的标题使用 ids 链接

<h2 id="section-name">section x</h2>

并有这样的链接可以向下滚动到它们:

<a href=#section-name>section x</a>

问题(在我看来)是当页面短于浏览器窗口高度,或者标题靠近页面底部时,跳转链接无效,因为浏览器没有可用的滚动。

我希望滚动条能够正常工作,并根据需要将页脚颜色向下扩展。

我能想到的唯一方法是在页脚上有一个巨大的padding-bottom: 200em;,但随后很容易滚动到虚无中,我不得不猜测用户的屏幕有多高。

有没有更好的办法?


这是我正在处理的http://demo.schemaexplorer.io/tables/Genre?GenreId=2&_rowLimit=100#data - 请注意网址末尾的#data,但请注意它不会将“数据”标题放在浏览器窗口的顶部。

【问题讨论】:

  • 这一直是 AFAIK 的事情。我认为在不增加文档长度的情况下没有办法解决这个问题。
  • 您只能将相对于文档高度的元素带入视口。如果文档在视口中包含所有元素,则没有什么可以滚动到的。您可以将页脚固定到视口的底部:0 并像您说的那样添加填充,或者动态添加一些其他间距偶然性,但就目前而言,它按预期工作。
  • 请查看一些 css 功能,例如过度滚动行为,您可以拥有/控制反弹效果,这是您可以使用滚动区域/视图执行的最大操作
  • 我不认为过度滚动是我在developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior 之后的样子,但谢谢,了解一下很有用。

标签: html css href user-experience


【解决方案1】:

我的谦虚建议是通过点击使用部分突出显示。

通过单击链接获取部分 id 并用某个类突出显示它。

使用过渡使其更平滑。

$('a').click(function() { 
	
  var currentSection = $(this).attr('href');
  $(currentSection).addClass('highlighted');

  setTimeout(function() {
      $(currentSection).removeClass('highlighted');
  }, 2000);
  
});
div {
  height: 200px;
  transition: background-color 1000ms linear;
}

.highlighted {
  background-color: rgba(0,0,0,0.2);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#section1">Section 1</a>

<a href="#section2">Section 2</a>

<div>
some text
</div>
<div id="section1">
section1
</div>

<div id="section2">
section2
</div>

【讨论】:

  • 很好,谢谢!这肯定会吸引人们注意它跳到的东西。
猜你喜欢
  • 1970-01-01
  • 2018-03-23
  • 2021-10-15
  • 2011-05-14
  • 1970-01-01
  • 2012-07-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多