Javascript 单击可从窗口顶部滚动到特定位置
有人知道我如何在使用JS单击链接时滚动到页面上的某个位置吗?例如,单击时,从窗口顶部滚动到500px的位置 我正在使用ScrollMagic插件,我的网站内容被scroll位置激活,所以我不可能只使用锚链接。此外,它不能从当前位置偏移,因为这也不起作用Javascript 单击可从窗口顶部滚动到特定位置,javascript,jquery,html,Javascript,Jquery,Html,有人知道我如何在使用JS单击链接时滚动到页面上的某个位置吗?例如,单击时,从窗口顶部滚动到500px的位置 我正在使用ScrollMagic插件,我的网站内容被scroll位置激活,所以我不可能只使用锚链接。此外,它不能从当前位置偏移,因为这也不起作用 有什么想法吗?这在纯js中应该可以做到: document.body.scrollTop = 500; 这在纯js中应该可以做到: document.body.scrollTop = 500; 你喜欢这个工作吗?它将为您提供一个平滑的滚动到该
有什么想法吗?这在纯js中应该可以做到:
document.body.scrollTop = 500;
这在纯js中应该可以做到:
document.body.scrollTop = 500;
你喜欢这个工作吗?它将为您提供一个平滑的滚动到该位置的链接
$('a[href*=#]').click(function() {
$('html, body').animate({scrollTop: 500}, 500);
}
你喜欢这个工作吗?它将为您提供一个平滑的滚动到该位置的链接
$('a[href*=#]').click(function() {
$('html, body').animate({scrollTop: 500}, 500);
}
我用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
});
});
我用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
});
});
简单使用简单使用