jquery实现简单的回到顶部
2016-12-12 16:18
459 查看
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
<style>
.box1{
width:35px;
height:35px;
background-color: #00b3ee;
text-align: center;
line-height: 35px;
font-size: 36px;
font-weight: bold;
text-decoration: none;
display: block;
position: fixed;
bottom:30px;
right:30px;
display: none;
}
.box1:hover{
background-color: #00B83F;
}
</style>
</head>
<body>
<div style="background:#ff9900;height:100px;"></div>
<div style="background:#ccc;height:1200px;"></div>
<a href="javascript:(0);" class="box1">↑</a>
<script>
$(function(){
$(window).scroll(function(){
var t = $(this).scrollTop();
if(t>100){
$(".box1").fadeIn();
}else{
$(".box1").fadeOut();
}
});
$(".box1").on("click",function(){
$("body,html").animate({scrollTop:0},300);
});
})
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
<style>
.box1{
width:35px;
height:35px;
background-color: #00b3ee;
text-align: center;
line-height: 35px;
font-size: 36px;
font-weight: bold;
text-decoration: none;
display: block;
position: fixed;
bottom:30px;
right:30px;
display: none;
}
.box1:hover{
background-color: #00B83F;
}
</style>
</head>
<body>
<div style="background:#ff9900;height:100px;"></div>
<div style="background:#ccc;height:1200px;"></div>
<a href="javascript:(0);" class="box1">↑</a>
<script>
$(function(){
$(window).scroll(function(){
var t = $(this).scrollTop();
if(t>100){
$(".box1").fadeIn();
}else{
$(".box1").fadeOut();
}
});
$(".box1").on("click",function(){
$("body,html").animate({scrollTop:0},300);
});
})
</script>
</body>
</html>
相关文章推荐
- Jquery实现简单回到顶部效果
- jquery实现跳到底部,回到顶部效果的简单实例(类似锚)
- jQuery实现简单的回到顶部totop功能示例
- 回到顶部最简单的JQuery实现代码
- 用jquery实现动画跳到顶部和底部(这个比较简单)
- jquery实现"跳到底部","回到顶部"效果
- jQuery实现分章节锚点“回到顶部”动画特效代码
- JavaScript简单实现网页回到顶部功能
- jQuery实现带有动画效果的回到顶部和底部代码
- jQuery实现简单而且很酷的返回顶部链接效果
- 7行JQuery代码实现回到顶部效果
- jquery 面向对象 实现 极客公园的 回到顶部 效果
- JS实现简单的回到顶部
- jquery实现的动态回到顶部特效代码
- 最简单的用jquery实现动画的跳到顶部和底部
- jquery 实现回到顶部
- jquery配合css简单实现返回顶部效果
- jQuery插件scrollToTop 4行代码实现网站回到顶部
- jquery实现"跳到底部","回到顶部"效果
- JQuery实现页面回到顶部