jQuery移动到页面加载时的锚点位置 [英] jQuery move to anchor location on page load

查看:60
本文介绍了jQuery移动到页面加载时的锚点位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的页面设置,例如:

I have a simple page setup such as:

<div id="aboutUs">
  About us content...
</div>
<div id="header">
  Header content...
</div>

页面加载后,我需要页面自动向下滚动(无需动画)到#header,因此用户除非向上滚动,否则无法看到关于我们" div.

When the page loads, I need the page to automatically scroll down (no animation needed) to #header, so the user cannot see the About Us div unless they scroll up.

#aboutUs具有固定的高度,因此不需要任何变量来确定高度或任何东西……甚至需要.

#aboutUs has a fixed height, so there isn't any need for any variables to determine the height or anything... if that's even needed.

我遇到了另一个问题,并试图根据我的情况修改一些答案,但似乎没有任何效果.

I came across this other question and tried to modify some of the answers for my situation, but nothing seemed to work.

任何帮助将不胜感激.

推荐答案

说明

您可以使用jQuery的.scrollTop().offset()方法

查看我的示例以及 jsFiddle演示

$(function() {
    $(document).scrollTop( $("#header").offset().top );  
});

更多信息

  • jsFiddle演示
  • jQuery.scrollTop()
  • jQuery.offset()
  • More Information

    • jsFiddle Demonstration
    • jQuery.scrollTop()
    • jQuery.offset()
    • 这篇关于jQuery移动到页面加载时的锚点位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆