javascript - The difference between html and body in jquery selector
怪我咯
怪我咯 2017-05-19 10:43:53
0
2
722
//第一种是正常的点击返回顶部
// 滚动条
$('#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.

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
習慣沉默

$('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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template