需要调用Jquery文件哦
JS代码如下:
jQuery(document).ready(function ($) {
$('.rtTop h4 img').hover(function () {
$(this).stop().animate({ "top": "-43px" }, 200)
}, function () {
$(this).stop().animate({ "top": "0" }, 200)
})
$(window).scroll(function () {
var st = $(document).scrollTop();
if (st > 200) {
$('.rtTop').show();
} else {
$('.rtTop').hide();
}
})
$('.rtTop h4').click(function () {
$('html,body').animate({ 'scrollTop': 0 }, 500);
});
//回到顶部函数
});
HTML代码如下:
<div class="rtTop">
<h4> <img src="images/backBg.png" width="43" height="86" alt="返回顶部"
title="返回顶部" /></h4>
</div>