ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 返回顶部

返回顶部

原创 Linux操作系统 作者:wang_0720 时间:2017-08-02 15:59:16 0 删除 编辑
1 html

点击(此处)折叠或打开

  1. <div class="side-tool">
  2.       <ul style="list-style-type: none;">
  3.         <li>
  4.           <div id="scrolltop" class="function-button">
  5.             <span class="glyphicon glyphicon-chevron-up" style="padding-top: 16px;"></span>
  6.           </div>
  7.         </li>
  8.       </ul>
  9.  </div>
2 css

.side-tool {
  position: fixed;
  bottom: 40px;
  right: 40px;
  z-index: 9;
}

.function-button {
  width: 50px;
  height: 50px;
  text-align: center;
  display: block;
  cursor: pointer;
  border-top-width: 1px;
  border-right-width: 1px;
  border-bottom-width: 1px;
  border-left-width: 1px;
  border-top-style: solid;
  border-right-style: solid;
  border-bottom-style: solid;
  border-left-style: solid;
  border-top-color: rgb(220, 220, 220);
  border-right-color: rgb(220, 220, 220);
  border-bottom-color: rgb(220, 220, 220);
  border-left-color: rgb(220, 220, 220);
  -moz-border-top-colors: none;
  -moz-border-right-colors: none;
  -moz-border-bottom-colors: none;
  -moz-border-left-colors: none;
  border-image-source: none;
  border-image-slice: 100% 100% 100% 100%;
  border-image-width: 1 1 1 1;
  border-image-outset: 0 0 0 0;
  border-image-repeat: stretch stretch;
  background-color: #fff;
  transition: .1s ease-in;
  transition-property: all;
  transition-duration: 0.1s;
  transition-timing-function: ease-in;
  transition-delay: 0s;
  -webkit-transition: .1s ease-in;
  transition-property: all;
  transition-duration: 0.1s;
  transition-timing-function: ease-in;
  transition-delay: 0s;
  -moz-transition: .1s ease-in;
  transition-property: all;
  transition-duration: 0.1s;
  transition-timing-function: ease-in;
  transition-delay: 0s;
 -o-transition: .1s ease-in;
 -ms-transition: .1s ease-in;
}

3 js
$(function(){
//首先将#scrolltop隐藏
  $("#scrolltop").hide();
  //当滚动条的位置处于距顶部100像素以下时,跳转链接出现,否则消失
  $(function() {
    $(window).scroll(function() {
      if ($(window).scrollTop() > 100) {
        $("#scrolltop").show();
      } else {
        $("#scrolltop").hide();
      }
    });
    //当点击跳转链接后,回到页面顶部位置
    $("#scrolltop").click(function() {
      $('body,html').animate({
        scrollTop: 0
      },
      1000);
      return false;
    });
  });
});

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27181165/viewspace-2142978/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 页面上传头像
请登录后发表评论 登录
全部评论

注册时间:2013-11-05

  • 博文量
    111
  • 访问量
    953132