zoukankan      html  css  js  c++  java
  • 使用js写点击一个事件使页面返回顶部以及控制一个元素在右下角的固定位置的方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
       body{margin:0; padding:0}
       #to_top{
      30px;
      height:40px;
      padding:20px;
      font:14px/20px arial;
      text - align: center;
      background: #06c;
      position: absolute;
      cursor: pointer;
      color: #fff;
     }
    </style>
    </head>

    <body style="height:1000px;">
                 <h1>返回顶部</h1 >
        <div id = "to_top"> 返回顶部
              </div>
    </body>
    </html>
    <script type="text/javascript">
     window.onload = function(){
     var oTop = document.getElementById("to_top");
     var screenw = document.documentElement.clientWidth || document.body.clientWidth;
     var screenh = document.documentElement.clientHeight || document.body.clientHeight;
     oTop.style.left = screenw - oTop.offsetWidth +"px";
     oTop.style.top = screenh - oTop.offsetHeight + "px";
     window.onscroll = function(){
       var scrolltop = document.documentElement.scrollTop || document.body.scrollTop;
       oTop.style.top = screenh - oTop.offsetHeight + scrolltop +"px";
      } 
     oTop.onclick = function(){
      document.documentElement.scrollTop = document.body.scrollTop =0;
      }

    /**jquery的写法实现返回顶部
     jQuery("#to_top").click(function(){
      jQuery("html,body").animate({'scrollTop':0},100)
     })
    **/

    </script>


     

  • 相关阅读:
    android有进度条的下载图片并且显示图片
    在Java中,直接将类的对象使用system.out.println输出
    改写toString
    Android中Uri的使用
    重写toString()
    权限管理
    实训
    第一次上传文件成功
    sql server 2005 JDBC连接遇到的问题
    JSP 权限控制
  • 原文地址:https://www.cnblogs.com/dearxinli/p/2772777.html
Copyright © 2011-2022 走看看