好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

HTML学习笔记之二(回到顶部与回到底部)_html/css_WEB-ITnose

回到顶部 回到底部

回到顶部的俩种方式

一、使用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的详细内容...

  阅读:34次