任何人都知道我可以滾動到頁面上的某個位置時,點擊使用JS的鏈接?例如,點擊時,滾動到窗口頂部500px的位置。滾動到窗口頂部點擊某個位置
我使用的ScrollMagic插件和我的網站內容被滾動位置激活,所以我不可能只使用錨鏈接。它也不能從當前位置偏移,因爲這也不起作用。
任何想法?
任何人都知道我可以滾動到頁面上的某個位置時,點擊使用JS的鏈接?例如,點擊時,滾動到窗口頂部500px的位置。滾動到窗口頂部點擊某個位置
我使用的ScrollMagic插件和我的網站內容被滾動位置激活,所以我不可能只使用錨鏈接。它也不能從當前位置偏移,因爲這也不起作用。
任何想法?
我reccomand的jQuery做:)在這裏工作的所有設備版本
$(document).ready(function() //When the page is ready, load function
{
$("#some_id").click(function() // When arrow is clicked
{
$("body,html").animate(
{
scrollTop : 500 // Scroll 500px from top of body
}, 400); //how fast the scrolling animation will be in miliseconds
});
});
這應該做的伎倆在純JS:
document.body.scrollTop = 500;
會是這樣的工作?它會給你一個平滑的滾動到該位置爲你連接它的任何鏈接。
$('a[href*=#]').click(function() {
$('html, body').animate({scrollTop: 500}, 500);
}
只需使用[scrollTop的(Y)](https://api.jquery.com/scrollTop/# scrollTop2) –