返回到頂部按鈕實現

<div id="gotop"><span class="glyphicon glyphicon-chevron-up"></span></div>  //bootstrap圖標


#gotop{ 
display:none;
font-size: 25px;
color:#fff;
text-align: center;
background: #aaa;
padding:10px 15px;
position:fixed;
right:50px;
bottom:50px;
cursor:pointer;   
}


function goTop()

{
    $(window).scroll(function(e) {
        //若滾動條離頂部大於100元素
        if($(window).scrollTop()>100)
            $("#gotop").fadeIn(1000);//以1秒的間隔漸顯id=gotop的元素
        else
            $("#gotop").fadeOut(1000);//以1秒的間隔漸隱id=gotop的元素
    });

};



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章