做小项目遇到,以前做的一直没有兼容IE6,然后网上找了点资料,实现了IE6的兼容
代码如下
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
- <title></title>
- <script type="text/javascript" src="script/jquery-1.8.2.min.js"></script>
- <script type="text/javascript">
- //回到顶部
- //设置滚动条响应事件
- $(document).ready(function (){
- $(window).scroll(function () {
- //拿到滚动条滚动的距离
- var a = $(window).scrollTop();
- if (a > 0) {
- $("#to_top").css("display", "block");
- } else {
- $("#to_top").css("display", "none");
- }
- });
- $('#to_top').click(function () { $('html,body').animate({ scrollTop: '0px' }, 800); return false; });
- });
- </script>
- <style type="text/css">
- #content{
- height:3000px;
- }
- #to_top{
- width:46px;
- height:46px;
- font-size:30px;
- line-height:60px;
- text-align:center;
- position:fixed;
- _position:absolute;
- left:50%;
- color:#fff;
- margin-left:520px;
- bottom:140px;
- cursor:pointer;
- }
- #to_top a{
- color:#fff;
- width:80px;
- height:80px;
- display:inline-block;
- }
- </style>
- </head>
- <body>
- <div id="content">
- </div>
- <!--回到顶部-->
- <!--[if IE 6]>
- <style type="text/css">
- html{_text-overflow:ellipsis}
- #to_top{_position:absolute;_top:expression(eval(document.documentElement.scrollTop + 300))}
- </style>
- <![endif]-->
- <div id="to_top" style="display:none;">
- <a href="#go_top"><img src="p_w_picpaths/top.gif" alt="回到顶部" title="回到顶部" /></a>
- </div>
- </body>
- </html>
其中<!--[if IE 6]>
- <!--[if IE 6]>
- <style type="text/css">
- html{_text-overflow:ellipsis}
- #to_top{_position:absolute;_top:expression(eval(document.documentElement.scrollTop + 300))}
- </style>
- <![endif]-->
做的是IE6的兼容,返回顶部的时间都可以自己在js代码里设置。