user-pic

“回到顶部”模块的设计

Vote 0 Votes

我对“回到顶部”这一模块进行了两部分设计:

一、将“回到顶部”固定在下拉框中间;
方法
在模版顶部添加<div id="top"></div>给予定位,然后在模版中增加下列源码(在IE6下无法显示,所以我还在页面底部加了个“回到顶部”)

<div align="center"><a id="toTop" href="#top" title="回到顶部" class="internal" rel="nofollow"><span>&uarr;</span></a></div> 

在css 中添加
#toTop {
width:26px;
height:26px;
display:block;
position:fixed;
bottom:50%;
right:5px;
background:url(<$MTBlogURL$>styles/milk/pager_home.gif) no-repeat 0 0;
outline:0 none;
}
#toTop span {
display:none;
}

二、在回到顶部过程中使用逐步上升的JS。
在<head></head>中添加下列JS
<script type="text/javascript">
toTop = {
init:function(){
document.getElementById("toTop").onclick=function(e){
toTop.set();
return false;

},
waitTimer:null,
set:function(){
var d_st=document.documentElement.scrollTop;
if(window.navigator.userAgent.indexOf("MSIE")>=1){
for (var i=d_st; i>10; i-=Math.floor(i/6)){
window.scrollTo(0,i);
}
window.scrollTo(0,10);
}
else{
window.scrollTo(0,Math.floor(d_st / 2));

 if(d_st>10){
 waitTimer=setTimeout("toTop.set()",40);
  }
else{
  clearTimeout(waitTimer);
}
}
}
}
window.onload = function(){toTop.init();}
</script>

Add a Reply

Forum Groups

Blogcs 基于MT平台的BSP

MovableType 中文化

MovableType 使用

16 13

Last Topic: Image::Magick 模块的安装 by bb on 9, 2008

22 1

Last Topic: 修改MT的作者归档路径 by bb on 25, 2008

1 0

Last Topic: 漂亮的Movable Type模板 by Aviva on 11, 2009

MovableType 延伸

3 4

Last Topic: dreamhost完美支持MT by kesor on 24, 2008