jquery 至顶例子

<!DOCTYPE html>
<html lang="en">
 
<head>
<meta charset="utf-8">
<title>Back to Top</title>
<style type="text/css">
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 100%;
}
 
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
 
* {
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
}
 
 
 
 
 
/***********************************************************************************************/
/* General Styling */
/***********************************************************************************************/
body {
background: #eaeaea;
font: 300 14px/21px "Helvetica Neue", "Helvetica", Arial, sans-serif;
padding: 2em 0;
}
 
p {
margin-bottom: 1.5em;
}
 
hr {
background-color: #ccc;
border: none;
height: 1px;
margin: 2em 0;
}
 
h1 {
font-size: 32px;
margin-bottom: 21px;
}
 
h3  {
font-size: 21px;
margin-bottom: 21px;
}
 
.container {
background: white;
margin: 0 auto;
padding: 4em;
width: 960px;
}
 
 
 
/***********************************************************************************************/
/* Button */
/***********************************************************************************************/
.go-top {
position: fixed;
bottom: 2em;
right: 2em;
text-decoration: none;
color: white;
background-color: rgba(0, 0, 0, 0.3);
font-size: 12px;
padding: 1em;
display: none;
}
 
.go-top:hover {
background-color: rgba(0, 0, 0, 0.6);
}
</style>
</head>
<body>
 
<div class="container">
<hgroup>
<h1>快速回到顶部按钮</h1>
</hgroup>
 
<hr />
 
<section>
 
<p>
这个从哪说呢:从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说,从前有座山,山上有座庙,庙里有个老和尚对小和尚说
            </p>
 
</section>
 
<footer>
<hr />
 
<p>Just some basic footer text.</p>
 
<a href="#" class="go-top">Go Top</a>
</footer>
</div> <!-- end container -->
 
<!-- JavaScript -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
// Show or hide the sticky footer button
$(window).scroll(function() {
if ($(this).scrollTop() > 200) {
$('.go-top').fadeIn(200);
} else {
$('.go-top').fadeOut(200);
}
});
 
// Animate the scroll to top
$('.go-top').click(function(event) {
event.preventDefault();
 
$('html, body').animate({scrollTop: 0}, 300);
})
});
</script>
</body>
</html>

posted on 2013-12-06 09:51  小刈  阅读(250)  评论(0编辑  收藏  举报

导航