转载“精简版”滚动到顶部和底部的jQuery效果

原文链接地址:“精简版”滚动到顶部和底部的jQuery效果

 

滚动到顶部和底部的jQuery效果也是一个在blog中很常见的jQuery效果。
之前一直用的是西门《缓冲版”返回顶部”》,当然现在还在继续用,觉得蛮好的,昨天看了一些jQuery的资料,浏览了一些国外jQuery代码网站,于是自己修改了一个”精简版”滚动到顶部和底部的jQuery(折腾玩玩..)。

ExpandedBlockStart.gif 代码
$( function () {
                
var  $elem  =  $( ' #content ' ); // 此页面元素里滚动
 
                $(
' #nav_up ' ).fadeIn( ' slow ' );
                $(
' #nav_down ' ).fadeIn( ' slow ' ); // 显示按钮
 
                $(
' #nav_down ' ).click(
                    
function  (e) {
                        $(
' html, body ' ).animate({scrollTop: $elem.height()},  800 ); // 按下""按钮,将页面滚动到页面底部(所示高度)
                    }
                );
                $(
' #nav_up ' ).click(
                    
function  (e) {
                        $(
' html, body ' ).animate({scrollTop:  ' 0px ' },  800 ); // 按下"向上"按钮,将页面滚动到页面顶部
                    }
                );
            });

 

ExpandedBlockStart.gif 代码
.nav_up {
    padding
: 7px ;
    background-color
: white ;
    border
: 1px solid #CCC ;
    position
: fixed ;
    background
: transparent url(../images/arrow_up.png) no-repeat top left ;
    background-position
: 50% 50% ;
    width
: 8px ;
    height
: 20px ;
    bottom
: 10px ;
    opacity
: 0.7 ;
    left
: 4px ;
    white-space
: nowrap ;
    cursor
:  pointer ;
    -moz-border-radius
:  3px 3px 3px 3px ;
    -webkit-border-top-left-radius
: 3px ;
    -webkit-border-top-right-radius
: 3px ;
    -khtml-border-top-left-radius
: 3px ;
    -khtml-border-top-right-radius
: 3px ;
    filter
: progid:DXImageTransform.Microsoft.Alpha(opacity=70) ;
}
.nav_down
{
    padding
: 7px ;
    background-color
: white ;
    border
: 1px solid #CCC ;
    position
: fixed ;
    background
: transparent url(../images/arrow_down.png) no-repeat top left ;
    background-position
: 50% 50% ;
    width
: 8px ;
    height
: 20px ;
    bottom
: 10px ;
    opacity
: 0.7 ;
    left
: 25px ;
    white-space
: nowrap ;
    cursor
:  pointer ;
    -moz-border-radius
:  3px 3px 3px 3px ;
    -webkit-border-top-left-radius
: 3px ;
    -webkit-border-top-right-radius
: 3px ;
    -khtml-border-top-left-radius
: 3px ;
    -khtml-border-top-right-radius
: 3px ;
    filter
: progid:DXImageTransform.Microsoft.Alpha(opacity=70) ;
}

 

 

 

最后再在footer.php里面加上:

<div style=”display:none;” id=”nav_up”></div>
<div style=”display:none;” id=”nav_down”></div>

加在</body>之前。

好了,就这样。效果如本站左下角:

 

转载于:https://www.cnblogs.com/CB/archive/2010/10/19/1855362.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值