簡體   English   中英

我想用 link_to 滾動頁面(ruby on rails)

[英]I want to scroll page with a link_to (ruby on rails)

這是說明我的主題的一個例子,它是在頁面不同部分滾動的代碼:

<!DOCTYPE html>
<html>
<head>
<style>
html {
  scroll-behavior: smooth;
}

#section1 {
  height: 600px;
  background-color: pink;
}

#section2 {
  height: 600px;
  background-color: yellow;
}
</style>
</head>
<body>

<h1>Smooth Scroll</h1>

<div class="main" id="section1">
  <h2>Section 1</h2>
  <p>Click on the link to see the "smooth" scrolling effect.</p>
  <a href="#section2">Click Me to Smooth Scroll to Section 2 Below</a>
  <p>Note: Remove the scroll-behavior property to remove smooth scrolling.</p>
</div>

<div class="main" id="section2">
  <h2>Section 2</h2>
  <a href="#section1">Click Me to Smooth Scroll to Section 1 Above</a>
</div>

</body>
</html>

所以我的問題是可以通過在軌道上使用 ruby 的 link_to 來做到這一點嗎?

我在軌道上使用 ruby 我希望錨鏈接跳轉到頁面的特定部分^^

謝謝 =)

Looking into https://api.rubyonrails.org/v5.2.1/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to i guess you'd just pass the hash and id as the second param into the link_to function喜歡:

<%= link_to "Click Me to Smooth Scroll to Section 2 Below", "#section2" %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM