生态65
首页 电脑知识 正文

通过W3C验证的返回顶部按扭代码

电脑知识 6.15k

上篇文章刚上传了网上流行的返回顶部隐现的按钮JS代码,一般是无法通过W3C认证的,对于追求完美的人来说,可能觉得很不爽,经过给证,删除一些不必要代码,修证后的代码如下:

<style type="text/css">
                #w2b-StoTop {-moz-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px; width:10px;
                background-color: #EEEEEE;background-color: rgba(238, 238, 238, 0.6);
                text-align:center;padding:5px;position:fixed;bottom:10px;right:10px;cursor:pointer;color:#444000;text-decoration:none;border:1px solid #000000;}
            </style>
               
            <script type="text/javascript" src="http://ihb65.com/content/templates/DaZengCMS/js/jquery.min.js"></script>
            <script type='text/javascript'>
                    $(function() {
                        $.fn.scrollToTop = function() {
                            $(this).hide().removeAttr("href");
                            if ($(window).scrollTop() != "0") {
                                $(this).fadeIn("slow")
                            }
                            var scrollDiv = $(this);
                            $(window).scroll(function() {
                                if ($(window).scrollTop() == "0") {
                                    $(scrollDiv).fadeOut("slow")
                                } else {
                                    $(scrollDiv).fadeIn("slow")
                                }
                            });
                            $(this).click(function() {
                                $("html, body").animate({
                                    scrollTop: 0
                                }, "slow")
                            })
                        }
                    });
                    $(function() {
                        $("#w2b-StoTop").scrollToTop();
                    });
            </script>
            <a href='#' id='w2b-StoTop' style='display:none;'>
                返回顶部
            </a>

主要是删除其中不兼容的部分,实际上效果一样,测试FOX、IE9等!

上一篇 青春散场,谁知道幸福的摸样:夜未殇
下一篇 直接调用GOOGLE的JS码返回顶部的代码

发表评论

还没有评论