├── ie-bug ├── images │ ├── b.gif │ ├── test.jpg │ └── alphabg.png ├── demo │ ├── demo2.html │ ├── demo.html │ ├── 1.html │ ├── 4.html │ ├── 34.html │ ├── 5.html │ ├── 11.html │ ├── 15.html │ ├── 3.html │ ├── 22.html │ ├── 14.html │ ├── 26.html │ ├── 19.html │ ├── 19-2.html │ ├── 20.html │ ├── 28.html │ ├── 2.html │ ├── 21.html │ ├── 30.html │ ├── 23.html │ ├── 9.html │ ├── 25.html │ ├── 12.html │ ├── 29.html │ ├── 27.html │ ├── 33.html │ ├── 32.html │ ├── 18.html │ ├── 13.html │ ├── 17.html │ ├── 7.html │ ├── 6.html │ ├── 10.html │ ├── 16.html │ ├── 8.html │ ├── 31.html │ └── 24.html ├── css │ └── demo.css └── index.html ├── README.md ├── code ├── ECMAScript6.js ├── dataFormat.js ├── Common.js ├── EventUtil.js ├── DOMUtil.js ├── ECMAScript5.js └── Tool.js └── LICENSE /ie-bug/images/b.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumuy/tools-library/HEAD/ie-bug/images/b.gif -------------------------------------------------------------------------------- /ie-bug/images/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumuy/tools-library/HEAD/ie-bug/images/test.jpg -------------------------------------------------------------------------------- /ie-bug/images/alphabg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumuy/tools-library/HEAD/ie-bug/images/alphabg.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 文件说明(code目录) 2 | 3 | * ajax.js 原生ajax解决方案(类似于jquery) 4 | * DOMUtil.js DOM操作兼容性解决方案 5 | * EventUtil.js 浏览器事件兼容性解决方案 6 | * ECMAScript5.js 让低版本浏览器支持ECMAScript的解决方案(整理自MDN Polyfill) 7 | * Common.js 建站通用方法 8 | * Tool.js 常用工具方法 9 | 10 | ## 浏览器bug汇总 11 | [IE8-](http://passer-by.com/tools-library/ie-bug/) 12 | -------------------------------------------------------------------------------- /ie-bug/demo/demo2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Demo 5 | 6 | 11 | 12 | 13 |
14 |
15 | 返回列表>> 16 |

问题

17 |

浏览器:内容

18 |

描述:内容

19 |
20 |
21 |
22 |

修复前:

23 |
24 |
25 |
26 | 27 |
28 |

应用场景:内容

29 |
30 |
31 |
32 | 33 |
34 |

应用场景:内容

35 |
36 |
37 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /code/ECMAScript6.js: -------------------------------------------------------------------------------- 1 | /* 2 | ECMAScript6 Polyfill 3 | */ 4 | 5 | if (typeof Object.assign != 'function') { 6 | Object.assign = function(target) { 7 | 'use strict'; 8 | if (target == null) { 9 | throw new TypeError('Cannot convert undefined or null to object'); 10 | } 11 | target = Object(target); 12 | for (var index = 1; index < arguments.length; index++) { 13 | var source = arguments[index]; 14 | if (source != null) { 15 | for (var key in source) { 16 | if (Object.prototype.hasOwnProperty.call(source, key)) { 17 | target[key] = source[key]; 18 | } 19 | } 20 | } 21 | } 22 | return target; 23 | }; 24 | } 25 | if (!Object.is) { 26 | Object.is = function(x, y) { 27 | // SameValue algorithm 28 | if (x === y) { // Steps 1-5, 7-10 29 | // Steps 6.b-6.e: +0 != -0 30 | return x !== 0 || 1 / x === 1 / y; 31 | } else { 32 | // Step 6.a: NaN == NaN 33 | return x !== x && y !== y; 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /ie-bug/demo/demo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Demo 6 | 7 | 12 | 13 | 14 |
15 |
16 | 返回列表>> 17 |

问题

18 |

浏览器:内容

19 |

描述:内容

20 |
21 |
22 |
23 |

修复前:

24 |
25 |
26 |
27 | 28 |
29 |
30 |
31 |
32 |
33 |

修复后:

34 |
35 |
36 |
37 | 38 |
39 |

解决方案:内容

40 |
41 |
42 |
43 | 44 | 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Haole Zheng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /ie-bug/demo/1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 水平居中 5 | 6 | 11 | 12 | 13 |
14 |
15 | 返回列表>> 16 |

水平居中

17 |

浏览器:IE6~8

18 |

描述:使用margin:0 auto;无法居中块元素

19 |
20 |
21 |
22 |

修复前:

23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |

修复后:

33 |
34 |
35 |
36 |
37 |
38 |

解决方案:对其父容器添加text-align:center;(或增加DTD声明)

39 |
40 |
41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /ie-bug/demo/4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 外边距叠加 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

外边距叠加

19 |

浏览器:*

20 |

描述:外边距叠加的算法

21 |
22 |
23 |
24 |
25 |
26 |

本段落margin值为20px

27 |
28 |
29 |

应用场景:如果元素没有垂直边框或内边框,它的高度就是它包含子元素的顶部和底部边框边缘之间的距离

30 |
31 |
32 |
33 |
34 |

本段落margin值为20px,padding值为1px

35 |
36 |
37 |

应用场景:如果元素添加一个垂直边框或内边距,它的高度就是它包含的子元素的顶部和底部外边距边缘之间的距离

38 |
39 |
40 |
41 | 42 | 43 | -------------------------------------------------------------------------------- /ie-bug/demo/34.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Demo 6 | 7 | 12 | 13 | 14 |
15 |
16 | 返回列表>> 17 |

右浮动元素换行

18 |

浏览器:IE6

19 |

描述:当一个容器内有文本(或一般文档流布局的元素)和向右浮动元素,浮动元素另起一行浮动

20 |
21 |
22 |
23 |

修复前:

24 |
25 |
26 |
27 | 这是一段文字 28 |
29 |
30 |
31 |
32 |
33 |
34 |

修复后:

35 |
36 |
37 |
38 |
39 | 这是一段文字 40 |
41 |

解决方案:交换文本与浮动元素的位置

42 |
43 |
44 |
45 | 46 | 47 | -------------------------------------------------------------------------------- /ie-bug/demo/5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 内联元素margin 5 | 6 | 11 | 12 | 13 |
14 |
15 | 返回列表>> 16 |

内联元素margin

17 |

浏览器:IE6

18 |

描述:IE中内联元素撑开容器

19 |
20 |
21 |
22 |
23 |
24 | span 0 25 |
26 | span 1 27 |
28 |
29 |

应用场景:未设置高度

30 |
31 |
32 |
33 |
34 | span 0 35 |
36 | span 1 37 |
38 |
39 |

应用场景:IE6中为行元素设置高度,上下行margin有效且不被压缩(无DTD声明时)

40 |
41 |
42 |
43 | 44 | 45 | -------------------------------------------------------------------------------- /ie-bug/demo/11.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 无法设置微型高度 6 | 7 | 12 | 13 | 14 |
15 |
16 | 返回列表>> 17 |

无法设置微型高度

18 |

浏览器:IE6

19 |

描述:IE6及更早浏览器默认高度为19px行高,高度无法设置为小于19px的值

20 |
21 |
22 |
23 |

修复前:

24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |

修复后:

34 |
35 |
36 |
37 |
38 |
39 |

解决方案:对该元素添加:line-height:0; font-size:0;

40 |
41 |
42 |
43 | 44 | 45 | -------------------------------------------------------------------------------- /ie-bug/css/demo.css: -------------------------------------------------------------------------------- 1 | /*** demo文档样式 ***/ 2 | *{margin:0; padding:0;} 3 | a{text-decoration:none;} 4 | img{border:none;} 5 | body{font-family:Microsoft Yahei,Arial,Verdana;font-size:12px;color:#666;text-align:center;line-height:150%;} 6 | .container{width:900px; margin:15px auto; padding:0 15px; text-align:left;} 7 | .container p{color:#777;} 8 | .container span{font-weight:bold; margin-right:5px;} 9 | .container .decs{margin-bottom:10px;} 10 | .container .decs h3{color:#3d7489; font-size:1.3em;} 11 | .container .decs a{float:right; text-decoration:none; color:#275973;} 12 | .container .panel{margin-bottom:10px;} 13 | .container .panel .panel-head{height:30px;} 14 | .container .panel .panel-head h3{color:#777; font-size:18px; line-height:24px;} 15 | .container .panel .panel-body{margin-bottom:10px;} 16 | /*** demo测试样式 ***/ 17 | /* 通用 */ 18 | ul.test{list-style: none;} 19 | ul.test li a{background:#d5d5d5;} 20 | ul.test li a:hover{background:#bbb;} 21 | /* 外层-父容器 */ 22 | .outer{min-height:210px; _height:210px; border:1px dashed #ccc;} 23 | /* 内层-子元素 */ 24 | .box{border:1px solid #3a7ea2;} 25 | .block{background-color:#d5d5d5;} 26 | .block1{background-color:#f00; color:#fff;} 27 | .block2{background-color:#0f0; color:#fff;} 28 | .block p{background-color:#6699ff; color:#fff;} -------------------------------------------------------------------------------- /ie-bug/demo/15.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | overflow失效 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

overflow失效

19 |

浏览器:IE7

20 |

描述:IE7及更早浏览器下子元素相对定位时父元素overflow属性的auto|hidden失效

21 |
22 |
23 |
24 |

修复前:

25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |

修复后:

35 |
36 |
37 |
38 |
39 |
40 |

解决方案:给外层也设置相对定位position:relative

41 |
42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /ie-bug/demo/3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 绝对定位奇数宽高1px间距bug 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

绝对定位奇数宽高1px间距bug

19 |

浏览器:IE6

20 |

描述:当绝对定位元素的父元素高或宽为奇数时,bottom和right会多出1px

21 |
22 |
23 |
24 |

修复前:

25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |

修复后:

35 |
36 |
37 |
38 |
39 |
40 |

解决方案:hack暴力破解_bottom:-1px;

41 |
42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /ie-bug/demo/22.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | background-color失效 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

background-color失效

19 |

浏览器:IE7

20 |

描述::hover 时若background-color为#fff, 失效

21 |
22 |
23 |
24 |

修复前:

25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |

修复后:

35 |
36 |
37 |
38 |
39 |
40 |

解决方案:把background-color改成background。或者,非#fff || #ffffff

41 |
42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /ie-bug/demo/14.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | !important规则失效 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

!important规则

19 |

浏览器:IE6、IE8

20 |

描述:在一些情况下浏览器忽略!important规则

21 |
22 |
23 |
24 |

修复前:

25 |
26 |
27 |
28 |

这是一段测试文字。这是一段测试文字。这是一段测试文字。这是一段测试文字。这是一段测试文字。

29 |
30 |

应用场景:IE8会忽略伪对象:first-letter/:first-line里的!important规则,本例中首字母应为绿色

31 |
32 |
33 |
34 |

这是一段测试文字。这是一段测试文字。这是一段测试文字。这是一段测试文字。这是一段测试文字。

35 |
36 |

应用场景:IE6会忽略同一条样式体内的!important规则,本例中文字应为绿色

37 |
38 |
39 |
40 | 41 | 42 | -------------------------------------------------------------------------------- /ie-bug/demo/26.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 图片与文本垂直对齐居中 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

图片与文本垂直对齐居中

19 |

浏览器:IE6

20 |

描述:当图片与文本在一起,且图片由链接包含,设置行高无法水平居中

21 |
22 |
23 |
24 |

修复前:

25 |
26 |
27 |
28 |
这是一段文字
29 |
30 |
31 |
32 |
33 |
34 |

修复后:

35 |
36 |
37 |
38 |
这是一段文字
39 |
40 |

解决方案:设置img的margin值,margin-top为(外容器高度-图片高度)/2

41 |
42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /ie-bug/demo/19.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 盒模型 5 | 6 | 12 | 13 | 14 |
15 |
16 | 返回列表>> 17 |

盒模型

18 |

浏览器:IE6

19 |

描述:所有块width:50px;height:50px;当没有DTD声明时,所有IE版本也会进入Quirks Mode。width近似于按25px解析

20 |
21 |
22 |
23 |

没有DOCTYPE时

24 |
25 |
26 |
27 |
box1
28 |
box2
29 |
30 |

应用场景:box2{padding:50px;}

31 |
32 |
33 |
34 |
box1
35 |
box2
36 |
37 |

应用场景:box2{padding-left:50px;}

38 |
39 |
40 |
41 | 42 | 43 | -------------------------------------------------------------------------------- /ie-bug/demo/19-2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 盒模型 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

盒模型

19 |

浏览器:IE6

20 |

描述:所有块width:50px;height:50px;当没有DTD声明时,所有IE版本也会进入Quirks Mode。width近似于按25px解析

21 |
22 |
23 |
24 |

有DOCTYPE时

25 |
26 |
27 |
28 |
box1
29 |
box2
30 |
31 |

应用场景:box2{padding:50px;}

32 |
33 |
34 |
35 |
box1
36 |
box2
37 |
38 |

应用场景:box2{padding-left:50px;}

39 |
40 |
41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /ie-bug/demo/20.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IE透明滤镜 6 | 7 | 11 | 12 | 13 |
14 |
15 | 返回列表>> 16 |

IE透明滤镜

17 |

浏览器:IE

18 |

描述:兼容各版本IE的滤镜

19 |
20 |
21 |
22 | 28 |

IE透明滤镜 29 |

30 | filter:alpha(opacity=40);
31 | filter: progid: DXImageTransform.Microsoft.Alpha( opacity=40 ); /* IE6, IE7, and IE8 */
32 | -ms-filter : progid:DXImageTransform.Microsoft.Alpha( opacity=40 ); /* IE8 only */
33 | 						
34 |

35 |
36 |
37 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /ie-bug/demo/28.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 距出边界的Bug 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

距出边界的Bug

19 |

浏览器:IE6/7

20 |

描述:元素设置了 overflow: auto;子元素设置 position:relative;并且其高度大于父元素,在IE6和IE7中会产生一个比较难看的 Bug,也就是子元素块不被隐藏会溢出父元素块

21 |
22 |
23 |
24 |

修复前:

25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |

修复后:

37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |

解决方案:父元素中也设置一个position:relative;

45 |
46 |
47 |
48 | 49 | 50 | -------------------------------------------------------------------------------- /ie-bug/demo/2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 双外边距浮动bug 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

双外边距浮动bug

19 |

浏览器:IE6

20 |

描述:使用float浮动容器,如果浮动容器具有margin值,则呈现margin-left值双倍情况。

21 |
22 |
23 |
24 |

修复前:

25 |
26 |
27 |
28 |
margin:25px;
29 |
30 |
31 |
32 |
33 |
34 |

修复后:

35 |
36 |
37 |
38 |
margin:25px;
39 |
40 |

解决方案:在浮动元素上加上position: absolute;

41 |
42 |
43 |
44 |
margin:25px;
45 |
46 |

解决方案:在浮动元素上加上display:inline;

47 |
48 |
49 |
50 | 51 | 52 | -------------------------------------------------------------------------------- /ie-bug/demo/21.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 不支持png透明图片 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

不支持png透明图片

19 |

浏览器:IE6

20 |

描述:IE6中不支持png24的透明效果

21 |
22 |
23 |
24 |

修复前:

25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |

修复后:

35 |
36 |
37 |
38 |
39 |
40 |

解决方案:增加IE滤镜,filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=noscale, src="绝对路径");

41 |
42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /ie-bug/demo/30.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | li背景失效 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

li背景失效

19 |

浏览器:IE6

20 |

描述:当li中有浮动元素时,且li的display为inline;

21 |
22 |
23 |
24 |

修复前:

25 |
26 |
27 |
28 |
    29 |
  • 文字
  • 30 |
  • 文字
  • 31 |
  • 文字
  • 32 |
33 |
34 |

解决方案:li中添加display:inline; width:100%;

35 |
36 |
37 |
38 |
39 |

修复后:

40 |
41 |
42 |
43 |
    44 |
  • 文字
  • 45 |
  • 文字
  • 46 |
  • 文字
  • 47 |
48 |
49 |

解决方案:触发layout,zoom:1;

50 |
51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /ie-bug/demo/23.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 图片垂直居中 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

图片垂直居中

19 |

浏览器:IE6

20 |

描述:图片无法通过display:table-cell; vertical-align:middle;设置垂直居中

21 |
22 |
23 |
24 |

修复前:

25 |
26 |
27 |
28 |
pic
29 |
30 |
31 |
32 |
33 |
34 |

修复后:

35 |
36 |
37 |
38 |
pic
39 |
40 |

解决方案: 41 |

42 | *display: block;
43 | *font-size: 175px;/*约为高度的0.873,200*0.873 约为175*/
44 | *font-family:Arial;/*防止非utf-8引起的hack失效问题,如gbk编码*/
45 | 						
46 |

47 |
48 |
49 |
50 | 51 | 52 | -------------------------------------------------------------------------------- /ie-bug/demo/9.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 浮动元素3px间隔Bug 6 | 7 | 14 | 15 | 16 |
17 |
18 | 返回列表>> 19 |

浮动元素3px间隔Bug

20 |

浏览器:IE6

21 |

描述:发生在一个元素浮动,然后一个不浮动的元素自然上浮与之靠近会出现的3px的bug(在其他浏览器中重叠)

22 |
23 |
24 |
25 |

修复前:

26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |

修复后:

37 |
38 |
39 |
40 |
41 |
42 |
43 |

解决方案:为右边的元素添加float:left;

44 |
45 |
46 |
47 |
48 |
49 |
50 |

解决方案:使用hack暴力破解margin-left:-3px;

51 |
52 |
53 |
54 | 55 | 56 | -------------------------------------------------------------------------------- /ie-bug/demo/25.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 滤镜致链接失效BUG 6 | 7 | 12 | 13 | 14 |
15 |
16 | 返回列表>> 17 |

滤镜致链接失效BUG

18 |

浏览器:IE6

19 |

描述:IE6下使用DXImageTransform.Microsoft.AlphaImageLoader滤镜(用于PNG32 Alpha透明)后链接不能点击

20 |
21 |
22 |
23 |

修复前:

24 |
25 |
26 |
27 | 30 |
31 |
32 |
33 |
34 |
35 |

修复后:

36 |
37 |
38 |
39 |
40 |

这个链接能点

41 |
42 |
43 |

解决方案:a标签上加相对定位的属性(position:relative)

44 |
45 |
46 |
47 | 48 | 49 | -------------------------------------------------------------------------------- /code/dataFormat.js: -------------------------------------------------------------------------------- 1 | // 数据格式转换 2 | const dataFormat = { 3 | ArrayBufferToBlob(){ 4 | return new Blob([new Uint8Array(buffer, byteOffset, length)]); 5 | }, 6 | ArrayBufferToBase64(){ 7 | return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer))); 8 | }, 9 | Base64ToBlob(base64Data, contentType, sliceSize){ 10 | const byteCharacters = atob(base64Data); 11 | const byteArrays = []; 12 | for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) { 13 | const slice = byteCharacters.slice(offset, offset + sliceSize); 14 | const byteNumbers = new Array(slice.length); 15 | for (let i = 0; i < slice.length; i++) { 16 | byteNumbers[i] = slice.charCodeAt(i); 17 | } 18 | const byteArray = new Uint8Array(byteNumbers); 19 | byteArrays.push(byteArray); 20 | } 21 | const blob = new Blob(byteArrays, {type: contentType}); 22 | return blob; 23 | }, 24 | BlobToArrayBuffer(blob){ 25 | return new Promise((resolve, reject) => { 26 | const reader = new FileReader(); 27 | reader.onload = () => resolve(reader.result); 28 | reader.onerror = () => reject; 29 | reader.readAsArrayBuffer(blob); 30 | }); 31 | }, 32 | BlobToBase64(blob) { 33 | return new Promise((resolve) => { 34 | const reader = new FileReader(); 35 | reader.onloadend = () => resolve(reader.result); 36 | reader.readAsDataURL(blob); 37 | }); 38 | }, 39 | BlobToObjectURL(blob){ 40 | return URL.createObjectURL(blob); 41 | } 42 | }; -------------------------------------------------------------------------------- /ie-bug/demo/12.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 按钮留白随value增加 6 | 7 | 12 | 13 | 14 |
15 |
16 | 返回列表>> 17 |

按钮留白随value增加

18 |

浏览器:IE6

19 |

描述:button、input两边留白随value长度的增加而增加

20 |
21 |
22 |
23 |

修复前:

24 |
25 |
26 |
27 |

28 |

29 |

30 |

31 |

32 |

33 |
34 |
35 |
36 |
37 |
38 |

修复后:

39 |
40 |
41 |
42 |

43 |

44 |

45 |

46 |

47 |

48 |
49 |

解决方案:为input或button添加overflow:visible;

50 |
51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /ie-bug/demo/29.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 浮动层错位 5 | 6 | 12 | 13 | 14 |
15 |
16 | 返回列表>> 17 |

浮动层错位

18 |

浏览器:IE6

19 |

描述:当内容超出外包容器定义的宽度时会导致浮动层错位问题。在 Firefox、IE7、IE8 及其他标准浏览 器里,超出的内容仅仅只是超出边缘;但在 IE6 中容器会忽 视定义的 width 值,宽度会错误地随内 容宽度增长而增长。如果在这个浮动元素之后还跟着一个 浮动元素,那么就会导致错位问题

20 |
21 |
22 |
23 |

修复前:

24 |
25 |
26 |
27 |
28 |
http://net.tutsplus.com/
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |

修复后:

37 |
38 |
39 |
40 |
41 |
http://net.tutsplus.com/
42 |
43 |
44 |
45 |

解决方案:overflow:hidden;

46 |
47 |
48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /ie-bug/demo/27.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | display:none引起的3像素的BUG 6 | 7 | 17 | 18 | 19 |
20 |
21 | 返回列表>> 22 |

display:none引起的3像素的BUG

23 |

浏览器:IE6

24 |

描述:一些浮动元素中有一个display:none;的元素,会引起3px的误差

25 |
26 |
27 |
28 |

修复前:

29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |

修复后:

44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |

解决方案:将最后一个div加一个margin-right:-3px

55 |
56 |
57 |
58 | 59 | 60 | -------------------------------------------------------------------------------- /ie-bug/demo/33.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Demo 6 | 7 | 15 | 16 | 17 |
18 |
19 | 返回列表>> 20 |

无法取消input默认边框

21 |

浏览器:IE6

22 |

描述:无法使用border:nonoe;取消input默认边框

23 |
24 |
25 |
26 |

修复前:

27 |
28 |
29 |
30 | 不带边框的input 31 |
32 |
33 |
34 |
35 |
36 |

修复后:

37 |
38 |
39 |
40 | 不带边框的input 41 |
42 |

解决方案:border:medium none;

43 |
44 |
45 |
46 | 不带边框的input 47 |
48 |

解决方案:border:0;

49 |
50 |
51 |
52 | 不带边框的input 53 |
54 |

解决方案:设置background-color,如background-color:#fff;

55 |
56 |
57 |
58 | 59 | 60 | -------------------------------------------------------------------------------- /ie-bug/demo/32.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Demo 6 | 7 | 14 | 15 | 16 |
17 |
18 | 返回列表>> 19 |

margin-top失效

20 |

浏览器:IE6/7

21 |

描述:当某块级元素设置了margin-top,并且之前存在着可被渲染的绝对定位元素时,其margin-top在IE6、IE7会失效。

22 |
23 |
24 |
25 |

修复前:

26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |

修复后:

39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |

解决方案:将定位元素放在后面

48 |
49 |
50 |
51 |
52 |
53 | 54 |
55 |
56 |
57 |

解决方案:将定位元素放在后面

58 |
59 |
60 |
61 | 62 | 63 | -------------------------------------------------------------------------------- /ie-bug/demo/18.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | z-index层次错误 6 | 7 | 19 | 20 | 21 |
22 |
23 | 返回列表>> 24 |

z-index层次错误

25 |

浏览器:IE6

26 |

描述:IE6中的绝对定位元素,z-index只与父容器的z-index进行比较

27 |
28 |
29 |
30 |

修复前:

31 |
32 |
33 |
34 |
35 |
z-index:10
36 |
37 |
38 |
z-index:9
39 |
40 |
41 |
42 |
43 |
44 |
45 |

修复后:

46 |
47 |
48 |
49 |
50 |
z-index:10
51 |
52 |
53 |
z-index:9
54 |
55 |
56 |

解决方案:给其父级元素定义z-index,有些情况下还需要定义position:relative

57 |
58 |
59 |
60 | 61 | 62 | -------------------------------------------------------------------------------- /ie-bug/demo/13.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 文本溢出BUG 6 | 7 | 16 | 17 | 18 |
19 |
20 | 返回列表>> 21 |

文本溢出BUG(“谍影重重”、“一只猪的故事”)

22 |

浏览器:IE

23 |

描述:造成此BUG的原因可能是多重混合的,如浮动,注释,宽高定义等等。并且注释条数越多,溢出的文本也会随之增多。

24 |
25 |
26 |
27 |

修复前:

28 |
29 |
30 |
31 |
32 |
33 | 34 |
↓这就是多出来的那只猪
35 |
36 |
37 |
38 |
39 |
40 |
41 |

修复后:

42 |
43 |
44 |
45 |
46 |
47 |
↓这就是多出来的那只猪
48 |
49 |
50 |

解决方案:删除两浮动元素间所有的注释

51 |
52 |
53 |
54 |
55 |
56 |
↓这就是多出来的那只猪
57 |
58 |
59 |

解决方案:调整box1的宽度

60 |
61 |
62 |
63 | 64 | 65 | -------------------------------------------------------------------------------- /ie-bug/demo/17.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 列表阶梯bug 6 | 7 | 13 | 14 | 15 |
16 |
17 | 返回列表>> 18 |

列表阶梯bug

19 |

浏览器:IE6

20 |

描述:float列表元素不水平对齐:li不设置float,a设置display:block;float:[方向],li不水平对齐

21 |
22 |
23 |
24 |

修复前:

25 |
26 |
27 | 34 |
35 |
36 |
37 |
38 |

修复后:

39 |
40 |
41 | 48 |

解决方案:给li添加float:[方向]

49 |
50 |
51 | 58 |

解决方案:给li添加display:inline;

59 |
60 |
61 |
62 | 63 | 64 | -------------------------------------------------------------------------------- /ie-bug/demo/7.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 垂直列表间隔bug 6 | 7 | 14 | 15 | 16 |
17 |
18 | 返回列表>> 19 |

垂直列表间隔bug

20 |

浏览器:IE6

21 |

描述:当li中出现2个或以上的浮动时,li之间产生的空白间隙的BUG

22 |
23 |
24 |
25 |

修复前:

26 |
27 |
28 |
29 |
    30 |
  • 31 |
  • 32 |
  • 33 |
34 |
35 |
36 |
37 |
38 |
39 |

修复后:

40 |
41 |
42 |
43 |
    44 |
  • 45 |
  • 46 |
  • 47 |
48 |
49 |

解决方案:li元素一起漂浮,即float:left; width:100%;

50 |
51 |
52 |
53 |
    54 |
  • 55 |
  • 56 |
  • 57 |
58 |
59 |

解决方案:li元素中添加vertical-align:bottom;

60 |
61 |
62 |
63 | 64 | 65 | -------------------------------------------------------------------------------- /ie-bug/demo/6.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 清除内部浮动 6 | 7 | 14 | 15 | 16 |
17 |
18 | 返回列表>> 19 |

清除内部浮动

20 |

浏览器:*

21 |

描述:当子元素浮动且未知高度时,如何使父容器适应子元素的高度

22 |
23 |
24 |
25 |

修复前:

26 |
27 |
28 |
29 |
30 |
31 |

这里是一行文字

32 |
33 |
34 |
35 |
36 |
37 |
38 |

修复后:

39 |
40 |
41 |
42 |
43 |
44 |

这里是一行文字

45 |
46 |
47 |

解决方案:增加一个清除类(如clearfix)

48 |

.clearfix:after{display:block; content:"."; height:0; visibility:hidden; clear:both;}

49 |

.clearfix{*zoom:1;}

50 |
51 |
52 |
53 |
54 |
55 |

这里是一行文字

56 |
57 |
58 |

解决方案:在父容器中添加overflow:hidden;*zoom:1;

59 |
60 |
61 |
62 | 63 | 64 | -------------------------------------------------------------------------------- /ie-bug/demo/10.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 图片下方出现空白间隙 6 | 7 | 14 | 15 | 16 |
17 |
18 | 返回列表>> 19 |

图片下方出现空白间隙

20 |

浏览器:IE6

21 |

描述:当图片为其父容器的唯一子元素,且代码中标签之间有间隙,会在图片下方产生间隙

22 |
23 |
24 |
25 |

修复前:

26 |
27 |
28 |
29 |
30 | 31 |
32 |
33 |
34 |
35 |
36 |
37 |

修复后:

38 |
39 |
40 |
41 |
42 | 43 |
44 |
45 |

解决方案:为img添加display:block;

46 |
47 |
48 |
49 |
50 | 51 |
52 |
53 |

解决方案:为img添加vertical-align:top;

54 |
55 |
56 |
57 |
58 | 59 |
60 |
61 |

解决方案:在img的父容器中添加font-size:0; line-height:0;

62 |
63 |
64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /code/Common.js: -------------------------------------------------------------------------------- 1 | //图片加载完成后执行 2 | function imageDownload(resources, callback) { 3 | var len = resources.length; 4 | var num = len; 5 | var list = []; 6 | for(var i=0;i 2 | 3 | 4 | 5 | 完美遮罩层 6 | 7 | 15 | 16 | 17 |
18 |
19 | 返回列表>> 20 |

完美遮罩层

21 |

浏览器:*

22 |

描述:容器透明,内容不透明

23 |
24 |
25 |
26 | 35 |

HTML结构 36 |

37 | <a class="pic" href="#">
38 | 	<img src="../images/test.jpg" />
39 | 	<div class="hover">
40 | 		<div class="bg"></div>
41 | 		<div class="content">我是不透明的内容</div>
42 | 	</div>
43 | </a>
44 | 						
45 |

46 |

CSS样式 47 |

48 | .pic{width:180px; height:180px; display:block; position:relative;}
49 | .hover{display:none;}
50 | .pic:hover{zoom:1; cursor:pointer;}
51 | .pic:hover .hover{display:block; position:absolute; top:0; left:0; z-index:9; }
52 | .hover .bg{width:180px; height:180px; background:#000; opacity:.75; filter:alpha(opacity=75);}
53 | .hover .content{width:180px; height:180px; position:absolute; top:0; left:0; color:#fff; z-index:99;}
54 | 						
55 |

56 |
57 |
58 |
59 | 60 | 61 | -------------------------------------------------------------------------------- /ie-bug/demo/8.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | li底部空白行 6 | 7 | 14 | 15 | 16 |
17 |
18 | 返回列表>> 19 |

li底部空白行

20 |

浏览器:IE6

21 |

描述:li里面的a标签display:block;时,并未触发layout。

22 |
23 |
24 |
25 |

修复前:

26 |
27 |
28 |
29 | 34 |
35 |
36 |
37 |
38 |
39 |

修复后:

40 |
41 |
42 |
43 | 48 |
49 |

解决方案:li中添加_display:inline;此时hover只在a标签的文本中生效

50 |
51 |
52 |
53 | 58 |
59 |

解决方案:触发a标签的layout,_zoom:1;

60 |
61 |
62 |
63 | 68 |
69 |

解决方案:触发a标签的layout,width:100%;

70 |
71 |
72 |
73 | 74 | 75 | -------------------------------------------------------------------------------- /ie-bug/demo/31.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 绝对定位元素消失bug 6 | 7 | 16 | 17 | 18 |
19 |
20 | 返回列表>> 21 |

绝对定位元素消失bug

22 |

浏览器:IE6

23 |

描述:一个内容区块,其中包含两个浮动的box,外加一个绝对定位的box,设置如下样式时会发生IE6绝对定位元素消失的BUG。

24 |
25 |
26 |
27 |

修复前:

28 |
29 |
30 |
31 |
32 |
abs
33 |
main
34 |
sub
35 |
36 |
37 |
38 |
39 |
40 |
41 |

修复后:

42 |
43 |
44 |
45 |
46 |
abs
47 |
main
48 |
sub
49 |
50 |
51 |

解决方案:给content加一个display:inline样式

52 |
53 |
54 |
55 |
56 |
abs
57 |
main
58 |
sub
59 |
60 |
61 |

解决方案:在main元素之前加一个空的<div></div>

62 |
63 |
64 |
65 |
66 |
abs
67 |
main
68 |
sub
69 |
70 |
71 |

解决方案:给abs元素再嵌套一个div元素

72 |
73 |
74 |
75 | 76 | 77 | -------------------------------------------------------------------------------- /ie-bug/demo/24.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | inline-block元素间间距 6 | 7 | 15 | 16 | 17 |
18 |
19 | 返回列表>> 20 |

inline-block元素间间距

21 |

浏览器:*

22 |

描述:真正意义上的inline-block水平呈现的元素间,换行显示或空格分隔的情况下会有间距

23 |
24 |
25 |
26 |

修复前:

27 |
28 |
29 |
30 |
31 | 惆怅 32 | 淡定 33 | 热血 34 |
35 |
36 |
37 |
38 |
39 |
40 |

修复后:

41 |
42 |
43 |
44 |
45 | 惆怅 46 | 淡定 47 | 热血 48 |
49 |
50 |

解决方案:使用font-size:0;基本上可以解决大部分浏览器下inline-block元素之间的间距(IE7等浏览器有时候会有1像素的间距)

51 |
52 |
53 |
54 |
55 | 惆怅 56 | 淡定 57 | 热血 58 |
59 |
60 |

解决方案:使用margin负值

61 |
62 |
63 |
64 |
65 | 惆怅 66 | 淡定 67 | 热血 68 |
69 |
70 |

解决方案: 71 |

72 | /***父容器中***/
73 | font-size:0; /*所有浏览器*/
74 | *word-spacing:-1px; /* IE6/7 */
75 | /***子元素****/
76 | font-size: 12px;
77 | letter-spacing: normal;
78 | word-spacing: normal;
79 | vertical-align:top;						
80 | 						
81 |

82 |
83 |
84 |
85 | 86 | 87 | -------------------------------------------------------------------------------- /code/EventUtil.js: -------------------------------------------------------------------------------- 1 | //跨浏览器事件对象 2 | var EventUtil = { 3 | addEvent:function(element,type,handler){ // 添加绑定 4 | if(element.addEventListener){ 5 | element.addEventListener(type,handler,false); 6 | }else if(element.attachEvent){ 7 | element.attachEvent('on'+type,handler); 8 | }else{ 9 | element['on'+type]=handler; 10 | } 11 | }, 12 | removeEvent:function(element,type,handler){ // 删除绑定 13 | if(element.removeEventListener){ 14 | element.removeEventListneter(type,handler,false); 15 | }else if(element.detachEvent){ 16 | element.detachEvent('on'+type,handler); 17 | }else{ 18 | element['on'+type]=null; 19 | } 20 | }, 21 | fireEvent:function(element, type) { 22 | if (document.createEventObject) { // IE浏览器支持fireEvent方法 23 | var evt = document.createEventObject(); 24 | return element.fireEvent('on' + type, evt) 25 | }else if(document.createEvent){ // 其他标准浏览器使用dispatchEvent方法 26 | var evt = document.createEvent('HTMLEvents'); 27 | evt.initEvent(type, true, false); 28 | return !element.dispatchEvent(evt); 29 | }else{ // 最新标准 30 | var evt = new Event(type, { bubbles: true, cancelable: false }); 31 | element.dispatchEvent(evt); 32 | } 33 | }, 34 | getEvent:function(event){ //返回事件对象引用 35 | return event?event:window.event; 36 | }, 37 | getTarget:function(event){ //返回事件源目标 38 | return event.target||event.srcElement; 39 | }, 40 | preventDefault:function(event){ //取消默认事件 41 | if(event.preventDefault){ 42 | event.preventDefault(); 43 | }else{ 44 | event.returnValue=false; 45 | } 46 | }, 47 | stoppropagation:function(event){ //阻止事件流 48 | if(event.stoppropagation){ 49 | event.stoppropagation(); 50 | }else{ 51 | event.canceBubble=false; 52 | } 53 | }, 54 | getRelatedTarget:function(event){ //获取相关元素 55 | if(event.relatedTarget){ 56 | return event.relatedTarget; 57 | }else if(event.toElement){ 58 | return envent.toElement; 59 | }else if(event.fromElement){ 60 | return event.fromElement; 61 | }else{ 62 | return null; 63 | } 64 | }, 65 | getButton:function(event){ //鼠标事件的button属性检测 66 | if(document.implementation.hasFeature('MouseEvent','2.0')){ 67 | return event.button; 68 | }else{ 69 | switch(event.button){ 70 | case 0: 71 | case 1: 72 | case 3: 73 | case 5: 74 | case 7: 75 | return 0; 76 | case 2: 77 | case 6: 78 | return 2; 79 | case 4: 80 | return 1; 81 | } 82 | } 83 | }, 84 | getCharCode:function(event){ //字符编码charCode属性检测 85 | if(typeof event,charCode=='number'){ 86 | return event.charCode; 87 | }else{ 88 | return event.keyCode; 89 | } 90 | }, 91 | getClipboardData:function(event){ 92 | var clipboardData=(event.clipboardData||window.clipboardData); 93 | return clipboardData.getData("text"); 94 | }, 95 | setClipboardData:function(event,value){ 96 | if(event.clipboardData){ 97 | return event.clipboardData.setData("text/plain",value); 98 | }else if(window.clipboardData){ 99 | return window.clipboardData.setData("text",value); 100 | } 101 | }, 102 | getWheelDlta : function(event){ 103 | if(event.wheelDelta){ 104 | return event.wheelDelta; 105 | }else{ 106 | return -event.detail * 40; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /code/DOMUtil.js: -------------------------------------------------------------------------------- 1 | //跨浏览器DOM对象 2 | var DOMUtil = { 3 | getStyle:function(node,attr){ 4 | return node.currentStyle ? node.currentStyle[attr] : getComputedStyle(node,0)[attr]; 5 | }, 6 | getScroll:function(){ //获取滚动条的滚动距离 7 | var scrollPos={}; 8 | if (window.pageYOffset||window.pageXOffset) { 9 | scrollPos['top'] = window.pageYOffset; 10 | scrollPos['left'] = window.pageXOffset; 11 | }else if (document.compatMode && document.compatMode != 'BackCompat'){ 12 | scrollPos['top'] = document.documentElement.scrollTop; 13 | scrollPos['left'] = document.documentElement.scrollLeft; 14 | }else if(document.body){ 15 | scrollPos['top'] = document.body.scrollTop; 16 | scrollPos['left'] = document.body.scrollLeft; 17 | } 18 | return scrollPos; 19 | }, 20 | getWindow:function(){ //获取可视窗口大小 21 | if(typeof window.innerWidth !='undefined') { 22 | return{ 23 | width : window.innerWidth, 24 | height : window.innerHeight 25 | }; 26 | }else{ 27 | return { 28 | width : document.documentElement.clientWidth, 29 | height : document.documentElement.clientHeight 30 | }; 31 | } 32 | }, 33 | getClient:function(){ //获取浏览器的可视区域位置 34 | var l,t,w,h; 35 | l = document.documentElement.scrollLeft || document.body.scrollLeft; 36 | t = document.documentElement.scrollTop || document.body.scrollTop; 37 | w = document.documentElement.clientWidth; 38 | h = document.documentElement.clientHeight; 39 | return {'left':l,'top':t,'width':w,'height':h} ; 40 | }, 41 | getNextElement:function(node){ //获取下一个节点 42 | if(node.nextElementSibling){ 43 | return node.nextElementSibling; 44 | }else{ 45 | var NextElementNode = node.nextSibling; 46 | while(NextElementNode.nodeValue != null){ 47 | NextElementNode = NextElementNode.nextSibling; 48 | } 49 | return NextElementNode; 50 | } 51 | }, 52 | getElementById:function(idName){ 53 | return document.getElementById(idName); 54 | }, 55 | getStyle:function(element, property){ 56 | var proValue = null; 57 | if (!document.defaultView) { 58 | proValue = element.currentStyle[property]; 59 | } else { 60 | proValue = document.defaultView.getComputedStyle(element)[property]; 61 | } 62 | return proValue; 63 | }, 64 | getElementsByClassName:function(className,context,tagName){ //根据class获取节点 65 | if(typeof context == 'string'){ 66 | tagName = context; 67 | context = document; 68 | }else{ 69 | context = context || document; 70 | tagName = tagName || '*'; 71 | } 72 | if(context.getElementsByClassName){ 73 | return context.getElementsByClassName(className); 74 | } 75 | var nodes = context.getElementsByTagName(tagName); 76 | var results= []; 77 | for (var i = 0; i < nodes.length; i++) { 78 | var node = nodes[i]; 79 | var classNames = node.className.split(' '); 80 | for (var j = 0; j < classNames.length; j++) { 81 | if (classNames[j] == className) { 82 | results.push(node); 83 | break; 84 | } 85 | } 86 | } 87 | return results; 88 | }, 89 | getSelectedText:function() { 90 | if (window.getSelection) { 91 | return window.getSelection().toString(); 92 | }else if (document.getSelection) { 93 | return document.getSelection(); 94 | }else if (document.selection) { 95 | return document.selection.createRange().text; 96 | } 97 | }, 98 | hasClass:function(node,classname){ 99 | return node.className.match(new RegExp('(\\s|^)'+classname+'(\\s|$)')); 100 | }, 101 | addClass:function(node,classname){ //对节点增加class 102 | if(!this.hasClass(node,classname)){ 103 | node.className = (node.className+" "+classname).replace(/^\s+|\s+$/g,''); 104 | } 105 | }, 106 | removeClass:function(node,classname){ //对节点删除class 107 | node.className = (node.className.replace(classname,"")).replace(/^\s+|\s+$/g,''); 108 | } 109 | }; -------------------------------------------------------------------------------- /ie-bug/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 列表 6 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 |
序号名称描述
1水平居中使用margin:0 auto;无法居中块元素
2双外边距浮动bug使用float浮动容器,如果浮动容器具有margin值,则呈现margin-left值双倍情况
3绝对定位奇数宽高1px间距bug当绝对定位元素的父元素高或宽为奇数时,bottom和right会多出1px
4外边距叠加外边距叠加的算法
5内联元素marginIE中内联元素撑开容器
6清除内部浮动当子元素浮动且未知高度时,如何使父容器适应子元素的高度
7垂直列表间隔bug当li中出现2个或以上的浮动时,li之间产生的空白间隙的BUG
8li底部空白行li里面的a标签display:block;时,并未触发layout
9浮动元素3px间隔Bug发生在一个元素浮动,然后一个不浮动的元素自然上浮与之靠近会出现的3px的bug
10图片下方出现空白间隙当图片为其父容器的唯一子元素,且代码中标签之间有间隙,会在图片下方产生间隙
11无法设置微型高度IE6及更早浏览器默认高度为19px行高,高度无法设置为小于19px的值
12按钮留白随value增加button、input两边留白随value长度的增加而增加
13文本溢出BUG造成此BUG的原因可能是多重混合的
14!important规则在一些情况下浏览器忽略!important规则
15overflow失效IE7及更早浏览器下子元素相对定位时父元素overflow属性的auto|hidden失效
16完美遮罩层容器透明,内容不透明
17列表阶梯bugfloat列表元素不水平对齐
18z-index层次错误IE6中的绝对定位元素,z-index只与父容器的z-index进行比较
19盒模型(无声明)  盒模型(含声明)当没有DTD声明时,所有IE版本也会进入Quirks Mode
20IE透明滤镜兼容各版本IE的滤镜
21不支持png透明图片IE6中不支持png24的透明效果
22background-color失效:hover 时若background-color为#fff, 失效
23图片垂直居中图片无法通过display:table-cell; vertical-align:middle;设置垂直居中
24inline-block元素间间距如何取消inline-block元素间间距
25滤镜致链接失效BUGE6下使用DXImageTransform.Microsoft.AlphaImageLoader滤镜后链接不能点击
26图片与文本垂直对齐居中当图片与文本在一起,且图片由链接包含,设置行高无法水平居中
27display:none引起的3像素的BUG一些浮动元素中有一个display:none;的元素,会引起3px的误差
28距出边界的Bug子元素块不被隐藏会溢出父元素块
29浮动层错位当内容超出外包容器定义的宽度时会导致浮动层错位问题
30li背景失效当li中有浮动元素时,且li的display为inline;
31绝对定位元素消失bug两个浮动的box,外加一个绝对定位的box,设置如下样式时会发生IE6绝对定位元素消失
32margin-top失效当某块级元素设置了margin-top,并且之前存在着可被渲染的绝对定位元素时,其margin-top在IE6、IE7会失效。
33无法取消input默认边框无法使用border:nonoe;取消input默认边框
34右浮动元素换行当一个容器内有文本(或一般文档流布局的元素)和向右浮动元素,浮动元素另起一行浮动
133 |
134 | 135 | 136 | -------------------------------------------------------------------------------- /code/ECMAScript5.js: -------------------------------------------------------------------------------- 1 | /* 2 | ECMAScript5 Polyfill 3 | */ 4 | 5 | //函数 6 | if (!Function.prototype.bind) { 7 | Function.prototype.bind = function(oThis) { 8 | if (typeof this !== 'function') { 9 | // closest thing possible to the ECMAScript 5 10 | // internal IsCallable function 11 | throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); 12 | } 13 | var aArgs = Array.prototype.slice.call(arguments, 1), 14 | fToBind = this, 15 | fNOP = function() {}, 16 | fBound = function() { 17 | return fToBind.apply(this instanceof fNOP 18 | ? this 19 | : oThis, 20 | aArgs.concat(Array.prototype.slice.call(arguments))); 21 | }; 22 | if (this.prototype) { 23 | // Function.prototype doesn't have a prototype property 24 | fNOP.prototype = this.prototype; 25 | } 26 | fBound.prototype = new fNOP(); 27 | return fBound; 28 | }; 29 | } 30 | 31 | //数值 32 | if(!Number.toFixed){ 33 | Number.prototype.toFixed = function(len){ 34 | var times = Math.pow(10,len); 35 | return Math.round(this*times)/times; 36 | } 37 | } 38 | 39 | //字符串 40 | if(!String.prototype.trim) { 41 | String.prototype.trim = function () { 42 | return this.replace(/^\s+|\s+$/g,''); 43 | }; 44 | } 45 | 46 | //日期 47 | if (!Date.now){ 48 | Date.now = function now(){ 49 | return new Date().getTime(); 50 | }; 51 | } 52 | if (!Date.prototype.toISOString) { 53 | (function() { 54 | function pad(number) { 55 | if (number < 10) { 56 | return '0' + number; 57 | } 58 | return number; 59 | } 60 | Date.prototype.toISOString = function() { 61 | return this.getUTCFullYear() + 62 | '-' + pad(this.getUTCMonth() + 1) + 63 | '-' + pad(this.getUTCDate()) + 64 | 'T' + pad(this.getUTCHours()) + 65 | ':' + pad(this.getUTCMinutes()) + 66 | ':' + pad(this.getUTCSeconds()) + 67 | '.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) + 68 | 'Z'; 69 | }; 70 | }()); 71 | } 72 | 73 | //对象 74 | if (typeof Object.create != 'function') { 75 | Object.create = (function(undefined) { 76 | var Temp = function() {}; 77 | return function (prototype, propertiesObject) { 78 | if(prototype !== Object(prototype) && prototype !== null) { 79 | throw TypeError('Argument must be an object, or null'); 80 | } 81 | Temp.prototype = prototype || {}; 82 | if (propertiesObject !== undefined) { 83 | Object.defineProperties(Temp.prototype, propertiesObject); 84 | } 85 | var result = new Temp(); 86 | Temp.prototype = null; 87 | // to imitate the case of Object.create(null) 88 | if(prototype === null) { 89 | result.__proto__ = null; 90 | } 91 | return result; 92 | }; 93 | })(); 94 | } 95 | if (!Object.keys) { 96 | Object.keys = (function() { 97 | 'use strict'; 98 | var hasOwnProperty = Object.prototype.hasOwnProperty, 99 | hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'), 100 | dontEnums = [ 101 | 'toString', 102 | 'toLocaleString', 103 | 'valueOf', 104 | 'hasOwnProperty', 105 | 'isPrototypeOf', 106 | 'propertyIsEnumerable', 107 | 'constructor' 108 | ], 109 | dontEnumsLength = dontEnums.length; 110 | return function(obj) { 111 | if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) { 112 | throw new TypeError('Object.keys called on non-object'); 113 | } 114 | var result = [], prop, i; 115 | for (prop in obj) { 116 | if (hasOwnProperty.call(obj, prop)) { 117 | result.push(prop); 118 | } 119 | } 120 | if (hasDontEnumBug) { 121 | for (i = 0; i < dontEnumsLength; i++) { 122 | if (hasOwnProperty.call(obj, dontEnums[i])) { 123 | result.push(dontEnums[i]); 124 | } 125 | } 126 | } 127 | return result; 128 | }; 129 | }()); 130 | } 131 | 132 | //数组 133 | if (!Array.isArray) { 134 | Array.isArray = function(arg) { 135 | return Object.prototype.toString.call(arg) === '[object Array]'; 136 | }; 137 | } 138 | if (typeof Array.prototype.forEach != "function") { 139 | Array.prototype.forEach = function (fn, context) { 140 | for (var k = 0, length = this.length; k < length; k++) { 141 | if (typeof fn === "function" && Object.prototype.hasOwnProperty.call(this, k)) { 142 | fn.call(context, this[k], k, this); 143 | } 144 | } 145 | }; 146 | } 147 | if (typeof Array.prototype.map != "function") { 148 | Array.prototype.map = function (fn, context) { 149 | var arr = []; 150 | if (typeof fn === "function") { 151 | for (var k = 0, length = this.length; k < length; k++) { 152 | arr.push(fn.call(context, this[k], k, this)); 153 | } 154 | } 155 | return arr; 156 | }; 157 | } 158 | if (typeof Array.prototype.filter != "function") { 159 | Array.prototype.filter = function (fn, context) { 160 | var arr = []; 161 | if (typeof fn === "function") { 162 | for (var k = 0, length = this.length; k < length; k++) { 163 | fn.call(context, this[k], k, this) && arr.push(this[k]); 164 | } 165 | } 166 | return arr; 167 | }; 168 | } 169 | if (typeof Array.prototype.some != "function") { 170 | Array.prototype.some = function (fn, context) { 171 | var passed = false; 172 | if (typeof fn === "function") { 173 | for (var k = 0, length = this.length; k < length; k++) { 174 | if (passed === true) break; 175 | passed = !!fn.call(context, this[k], k, this); 176 | } 177 | } 178 | return passed; 179 | }; 180 | } 181 | if (typeof Array.prototype.every != "function") { 182 | Array.prototype.every = function (fn, context) { 183 | var passed = true; 184 | if (typeof fn === "function") { 185 | for (var k = 0, length = this.length; k < length; k++) { 186 | if (passed === false) break; 187 | passed = !!fn.call(context, this[k], k, this); 188 | } 189 | } 190 | return passed; 191 | }; 192 | } 193 | if (typeof Array.prototype.indexOf != "function") { 194 | Array.prototype.indexOf = function (searchElement, fromIndex) { 195 | var index = -1; 196 | fromIndex = fromIndex * 1 || 0; 197 | for (var k = 0, length = this.length; k < length; k++) { 198 | if (k >= fromIndex && this[k] === searchElement) { 199 | index = k; 200 | break; 201 | } 202 | } 203 | return index; 204 | }; 205 | } 206 | if (typeof Array.prototype.lastIndexOf != "function") { 207 | Array.prototype.lastIndexOf = function (searchElement, fromIndex) { 208 | var index = -1, length = this.length; 209 | fromIndex = fromIndex * 1 || length - 1; 210 | for (var k = length - 1; k > -1; k-=1) { 211 | if (k <= fromIndex && this[k] === searchElement) { 212 | index = k; 213 | break; 214 | } 215 | } 216 | return index; 217 | }; 218 | } 219 | if (typeof Array.prototype.reduce != "function") { 220 | Array.prototype.reduce = function (callback, initialValue ) { 221 | var previous = initialValue, k = 0, length = this.length; 222 | if (typeof initialValue === "undefined") { 223 | previous = this[0]; 224 | k = 1; 225 | } 226 | if (typeof callback === "function") { 227 | for (k; k < length; k++) { 228 | this.hasOwnProperty(k) && (previous = callback(previous, this[k], k, this)); 229 | } 230 | } 231 | return previous; 232 | }; 233 | } 234 | if (typeof Array.prototype.reduceRight != "function") { 235 | Array.prototype.reduceRight = function (callback, initialValue ) { 236 | var length = this.length, k = length - 1, previous = initialValue; 237 | if (typeof initialValue === "undefined") { 238 | previous = this[length - 1]; 239 | k--; 240 | } 241 | if (typeof callback === "function") { 242 | for (k; k > -1; k-=1) { 243 | this.hasOwnProperty(k) && (previous = callback(previous, this[k], k, this)); 244 | } 245 | } 246 | return previous; 247 | }; 248 | } -------------------------------------------------------------------------------- /code/Tool.js: -------------------------------------------------------------------------------- 1 | //工具方法 2 | var Tool = { 3 | // Cookie设置 4 | addCookie:function(objName,objValue,objHours,objDomain,objPath){ //添加cookie 5 | var str = objName + "=" + encodeURIComponent(objValue); 6 | if(objHours > 0){ 7 | var date = new Date(); 8 | var ms = objHours*3600*1000; 9 | date.setTime(date.getTime() + ms); 10 | str += "; expires=" + date.toGMTString(); 11 | if(objDomain){ 12 | str += ";domain="+objDomain; 13 | } 14 | if(objPath){ 15 | str += ";path="+objPath; 16 | } 17 | } 18 | document.cookie = str; 19 | }, 20 | getCookie:function(objName){ //获取指定名称的cookie的值 21 | var arrStr = document.cookie.split("; "); 22 | for(var i = 0;i < arrStr.length;i ++){ 23 | var temp = arrStr[i].split("="); 24 | if(temp[0] == objName) return decodeURIComponent(temp[1]); 25 | } 26 | }, 27 | delCookie:function(name){ //为了删除指定名称的cookie,可以将其过期时间设定为一个过去的时间 28 | var date = new Date(); 29 | date.setTime(date.getTime() - 10000); 30 | document.cookie = name + "=a; expires=" + date.toGMTString(); 31 | }, 32 | // 对象合并 33 | extend:function (target, source) { 34 | for (var p in source) { 35 | if (source.hasOwnProperty(p)) { 36 | target[p] = source[p]; 37 | } 38 | } 39 | return target; 40 | }, 41 | // 格式化 42 | date:function(fmt,timestamp){ 43 | // 对Date的扩展,将 Date 转化为指定格式的String 44 | // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, 45 | // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 46 | // 例子: 47 | // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 48 | // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 49 | var day = timestamp?new Date(timestamp):new Date(); 50 | var o = { 51 | "M+" : day.getMonth()+1, //月份 52 | "d+" : day.getDate(), //日 53 | "h+" : day.getHours(), //小时 54 | "m+" : day.getMinutes(), //分 55 | "s+" : day.getSeconds(), //秒 56 | "q+" : Math.floor((day.getMonth()+3)/3), //季度 57 | "S" : day.getMilliseconds() //毫秒 58 | }; 59 | if(/(y+)/.test(fmt)){ 60 | fmt=fmt.replace(RegExp.$1, (day.getFullYear()+"").substr(4 - RegExp.$1.length)); 61 | } 62 | for(var k in o){ 63 | if(new RegExp("("+ k +")").test(fmt)){ 64 | fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); 65 | } 66 | } 67 | return fmt; 68 | }, 69 | // 复制文本 70 | setClipboard(text,callback){ 71 | var callback = callback||function(){}; 72 | window.getSelection().removeAllRanges(); 73 | var selection = window.getSelection(); 74 | var newdiv = document.createElement('div'); 75 | newdiv.style.position = 'absolute'; 76 | newdiv.style.left = '-99999px'; 77 | document.body.appendChild(newdiv); 78 | newdiv.innerHTML = text; 79 | selection.selectAllChildren(newdiv); 80 | document.execCommand("Copy"); 81 | window.setTimeout(function () { 82 | document.body.removeChild(newdiv); 83 | callback(); 84 | }, 100); 85 | }, 86 | // 下载图片 87 | downloadImage(src){ 88 | var canvas = document.createElement('canvas'); 89 | var img = document.createElement('img'); 90 | var format = src.indexOf('.png')>-1?"image/png":"image/jpeg"; 91 | img.onload = function(e) { 92 | canvas.width = img.width; 93 | canvas.height = img.height; 94 | var context = canvas.getContext('2d'); 95 | context.drawImage(img, 0, 0, img.width, img.height); 96 | canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height); 97 | canvas.toBlob((blob)=>{ 98 | let link = document.createElement('a'); 99 | link.href = window.URL.createObjectURL(blob); 100 | link.download = 'aaa'; 101 | link.click(); 102 | }, format); 103 | } 104 | img.setAttribute("crossOrigin",'Anonymous'); 105 | img.src = src; 106 | }, 107 | // 解析URL 108 | parseURL:function(url){ //URL解析 109 | var a = document.createElement('a'); 110 | a.href = url; 111 | return { 112 | source: url, 113 | protocol: a.protocol.replace(':',''), 114 | host: a.hostname, 115 | port: a.port, 116 | query: a.search, 117 | params: (function(){ 118 | var ret = {}, 119 | seg = a.search.replace(/^\?/,'').split('&'), 120 | len = seg.length, i = 0, s; 121 | for (;i= wait) { // 如果距离上次执行超过了等待时间,立即执行 205 | if (timer) { 206 | clearTimeout(timer); 207 | timer = null; 208 | } 209 | lastResult = await invokeFn(); 210 | } else { 211 | if (!timer) { // 如果没有定时器,设置一个定时器确保在wait时间后执行 212 | return new Promise((resolve)=>{ 213 | timer = setTimeout(async () => { 214 | lastResult = await invokeFn(); 215 | timer = null; 216 | resolve(lastResult); 217 | }, wait - elapsed); 218 | }); 219 | } else { // 否则更新防抖定时器,确保最后一次调用一定会执行 220 | clearTimeout(timer); 221 | return new Promise((resolve)=>{ 222 | timer = setTimeout(async () => { 223 | lastResult = await invokeFn(); 224 | timer = null; 225 | resolve(lastResult); 226 | }, wait); 227 | }); 228 | } 229 | } 230 | return lastResult; 231 | }; 232 | }, 233 | // 类型判断 234 | in_array:function(val,arr){ //元素是否在数组中 235 | for(i=0;i