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


    原文链接地址:“精简版”滚动到顶部和底部的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>之前。

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

     

  • 相关阅读:
    Linux 配置 SSL 证书
    freemarker 异常处理
    StringTemplateLoader的用法
    序列的重点知识小结
    Linux下安装lrzsz上传下载工具
    ajax技术
    Response对象介绍(服务器到客户端)
    Request对象介绍(客户端到服务器)
    JSP--内置对象&动作标签介绍
    JSP--常用指令
  • 原文地址:https://www.cnblogs.com/CB/p/1855362.html
Copyright © 2020-2023  润新知