读书人

jquery 平滑到页面上端

发布时间: 2013-09-28 10:01:20 作者: rapoo

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>

读书人网 >编程

热点推荐