Skip to content

Instantly share code, notes, and snippets.

@simplelife7
simplelife7 / hacks.css
Created May 20, 2012 08:06
【CSS】Hacks
.all-IE{property:value\9;}
:root .IE-9{property:value\0/;}
.gte-IE-8{property:value\0;}
.lte-IE-7{*property:value;}
.IE-7{+property:value;}
.IE-6{_property:value;}
.not-IE{property//:value;}
@-moz-document url-prefix() { .firefox{property:value;} }
@media all and (-webkit-min-device-pixel-ratio:0) { .webkit{property:value;} }
@media all and (-webkit-min-device-pixel-ratio:10000),not all and (-webkit-min-device-pixel-ratio:0) { .opera{property:value;} }
@simplelife7
simplelife7 / clearfix.css
Created May 20, 2012 08:07
【CSS】clearfix
/* 清除浮动 */
.fix:after {
visibility:hidden;
display:block;
font-size:0;
content:" ";
clear:both;
height:0;
}
.clearfix {
@simplelife7
simplelife7 / html.html
Created May 20, 2012 08:11
【技巧】未知宽高图片在已知宽高容器中垂直水平居中
<div class="goods_pic img_vh_box">
<span class="inner">
<a href="#">
<img src="http://ppms.paipaioa.com/img/demo/60x60.png" alt=""></a>
</span>
</div>
@simplelife7
simplelife7 / background-gradient.css
Created May 20, 2012 08:15
【CSS】CSS3渐变
background: -moz-linear-gradient(top, #FEFEFE 1%, #F1F1F3 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#FEFEFE), color-stop(100%,#F1F1F3)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #FEFEFE 1%,#F1F1F3 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #FEFEFE 1%,#F1F1F3 100%); /* Opera11.10+ */
background: -ms-linear-gradient(top, #FEFEFE 1%,#F1F1F3 100%); /* IE10+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#FEFEFE', endColorstr='#F1F1F3',GradientType=0 ); /* IE6-9 */
background: linear-gradient(top, #FEFEFE 1%,#F1F1F3 100%); /* W3C */
@simplelife7
simplelife7 / loop-optimization.js
Created May 20, 2012 08:25
【JS】循环优化
// 缓存
for(var i=0, j = document.getElementsByTagName('a').length; i0; i--){
}
// 据说是最快的
while(i--){
// maybe fastest
}
@simplelife7
simplelife7 / parent-node-listen.js
Created May 20, 2012 08:57
【JS】在外层元素监听事件
// 使用事件代理,在更外层的元素上监听事件
document.getElementById('list').onclick = function(evt){
var evt = evt || window.event,
target = evt.target || evt.srcElement;
if(target.id === 'btn1'){
// do something
}
}
@simplelife7
simplelife7 / console.js
Created May 20, 2012 09:00
【JS】console调试常用方法
// 尽量使用,可以传入多个参数,最后输出拼接后的字符串
console.log('xx','xx','...');
console.dir(someObj);
console.dirxml(someDom);
console.time('timer');
console.warn('xxx');
// 封装可以保证不小心发布出去也不会导致问题,但报错时行号可能有问题
function msg(msg){
if(console && console.log){
@simplelife7
simplelife7 / chrome-12px.css
Created May 24, 2012 03:41
【CSS】chrome下字体小于12px hack
{-webkit-text-size-adjust:none;}
@simplelife7
simplelife7 / css3-transition.css
Created May 29, 2012 16:18
【CSS】CSS3过渡transition
/* 简写:单个属性:*/
-moz-transition:background 0.5s ease-out 0s;
/* 简写:多个属性:*/
-moz-transition:background, 0.5s ease-out 0s, color 0.4 ease-out 0s;
/* 过渡单个 */
{
transition-property:opacity;
transition-duration:2s;
transition-timing-function:ease-in;
@simplelife7
simplelife7 / optClass.js
Created July 27, 2012 09:33
【JS】操作class
function hasClass(el, name) {
return new RegExp('(\\s|^)'+name+'(\\s|$)').test(el.className);
}
function addClass(el, name)
{
if (!hasClass(el, name)) { el.className += (el.className ? ' ' : '') +name; }
}
function removeClass(el, name)
{