Skip to content

Instantly share code, notes, and snippets.

@reelin
reelin / position fix hack.less
Created October 24, 2013 07:50
position fix hack.less
/*
@ 名称: position:fixed
@ 用法:添加class
@ 注意:
* 如果需要多个方向的固定位置,比如 top + right,需要加两个 class
* 如果加了.fixed-top, 那么就别给这个元素加 top 属性的值
* 为了不出现异常,这个只作为套用。比如要top:30px 的时候,请在 .fixed-top 的子元素内设置
* 由于我们有打包,所以,改solution是可以滴,但这是强烈不推荐的,因为不利于维护
*/
@reelin
reelin / note
Created December 11, 2012 05:27
代码注意
// 行注释不会被生成到最后的css中。 块注释则会生成到样式文件中
// 代码顺序: 布局(定位)>盒模型(宽高,margin,padding,border)>背景、颜色、字体等
// 尽量不同时给一个盒子设置 width 和 margin-left、margin-right、padding-left、padding-right
// height 同理。
@reelin
reelin / ie.fix.css
Created November 30, 2012 08:24
ie使用HTML5标签
/*
* IE support html5 tag
*/
header, nav, section, footer, aside {
display: block;
}
@reelin
reelin / animate
Created October 10, 2012 11:24
实现jQuery中的animate函数
/**
* animate
*/
(function (d) {
// 判断是否有重名函数
if (d.animate) {
throw new Error('methods already exist');
}
@reelin
reelin / myGetElementsByClassName
Created October 10, 2012 11:22
根据类名得到元素
(function () {
Element.prototype.myGetElementsByClassName = function (name) {
var result = [],
element = this,
childrens = element.children,
lenth = element.childElementCount;
for (var i = 0; i < lenth; i++) {
console.log(childrens[i].className);
if (childrens[i].className.indexOf(name) !== -1) {
@reelin
reelin / sohu-exams-2
Created October 10, 2012 11:17
类和对象(搜狐面试题)
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>man</title>
</head>
<body>
<p>打开console查看运行结果~</p>
<script type="text/javascript">
var Man;
@reelin
reelin / exams2
Created September 22, 2012 05:38
实现一个遍历数组或对象里所有成员的迭代器(搜狐面试题)
var each = function(obj, fn){
//+++++++++++答题区域+++++++++++
var isArray = (Array.isArray) ? Array.isArray(obj) : typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Array]";
for (prop in obj) {
var value = obj[prop];
if (isArray) {
if (fn.call( value, +prop + 1) === false) return;
} else {
if (fn.call(value, value, prop) === false) return;
@reelin
reelin / getSecondToZero.js
Created September 12, 2012 09:46
返回距离当天凌晨的毫秒数
function getSecondToZero() {
var today = new Date(),
hour = today.getHours(),
minutes = today.getMinutes(),
seconds = today.getSeconds(),
zero_hour = 24,
zero_minu = 0,
zero_seconds = 0;
if (seconds != 0) {
zero_seconds = 60;
@reelin
reelin / walkTheDom.js
Created September 12, 2012 09:45
walkTheDom的功能是,遍历所给根结点及其所有子树节点,对每个遍历到的节点都执行callback回调函数
/*
* 方法一
*/
function walkTheDom(root, callback) {
var childrens = root.children,
count = childrens.length;
callback(root);
if (count === 0) {
return;
} else {