惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Blog — PlanetScale
Blog — PlanetScale
博客园 - Franky
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
D
Docker
Google DeepMind News
Google DeepMind News
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
N
Netflix TechBlog - Medium
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Engineering at Meta
Engineering at Meta
H
Help Net Security
B
Blog
宝玉的分享
宝玉的分享

博客园 - CB

用HTML5 Canvas为网页添加动态波浪背景 SVG 动画实现弹性的页面元素效果 Trianglify – 五彩缤纷的 SVG 背景图案 『转』Photoshop中改进ios设计流程的30个诀窍 【转】6 个强大的 HTML5 应用在线开发工具 【转】2012年度最新免费web开发设计资源荟萃 【转】inline-blcok 前世今生 【转】60款很酷的 jQuery 幻灯片演示和下载 【转载】用CSS3做的动画按钮 【转载】时尚的CSS3进度条 【转】[jQuery插件]图片居中裁切效果 漂亮的表格 6款强大的jQuery插件 创建和加强网站布局 RMB符号的几种显示方式。 [转载] 模仿淘宝列表页面的工具栏随屏幕滚动效果 2010年最佳jQuery插件 网站开发人员应该知道的62件事 - CB - 博客园 21个精彩的Jquery效果插件 编写跨浏览器兼容的 CSS 代码的金科玉律
转载“精简版”滚动到顶部和底部的jQuery效果
CB · 2010-10-19 · via 博客园 - CB

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

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

代码

$(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);//按下"向上"按钮,将页面滚动到页面顶部
                    }
                );
            });

代码

.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>之前。

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