簡(jiǎn)單jQuery根據(jù)屏幕下拉到一定高度顯示返回頂部按鈕代碼

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標(biāo)題文檔</title>
<style>
.panel{overflow:hidden;width:100%;height:1000px;}
#return-top{position:fixed;bottom:10%;right:50px; width:60px;height:60px;background-color:#eee; text-align:center; display:none;}
#return-top a{text-decoration:none; }
 
</style>
<script src="js/jquery-1.8.3.min.js"></script>
</head>
 
<body>
<div class="panel" style="background-color:red;"></div>
<div class="panel" style="background-color:blue;"></div>
<div class="panel" style="background-color:yellow;"></div>


<div id="return-top"><a href="#">返回頂部</a></div>


<script>
$(function(){
    $('#return-top').hide();
    $(function(){
        $(window).scroll(function(){
            if($(window).scrollTop()>300){
                $('#return-top').fadeIn(300);
                }
                else{$('#return-top').fadeOut(200);}
            
            });
            $('#return-top').click(function(){
                
                $('body,html').animate({scrollTop:0},300);
                return false;
                
                })
        
        })
    
    
    })
</script>
</body>
</html>

作者:仰望星空的包子
來源:CSDN
原文:https://blog.csdn.net/sinat_21206105/article/details/52287654
版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請(qǐng)附上博文鏈接!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容