jQuery實現返回頂部功能,jquery實現返回頂部

來源:互聯網
上載者:User

jQuery實現返回頂部功能,jquery實現返回頂部

代碼很簡單,這裡就不多廢話了,小夥伴們看代碼吧。

HTML:        

    <!--Go to Top-->    <div id="Fixed">      <a id="goTop" class="fl" title="去頂部" href="javascript:;">去頂部</a>    </div>    <!--Go to Top end-->

CSS:    

  .fl{    display:block;    float:left;    width:50px;    height:50px;    text-align:center;    background-color:#eaeaea;    background-image:url(../images/toTop.png);  }  .fl:hover{background-color:#f48942;background-image:url(../images/toTop.png);}  #Fixed {    position: fixed;    _position: absolute;    z-index: 100;    bottom: 70px;    left: 50%;    margin-left: 530px;    _bottom: auto;_top:    expression(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-70);    width: 50px;    text-indent: -40000px;    background: #fff  }  /*置頂 end*/

Js:    

  /*置頂功能*/  $(function(){  $(window).bind('scroll', {    fixedOffsetBottom: parseInt($('#Fixed').css('bottom'))  },  function(e) {    var scrollTop = $(window).scrollTop();    var referFooter =$('#footer');    scrollTop > 100 ? $('#goTop').show() : $('#goTop').hide();    if (!/msie 6/i.test(navigator.userAgent)) {      if ($(window).height() - (referFooter.offset().top - $(window).scrollTop()) > e.data.fixedOffsetBottom) {        $('#Fixed').css('bottom', $(window).height() - (referFooter.offset().top - $(window).scrollTop()))      } else {        $('#Fixed').css('bottom', e.data.fixedOffsetBottom)      }    }  });  $('#goTop').click(function() {    $('body,html').stop().animate({      'scrollTop': 0,      'duration': 100,      'easing': 'ease-in'    })  });  });  /*置頂功能 end*/

您可能感興趣的文章:
  • JQuery 動畫卷頁 返回頂部 動畫特效(相容Chrome)
  • 基於jquery的返回頂部效果(相容IE6)
  • 仿新浪微博返回頂部的jquery實現代碼
  • js+JQuery返回頂部功能如何?
  • 用jQuery實現的智能隱藏、滑動效果的返回頂部代碼
  • jQuery實現返回頂部功能適合不支援js的瀏覽器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.