//第一种是正常的点击返回顶部
// 滚动条
$('#back_to_top').click(function(){
// $(window).scrollTop(0);
})
//第二种是加了滚动条变化的动画效果
// 滚动条
$('#back_to_top').click(function(){
$('html,body').stop().animate({
scrollTop:"0px"
},"slow")
})
The first time is $(window) and the second time is $('html,body')
What are the differences between these three? When to use window, when to use html, and when to use body?
Also why sometimes both html and body are written in.
$('html,body') Why do you need to write 2? It's because firefox ie does not support body, but chrome supports body, so I write it like this for compatibility. You can try firefox and chrome to understand.
For forms and DOM objects, obtaining relevant properties is also related to the document model. As for the scrollTop you mentioned, the xhtml mode body is 0, html is the scroll height, and the backcompat mode returns
window's scrollTop returns the scroll height pageYOffse