简体   繁体   English

单击锚定链接(例如fullpage.js)时快速滚动

[英]Snap scrolling when clicking an anchor link like fullpage.js

I have a page that is split into two columns. 我有一个分为两列的页面。 first column is fixed, the 2nd column vertical scrolls. 第一列固定,第二列垂直滚动。 Currently, when you click on a link to go to the 2nd column, it will smooth scroll to that anchor. 当前,当您单击链接转到第二列时,它将平滑滚动到该锚点。

What I'm trying to do is this: when a user tries to scroll, it will let them scroll, so currently they can basically scroll to the in-between section of anchor 1 and 2. I want it so if the user scrolls, it's as if they clicked the link and it goes entirely to the 2nd anchor. 我想做的是:当用户尝试滚动时,它会让他们滚动,因此当前他们基本上可以滚动到锚点1和2的中间部分。我希望这样做,如果用户滚动,好像他们单击了链接一样,它完全转到了第二个锚点。 If the user scrolls up, then it goes entirely to the 1st anchor and there's no way they can get into the in-between part of it. 如果用户向上滚动,则它将完全转到第一个锚点,他们将无法进入它的中间部分。

I know that fullpage.js already does this, the problem is that I don't have a lot of control with it. 我知道fullpage.js已经做到了,问题是我没有太多控制权。 If I could get this working manually, then I can control what happens when I'm on mobile as well. 如果我可以手动进行此操作,那么我也可以控制在移动设备上发生的情况。 I'm using the code on this page for scrolling: 我正在使用此页面上的代码进行滚动:

https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_eff_animate_smoothscroll https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_eff_animate_smoothscroll

and here's what my page code looks like: 这是我的页面代码的样子:

  <a name="#bespoke" id="bespoke"></a>
  <div class="v-image-1" style="height:100%">
    <div class="scroller">

      <div class="row no-margin">
        <div class="col-md-offset-1 col-md-10 no-padding">BESPOKE</div>
        <div class="col-md-1 no-padding"><a href="#targeted"><img src="images/but-scroll.png" alt="scroll" /></a></div>
      </div> 

    </div>
  </div>
<a name="targeted" id="targeted"></a>
<div class="v-image-2">
  <div class="scroller">

    <div class="row no-margin">
      <div class="col-md-offset-1 col-md-10 no-padding">TARGETED</div>
      <div class="col-md-1 no-padding"><a href="#bespoke"><img src="images/but-scroll.png" alt="scroll" /></a></div>
    </div>

  </div>
</div>

I know that fullpage.js already does this, the problem is that I don't have a lot of control with it. 我知道fullpage.js已经做到了,问题是我没有太多控制权。 If I could get this working manually, then I can control what happens when I'm on mobile as well. 如果我可以手动进行此操作,那么我也可以控制在移动设备上发生的情况。 I'm using the code on this page for scrolling: 我正在使用此页面上的代码进行滚动:

You don't specify why you lack of control. 您没有指定为什么缺乏控制力。 Perhaps if you can tell us what you miss in fullPage.js, we can tell you how to proceed? 也许如果您可以告诉我们在fullPage.js中错过了什么,我们可以告诉您如何进行?

fullPage.js has plenty of features, options and callbacks. fullPage.js具有许多功能,选项和回调。 Within them, you can find multiple responsive options such as responsiveWidth , responsiveHeight and responsiveSlides . 在它们中,您可以找到多个响应选项,例如responsiveWidthresponsiveHeightresponsiveSlides Which provides in most cases all you need. 在大多数情况下,这提供了您所需的一切。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM