引用的样式如下(实现top图标永远处在右下角位置):
<style type="text/css">
#toTop {
bottom: 0;
cursor: pointer;
padding: 0 0 1em;
position: fixed;
right: 0;
width: 38px;
}
</style>
js如下:
<script type="text/javascript" src="js/jquery-1.4.2.js"></script> //引用jquery数据库
<img id="toTop" src="images/scroll_to_top.gif" width="38" height="68" alt="Scroll to Top" title="Scroll to Top" />
<script type="text/javascript">
$(document).ready(function() {
var ScrolltoTop = $("#toTop");
$(ScrolltoTop).hide();
$(window).scroll(function() {
if ($(window).scrollTop() == "0") {
$(ScrolltoTop).fadeOut("slow")
} else {
$(ScrolltoTop).fadeIn("slow")
}
});
$(ScrolltoTop).click(function() {
$('html, body').animate({
scrollTop: 0
},
700)
})
});
</script>
(命名为scrol