1
我建立了一個網站,其中主頁有一個聯繫表單部分,其他頁面沒有它。使用Jquery,我確保當用戶點擊主頁上導航欄中的聯繫人鏈接時,頁面將向下滾動到聯繫人表單部分。假設用戶在關於我們頁面並點擊聯繫人鏈接,我希望網站將用戶帶回主頁並向下滾動到聯繫人表單部分。可能嗎??從一個頁面平滑滾動到另一個頁面中的特定部分
感謝您的回答。
我建立了一個網站,其中主頁有一個聯繫表單部分,其他頁面沒有它。使用Jquery,我確保當用戶點擊主頁上導航欄中的聯繫人鏈接時,頁面將向下滾動到聯繫人表單部分。假設用戶在關於我們頁面並點擊聯繫人鏈接,我希望網站將用戶帶回主頁並向下滾動到聯繫人表單部分。可能嗎??從一個頁面平滑滾動到另一個頁面中的特定部分
感謝您的回答。
您可以使用下面的ID和滾動功能腳本輕鬆向下滾動到目標。
<script>
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
var hash = this.hash;
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
}
});
});
</script>
您可以向下如果你想針對其他頁面的部分只是用滾動到你需要使用#和HREF通過使用下面的語法
<a href="#section_target">Click Me to Smooth Scroll to Section Below</a>
節鏈接跟着目標部分Id
<a href="index.html#section_target">Take to target section in homepage</a>
目標URL與部分標識
希望這一起是你在找什麼..
檢查這是否有幫助 https://www.w3schools.com/jquery/tryit.asp?filename= tryjquery_eff_animate_smoothscroll – amit77309