jquery实现返回顶部按钮和scroll滚动功能[带动画效果] 转载

jQuery脚本:

<script type="text/javascript">
        $(function() {
            var scrollDiv = document.createElement('div');
            $(scrollDiv).attr('id', 'toTop').html('^ 返回顶部').appendTo('body');
            $(window).scroll(function() {
                if ($(this).scrollTop() != 0) {
                    $('#toTop').fadeIn();
                } else {
                    $('#toTop').fadeOut();
                }
            });
            $('#toTop').click(function() {
                $('body,html').animate({ scrollTop: 0 }, 800);
            })
        });
    </script>

CSS样式:

<style type="text/css">
        #toTop
{
            width: 100px;
            z-index: 10;
            border: 1px solid #333;
            background: #121212;
            text-align: center;
            padding: 5px;
            position: fixed;
            bottom: 0px;
            right: 0px;
            cursor: pointer;
            display: none;
            color: #fff;
            text-transform: lowercase;
            font-size: 0.9em;
}
    </style>

带有iframe框架的滚动操作:

<script type="text/javascript">
<!--
        $().ready(function() {
            $('<div id="return_old_tips" class="btn_return_old" style="position:' + ($.browser.msie ? "absolute" : "fixed") + ';" οnclick="return_old({$feedback_flag},\'{$current_url}\')">返回旧版</div>').appendTo($("body"));
            if ($.browser.msie) {
                $("#return_old_tips").css("top", 200);
            }
            if ($.browser.msie) {
                top.document.body.onscroll = function() {
                    var f = 200 + (top.document.documentElement.scrollTop || top.document.body.scrollTop);
                    if (f > parseInt($("body").height(), 10)) {
                        f = parseInt($("body").height(), 10);
                    }
                    $("#return_old_tips").css({
                        top: f,
                        left: 0
                    });
                }
                top.document.body.onresize = top.document.body.onscroll;
            } else {
                $(window.parent.document).scroll(function() {
                    var f = 200 + (top.document.documentElement.scrollTop || top.document.body.scrollTop);
                    if (f > parseInt($("body").height(), 10)) {
                        f = parseInt($("body").height(), 10);
                    }
                    $("#return_old_tips").css({
                        top: f,
                        left: 0
                    });
                }).resize(function() {
                    var f = 200 + (top.document.documentElement.scrollTop || top.document.body.scrollTop);
                    if (f > parseInt($("body").height(), 10)) {
                        f = parseInt($("body").height(), 10);
                    }
                    $("#return_old_tips").css({
                        top: f,
                        left: 0
                    });
                });
            }
        });

//-->
    </script>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值