javascript如何设置滚动条位置

JavaScript设置滚动条位置的方法:

JS控制滚动条的位置:

window.scrollTo(x,y);

竖向滚动条置顶(window.scrollTo(0,0);

竖向滚动条置底 window.scrollTo(0,document.body.scrollHeight)

JS控制TextArea滚动条自动滚动到最下部

document.getElementByIdx_x('textarea').scrollTop = document.getElementByIdx_x('textarea').scrollHeight

 

获得滚动条距离顶部位置

function getScrollTop(){
var scrollTop=0;
if(document.documentElement&&document.documentElement.scrollTop){
scrollTop=document.documentElement.scrollTop;
}else if(document.body){
scrollTop=document.body.scrollTop;
}
return scrollTop;
}
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容