jquery返回頁面頂部


1、此博文圖片樣式引用騰訊網站,效果如下:

2、樣式設置:

#toTop {
       /*選中的背景圖片的大小*/
    width: 54px;
    height: 54px;
    display: none;/*剛開始不顯示*/
    position: fixed;
    right: 25px;/*距離右邊大小值*/
    bottom: 45px;/*距離底部大小值*/
       /*選定圖片區域*/
    background-image: url(images/qqbg_1.5.5.png);
    background-repeat: no-repeat;
    background-position: -700px -110px;
    opacity: 0.3; /*透明度*/
}

#toTop:hover {
    opacity: 1;/*懸停時不透明*/
    filter: alpha(opacity = 100);
}

3、JS代碼:

<a href="#" target="_self" id="toTop" title="返回頂部" onclick="window.scrollTo(0,0);return false"></a>
<script type = "text/javascript">
    function toTopHide(){
        $(document).scrollTop()>400?
                $("#toTop").show()
                    :$("#toTop").hide();
    }
    $(window).scroll(function(){toTopHide()});
</script>

 

 推薦一個自己業余時間開發的網盤搜索引擎,360盤搜www.360panso.com


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM