//第一種是正常的點(diǎn)擊返回頂部
// 滾動(dòng)條
$('#back_to_top').click(function(){
// $(window).scrollTop(0);
})
//第二種是加了滾動(dòng)條變化的動(dòng)畫(huà)效果
// 滾動(dòng)條
$('#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.
走同樣的路,發(fā)現(xiàn)不同的人生
$('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