悲欢收藏夹

那只是我喃喃自语间不能自控的迷惘

瀑布流100%宽的浮动布局解决方案(绝对干货)

思路就是不同的分辨率判断几列,然后再动态插入,此方法优点就是各大浏览器兼容,不同的分辨率兼容,网上大部分是绝对定位的方式,次方法要比绝对定位的效率高的多。

demo

注意几个特殊值,1170,1407,1644,1881

var bodyWidth =$(document).width();
if(bodyWidth < 1170){
$(“.wrapper”).css({“width”:”933px”});
}else if(bodyWidth < 1407){
$(“.wrapper”).css({“width”:”1170px”});
}else if(bodyWidth < 1644){
$(“.wrapper”).css({“width”:”1407px”});
}else if(bodyWidth < 1881){
$(“.wrapper”).css({“width”:”1644px”});
}else{
alert(“你在用小霸王吗”)
}

简单的jquery无缝滚动代码

原理是复制li插入ul再删除掉li就可以了,代码不通用,但看起来非常简单

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js” type=”text/javascript”></script>

$(“.pre”).click(function(){
$(“.scroll ul”).css({“width”:$(“.scroll ul li”).length*200+”px”});
$(“.scroll ul li:last”).clone().prependTo(‘.scroll ul’);
$(“.scroll ul li:last”).remove();
$(“.scroll ul”).animate({marginLeft:”0″},400);
})
$(“.next”).click(function(){
$(“.scroll ul”).css({“width”:$(“.scroll ul li”).length*200+”px”});
$(“.scroll ul li:last”).clone().prependTo(‘.scroll ul’);
$(“.scroll ul li:last”).remove();
$(“.scroll ul”).animate({marginRight:”0″},400);
})

<div>
<span>向上</span>
<div>
<ul>

<li><a href=”http://www.leshanju.com/solu/132643632311.html”><img src=”http://tp1.sinaimg.cn/2606002492/50/5618700278/0″ alt=”弱电工程案例” /></a></li>
<li><a href=”http://www.leshanju.com/solu/132643632311.html”><img src=”http://tp3.sinaimg.cn/2532499610/50/5616148789/0″ alt=”弱电工程案例” /></a></li>
<li><a href=”http://www.leshanju.com/solu/132643632311.html”><img src=”http://tp4.sinaimg.cn/2315812271/50/5608976165/1″ alt=”弱电工程案例” /></a></li>
<li><a href=”http://www.leshanju.com/solu/132643632311.html”><img src=”http://tp4.sinaimg.cn/2542997051/50/5619514728/1″ alt=”弱电工程案例” /></a></li>
</ul>

</div>
<span>向下</span>
</div>

<style>
*{margin:0;padding:0;}
a{color:#fff;}
.main{width:100%;height:500px;background:#000; position:relative;}
.open{width:100%;height:500px;background:#F00;display:none;position:relative;}
.scroll{ position:relative;width:300px;margin:0 auto;overflow:hidden;}
.scroll .pre{ position:absolute;left:0;top:0;width:50px;height:30px;background:#fff;}
.scroll .next{ position:absolute;right:0;top:0;width:50px;height:30px;background:#fff;}
.scroll .scroll-bd{width:200px;overflow:hidden;margin-left:50px;}
.scroll ul li{float:left;color:#fff;width:50px;}
.scroll ul{}
</style>

360跟搜狗在各系统下面存在的IE内核

搜狗浏览器版本 3.1.0.3846
IE 版本 IE6
操作系统 xp
详细描述 确认内核为IE6

360浏览器版本 4.1.3.3
IE 版本 IE6
操作系统 xp
详细描述 确认内核为IE6

搜狗浏览器版本 3.1.0.3846
IE 版本 IE6
操作系统 xp
详细描述 确认内核为IE6

360浏览器版本 4.1.3.3
IE 版本 IE8
操作系统 win7
详细描述 确认内核为IE8

搜狗浏览器版本 3.1.0.3846
IE 版本 IE8
操作系统 win7
详细描述 确认内核为IE7

一个房地产网站的浏览器版本

关于ie bug的一些整理

问题 浏览器 DEMO 解决方法
Hacking Rules:

property:all-ie\9; property:gte-ie8\0;*property:lte-ie7; +property:ie7; _property:ie6;

1 input[button | submit] 不能用 margin:0 auto; 居中 IE8 bug | fixed 为input添加width
2 body{overflow:hidden;}没有去掉滚动条 IE6/7 bug | fixed 设置html{overflow:hidden;}
3 hasLayout的标签拥有高度 IE6/7 bug | fixed *height:0;

_overflow:hidden;

4 form>[hasLayout]元素有margin-left时,子元素中的[input | textarea] 出现2×margin-left IE6/7 bug | fixed form > [hasLayout 元素]{margin-left:宽度;}

form div{*margin-left:宽度÷2;}

5 当border-width有1条<边3条时被设置成dotted时,1px的边dotted显示成dashed IE7 bug | fixed 不在同一个元素上使用不同宽度的 dotted
6 当子元素有position:relative的时候,父元素设置overflow:[hidden|auto]相当于给子元素设置了position:visible; IE6/7 bug | fixed 给父元素设置position:relative;
7 :hover伪类不能改变有position:absolute的子级元素的left/top值 IE7 bug | fixed 把top/left的值设置成除0%外的所有百分值;或添加一个margin-[所有方向]除0外的所有值,包括0%
8 :focus + selector {} 选择器失效 IE8 bug | fixed 在失效选择器后面添加一个空选择器, :focus{}
9 列表中混乱的浮动:在list中浮动图片时,图片出现溢出正常位置;或没有list-style IE8 bug | fixed 用背景图片替换list-style
10 th 不会自动继承上级元素的 text-align IE8 bug | fixed 给th添加text-align:inherit;
11 样式(包括link/style/@import(link)) 最多允许个为是:32 IE6-8 ─ 常识 99.99%的情况下,不会遇到
12 :hover 时若background-color为#fff, 失效 IE7 bug | fixed 把background-color改成background。或者,非#fff || #ffffff
13 忽略’>’后有注释的选择器:selector> /**/ selector{} IE7 bug | fixed 官方DEMO有误
14 * html IE6 ─ HACK 只对IE6有效
15 PNG图片中的颜色和背景颜色的值相同,但显示不同 IE6-7 bug | fixed 利用 pngcrush 去除图片中的 Gamma profiles
16 margin:0 auto; 不能让block元素水平居中 IE6-8 bug | fixed 给block元素添加一个width
17 使用伪类 :first-line | :first-letter, 属性的值中出现!important 会使属性失效 IE8 bug | fixed !important is evil, don’t use it anymore
18 :first-letter 失效 IE6 bug | fixed 把 :first-letter 移到离{}最近的地方,如 h1, p:first-letter{},而非 p:first-letter h1{}
19 Position:absolute元素中,a display:block, 在非:hover时只有文本可点击 IE6/7 bug | fixed 给a添加background, 如果背景透明,使用background:url(‘任何页面中已经缓存的文件链接’),不推荐background:url(#)[官方的解决方法],因为会增加一下HTTP请求
20 float列表元素不水平对齐:li不设置float,a设置display:block;float:[方向],li不水平对齐 IE6/7 bug | fixed 给li设置display:inline 或 float:[方向]
21 dt, dd, li 背景失效 IE6 bug | fixed dt, dd, li{position:relative;}
22 <noscript />元素的样式在启用javascript的情况下显示了样式 IE6-8 bug | fixed 利用js给<noscript />添加display:none;
23 使用filter处理的透明背景图片的透明部分不可点 IE6-8 bug | fixed 把background:none变成background:url(‘链接’),链接到本身和图片之外的任何文件
24 li内元素偏离 baseline 向下拉 IE8 bug | fixed 给li设置display:inline 或 float:[方向]
25 列表中li的list-style不显示 IE6/7 bug | fixed 给li添加margin-left,留空间来显示(不要加在ul上)
26 图片不能垂直居中 IE6/7 bug/fixed 添加一个空标签,并赋给”Layout”, 比如display:inline-block;
27 不能自定义指针样式 IE6-8 bug | fixed 给指针文件设置绝对路径
28 背景溢出,拖动滚动条后显示正常 IE6 bug | fixed 给父元素添加overflow:hidden防止溢出,并赋予hasLayout,如果添加_zoom:1;
29 高度超过height定义的高 IE6 bug/fixed 添加_overflow:hidden;(推荐)或者_font-size:0;
30 宽度超过width定义的宽 IE6 bug/fixed 添加_overflow:hidden;
31 双倍边距 IE6 ─ 常识 添加display:inline到float元素中
32 margin负值隐藏:hasLayout的父元素内的非hasLayout元素,使用负边距时,超出父元素部分不可见 IE6/7 bug/fixed 去掉父元素的hasLayout;或者赋hasLayout给子元素,并添加position:relative;
33 给两个浮动元素的某中一个的文字设定为斜体,另一个元素下拉在有斜体文字元素的下面 IE6 bug/fixed 给有斜体文字的元素添加overflow:hidden;
35 3px 间隔:在float元素后的元素,会有3px间隔 IE6 bug/fixed 因为是确切的3px,所以,用“暴力破解”吧,比如_margin-left:-3px;
35 text-align 影响块级元素 IE6/7 bug/fixed 整理你的float;或者分开设置text-align

滚动条底部触发事件

腾讯微博以前使用的就是这个效果,这个的原理就是,窗口距离与窗口高度加起来等于文档的总高度,上代码

$(window).scroll(function(){
var isFoot = $(document).scrollTop() + $(window).height() == $(document).height();
if(isFoot){
alert(“已经到底部了”)
}
})

如果是层,代码是一个道理

如何让复选框单选框与文字对齐

复选框跟单选框在14号字体的时候是没有问题的,触发条件是使用12号字体,我们来看下默认样式

BUG就是在火狐下没对齐,然后IE与文字之间的间距,莫名其妙多了3个像素,造成的原因其实我也不知道,我琢磨着IE的对齐方式是vertical-align:baseline方式对齐,最后解决他们,代码如下:

<style>
.test input{vertical-align:middle; margin-top:-2px; margin-bottom:1px;margin-right:6px;*margin-right:3px;*margin-left:-3px;}
</style>
<div>
<input type=”checkbox”/>我是文字
<input type=”radio”/>我是文字
</div>

注意是给input加样式,然后vertical-align:middle; margin-top:-2px; margin-bottom:1px;是解决与文字对齐的问题,后面是解决input间距的问题

好了,基本完美解决,当然这个文章写的不好,因为是给自己看看就好了

第二种办法是直接给文字加样式

<style>
*{margin:0;padding:0;}
label{vertical-align:middle}
.inputcheckbox{vertical-align:middle;}
body{font-family:tahoma;font-size:12px;}
</style>
<input name=”test” value=”1″ type=”checkbox”>
<label>测试文字x</label>

html5新的特性

1. 新的Doctype

尽管使用<!DOCTYPE html>,即使浏览器不懂这句话也会按照标准模式去渲染

2. Figure元素

用<figure>和<figcaption>来语义化地表示带标题的图片

<figure>

<img src="path/to/image" alt="About image" />

<figcaption>

<p>This is an image of something interesting. </p>

</figcaption>

</figure>

3. 重新定义的<small>

<small>已经被重新定义了,现在被用来表示小的排版,如网站底部的版权声明

4. 去掉link和script标签里面的type属性

5. 加/不加 括号

HTML5没有严格的要求属性必须加引号,闭合不闭合,但是建议加上引号和闭合标签

6. 让你的内容可编辑,只需要加一个contenteditable属性

7. Email Inputs

如果我们给Input的type设置为email,浏览器就会验证这个输入是否是email类型,当然不能只依赖前端的校验,后端也得有相应的校验

8. Placeholders

这个input属性的意义就是不必通过javascript来做placeholder的效果了

9. Local Storage

使用Local Storage可以永久存储大的数据片段在客户端(除非主动删除),目前大部分浏览器已经支持,在使用之前可以检测一下window.localStorage是否存在

10. 语义化的header和footer

11. 更多的HTML5表单特性

12. IE和HTML5

默认的,HTML5新元素被以inline的方式渲染,不过可以通过下面这种方式让

其以block方式渲染

header, footer, article, section, nav, menu, hgroup {

display: block;

}

不幸的是IE会忽略这些样式,可以像下面这样fix:

document.createElement("article");

document.createElement("footer");

document.createElement("header");

document.createElement("hgroup");

document.createElement("nav");

document.createElement("menu");

13. hgroup

一般在header里面用来将一组标题组合在一起,如

<header>

<hgroup>

<h1> Recall Fan Page </h1>

<h2> Only for people who want the memory of a lifetime. </h2>

</hgroup>

</header>

14. Required属性

required属性定义了一个input是否是必须的,你可以像下面这样声明

<input type=”text” name=”someInput” required>

或者

<input type=”text” name=”someInput” required=”required”>

15. Autofocus属性

正如它的词义,就是聚焦到输入框里面

<input type=”text” name=”someInput” placeholder=”Douglas Quaid”  required autofocus>

16. Audio支持

HTML5提供了<audio>标签,你不需要再按照第三方插件来渲染音频,大多数现代浏览器提供了对于HTML5 Audio的支持,不过目前仍旧需要提供一些兼容处理,如

<audio autoplay="autoplay" controls="controls">

<source src="file.ogg" /><!--FF-->

<source src="file.mp3" /><!--Webkit-->

<a href="file.mp3">Download this file.</a>

</audio>

17. Video支持

和Audio很像,<video>标签提供了对于video的支持,由于HTML5文档并没有给video指定一个特定的编码,所以浏 览器去决定要支持哪些编码,导致了很多不一致。Safari和IE支持H.264编码的格式,Firefox和Opera支持Theora和Vorbis 编码的格式,当使用HTML5 video的时候,你必须都提供:

<video controls preload>

<source src="cohagenPhoneCall.ogv" type="video/ogg; codecs=´vorbis, theora´" />

<source src="cohagenPhoneCall.mp4" type="video/mp4; ´codecs=´avc1.42E01E, mp4a.40.2´" />

<p> Your browser is old. <a href="cohagenPhoneCall.mp4">Download this video instead.</a> </p>

</video>

18. 预加载视频

preload属性就像它的字面意思那么简单,你需要决定是否需要在页面加载的时候去预加载视频

<video preload>

19. 显示视频控制

<video preload controls>

20. 正则表达式

由于pattern属性,我们可以在你的markup里面直接使用正则表达式了

<form action="" method="post">

<label for="username">Create a Username: </label>

<input type="text" name="username" id="username" placeholder="4 <> 10" pattern="[A-Za-z]{4,10}" autofocus required>

<button type="submit">Go </button>

</form>

21. 检测属性支持

除了Modernizr之外我们还可以通过javascript简单地检测一些属性是否支持,如:

<script>

if (!´pattern´ in document.createElement(´input´) ) {

// do client/server side validation

}

</script>

22. Mark元素

把<mark>元素看做是高亮的作用,当我选择一段文字的时候,javascript对于HTML的markup效果应该是这样的:

<h3> Search Results </h3>

<p> They were interrupted, just after Quato said, <mark>”Open your Mind”</mark>. </p>

23. 什么时候用<div>

HTML5已经引入了这么多元素,那么div我们还要用吗?div你可以在没有更好的元素的时候去用。

24. 想立即使用HTML5?

不要等2022了,现在就可以使用了,just do it.

25. 哪些不是HTML5

1)SVG

2)CSS3

3)Geolocation

4)Client Storage

5)Web Sockets

26. Data属性

<div id=”myDiv” data-custom-attr=”My Value”> Bla Bla </div>

CSS中使用:

<style>

h1:hover:after {

content: attr(data-hover-response);

color: black;

position: absolute;

left: 0;

}

</style>

<h1 data-hover-response=”I Said Don’t Touch Me!”> Don’t Touch Me  </h1>

27. Output元素

<output>元素用来显示计算结果,也有一个和label一样的for属性

28. 用Range Input来创建滑块

HTML5引用的range类型可以创建滑块,它接受min, max, step和value属性

可以使用css的:before和:after来显示min和max的值

<input type="range" name="range" min="0" max="10" step="1" value="">

input[type=range]:before { content: attr(min); padding-right: 5px;

}

input[type=range]:after { content: attr(max); padding-left: 5px;}