您的位置:首页 > Web前端 > JQuery

jquery 回到顶部,简洁大方

2016-08-02 11:51 357 查看

效果

HTML

<div id="back-to-top" title="返回顶部"><i class="fa fa-chevron-up"></i></div>

style

<style>
/*returnTop*/
div#back-to-top {
font-size: 40px;
position: fixed;
display: none;
bottom: 100px;
right: 60px;
cursor: pointer;
}
</style>

script

<script>
$(function () {
$(window).scroll(function () {
if ($(window).scrollTop() > 200) {
$("#back-to-top").fadeIn(1000);
}
else {
$("#back-to-top").fadeOut(1000);
}
});

//点击返回顶部
$("#back-to-top").click(function () {
$('body,html').animate({ scrollTop: 0 }, 1000);
return false;
});
});
</script>

注意,要引入 font-awesome.css 才可显示图标

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: