jquery 平滑到页面顶端

<html>

<haed>

<title>隔行变色</title>

<style type='text/css'>

#container{

   height: 1000px;

   line-height: 1000px;

   text-align: center;

   font-family: Arial;

   border: 1px solid #EEEEEE;

}

 

.topLink{

  float:right;

  padding:10px;

  color: #CCC;

}

</style>

<script language='javascript' type='text/javascript' src='../jquery-1.9.1.min.js'></script>

     <script type='text/javascript' >

$(document).ready(function() {

 

$("a.topLink").click(function() {

 

$("html, body").animate({

 

scrollTop: $($(this).attr("href")).offset().top + "px"

}, {

duration: 500,

easing: "swing"

});

return false;

});

 

});

 

</script>

</head>

<body>

<h1 id="anchor">页面标题</h1>

<div id="container">页面内容</div>

<p><a href="#anchor" class="topLink">回到顶端</a></p>

 

</body>

</html>

你可能感兴趣的:(平滑,顶端)