回到顶部的俩种方式
一、使用js
$('html, body').animate({ scrollTop: 0 }, 'fast');//带动画 $('html,body').scrollTop(0); //不带动画
$(window).scroll(function () { //You've scrolled this much: $('p').text("You've scrolled " + $(window).scrollTop() + " pixels"); });
二、使用 a 标签的name属性
top Click here go back to the top.
三、获取高度
1. 整个文档高度
var body = document.body, html = document.documentElement; var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); // 或者 var height = $(document).height();
2. 当前屏幕高度
var wheight = $(window).height();
HTML代码
TOP
查看更多关于HTML学习笔记之二(回到顶部与回到底部)_html/css_WEB-ITnose的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did108266