HTML 和 CSS 样式设置好了之后,最后就是添加 JavaScript 事件响应代码了,这里是基于 jQuery 实现的。代码如下:(这段代码还是放在source/_include/custom/footer.html文件中)
123456789101112131415161718192021222324252627
<scripttype="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script><scripttype="text/javascript">$(document).ready(function(){// hide #back-top first$("#back-top").hide();// fade in #back-top$(function(){$(window).scroll(function(){if($(this).scrollTop()>100){$('#back-top').fadeIn();}else{$('#back-top').fadeOut();}});// scroll body to 0px on click$('#back-top a').click(function(){$('body,html').animate({scrollTop:0},800);returnfalse;});});});</script>