This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [jQuery] 左右键快速切换上下篇文章 | |
$(document).keydown(function(e) { | |
if (e.keyCode == 37) { | |
var rnt = $('a[rel="next"]'); | |
if (rnt.length > 0) { | |
location.href = rnt.attr('href'); | |
}; | |
}; | |
if (e.keyCode == 39) { | |
var rpv = $('a[rel="prev"]'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 单行滚动文字 | |
var scrollTimer; | |
$('#js-scroller').hover(function() { | |
clearInterval(scrollTimer); | |
}, function() { | |
var $ths = $(this); | |
scrollTimer = setInterval(function() { | |
scroller($ths); | |
}, 2800); | |
}).trigger('mouseleave'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 去掉 String 中的多余空格 | |
if (!String.prototype.trim) { | |
String.prototype.trim = function() { | |
return this.replace(/^\s+|\s+$/g, ''); | |
}; | |
} | |
// 用法 | |
var str = " some string "; | |
str.trim(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 去掉Javscript数组中的重复元素 | |
function removeDuplicates(arr) { | |
var temp = {}; | |
for (var i = 0; i < arr.length; i++) | |
temp[arr[i]] = true; | |
var r = []; | |
for (var k in temp) | |
r.push(k); | |
return r; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 检查字符串中是否包含其他字符串 | |
if (!Array.prototype.indexOf) { | |
Array.prototype.indexOf = function(obj, start) { | |
for (var i = (start || 0), j = this.length; i < j; i++) { | |
if (this[i] === obj) { | |
return i; | |
} | |
} | |
return -1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 快速初始化 Javscript 数组 | |
var numbers = []; | |
for (var i = 1; numbers.push(i++) < 100;); | |
//numbers = [0,1,2,3 ... 100] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 检查表单数据是否改变 | |
function formIsDirty(form) { | |
for (var i = 0; i < form.elements.length; i++) { | |
var element = form.elements[i]; | |
var type = element.type; | |
if (type == "checkbox" || type == "radio") { | |
if (element.checked != element.defaultChecked) { | |
return true; | |
} | |
} else if (type == "hidden" || type == "password" || |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 根据元素的值移除数组元素中的值 | |
function removeByValue(arr, val) { | |
for (var i = 0; i < arr.length; i++) { | |
if (arr[i] == val) { | |
arr.splice(i, 1); | |
break; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 整站变灰 */ | |
* { | |
filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); | |
-webkit-filter: grayscale(100%); | |
-moz-filter: grayscale(100%); | |
-ms-filter: grayscale(100%); | |
-o-filter: grayscale(100%); | |
filter: grayscale(100%); | |
filter: gray; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 滚动条下拉固定不动 | |
$(function() { | |
$(window).scroll(function() { | |
if ($(window).scrollTop() < 270) { | |
$('.stayer').removeClass('fixed'); | |
} | |
// 不给ie6效果 | |
if ($(window).scrollTop() > 270 && !($.browser.msie && $.browser.version == '6.0')) { | |
$('.stayer').addClass('fixed'); |