Skip to content

Instantly share code, notes, and snippets.

View shuizhongyueming's full-sized avatar
🎯
Focusing

happy wang shuizhongyueming

🎯
Focusing
View GitHub Profile
@shuizhongyueming
shuizhongyueming / pfv.js
Created April 16, 2023 11:29
analytics execution time for code block
/**
# Usages:
pfv.start('some');
// some code
// some code
pfv.end();
pfv.check('ff', () => {
// some code
@shuizhongyueming
shuizhongyueming / javascript-for-statement
Last active December 17, 2018 04:49
simple achievement of javascript for statement
function forFunc(curr, compare, changer, actions) {
if (compare(curr)) {
actions(curr);
return forFunc(changer(curr), compare, changer, actions);
}
}
function iterateArr(arr, actions) {
forFunc(0, i => i < arr.length, i => i+1, i => actions(arr[i], i));
}
@shuizhongyueming
shuizhongyueming / fixedInIe6.css
Created September 9, 2013 11:53
修复IE6不支持fixed的问题,用css表达式来实现
/*让position:fixed在IE6下可用! */
 
.fixed-top /* 头部固定 */{position:fixed;bottom:auto;top:0px;}
.fixed-bottom /* 底部固定 */{position:fixed;bottom:0px;top:auto;}
.fixed-left /* 左侧固定 */{position:fixed;right:auto;left:0px;}
.fixed-right /* 右侧固定 */{position:fixed;right:0px;left:auto;}
/* 上面的是除了IE6的主流浏览器通用的方法 */
* html,* html body /* 修正IE6振动bug */{background-image:url(about:blank);background-attachment:fixed;}
* html .fixed-top /* IE6 头部固定 */{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop));}
* html .fixed-right /* IE6 右侧固定 */ {position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-(parseInt(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));}
@shuizhongyueming
shuizhongyueming / FlashSatay.html
Created August 27, 2013 05:00
From http://alistapart.com/article/flashsatay 一个比较通用的在页面中加载flash的方式,用的是object标签。但是考虑到现在html5的日渐普及,这种方式在日后的可用性还是有待商榷
<object type="application/x-shockwave-flash"
data="c.swf?path=movie.swf"
width="400" height="300">
</object>
@shuizhongyueming
shuizhongyueming / checkMail.js
Created May 10, 2013 17:25
JavaScript: Util checkMail
/**
* [checkMail 验证用户输入的邮箱格式是否正确]
* @param {[string]} mailStr [已经去除两边空白的邮箱地址]
* @return {[int]} [0,合法;1,不合法]
*/
function checkMail(mailStr){//验证邮箱格式
if(mailStr.match(/^[\w-]+@[\w-]+((\.[\w-]{2,3}){1,2})$/gi)){return 0;}
else{return 1;}
}
@shuizhongyueming
shuizhongyueming / trimSpace.js
Created May 10, 2013 17:25
JavaScript: Util trimSpace
/**
* [trimSpace 去除转入字符串两边的空白并返回新的字符串]
* @param {[string]} str [需要处理的字符串]
* @return {[string]} [处理之后的字符串]
*/
function trimSpace(str){//去除字符串两端的空白字符
return str.replace(/^\s*|\s*$/g,'');
}
@shuizhongyueming
shuizhongyueming / checkNull.js
Created May 10, 2013 17:24
JavaScript: Util checkNull
/**
* [checkNull 查看函数是否为空或者只有空格]
* @param {[string]} str [要验证的字符串]
* @return {[int]} [0,为空;1,不为空]
*/
function checkNull(str){//,是,则return 0
if(str.match(/^\s*$/g)){return 0;}
else{return 1;}
}
@shuizhongyueming
shuizhongyueming / disorderArr.js
Created May 10, 2013 17:12
JavaScript: Util disorderArr
/**
* @name disorderArr
* @description 乱序排列数组
* @param arr Array 要乱序排列的数组
* @return Array 乱序排列后的数组
* @author 水中月明(shuizhongyueming@gmail.com)
*/
function disorderArr(arr){
var copyArr = [],len = arr.length,i = 0,disorderedArr = [],randomVal;
for(i;i<len;i++){
@shuizhongyueming
shuizhongyueming / quickSort.js
Created May 10, 2013 17:09
JavaScript: Util quickSort
/*
* @name quickSort
* @description 针对数组进行快速排序
* @param arr Array 要排序的数组
* @param type String 排序的方式 desc 降序
* @notice 目前只实现了降序排序
* @author 水中月明(shuizhongyueming@gmail.com)
*/
function quickSort(arr,type){
var len = arr.length,
@shuizhongyueming
shuizhongyueming / AddFavorite.js
Created May 10, 2013 16:54
JavaScript: Util AddFavorite
function AddFavorite(sURL, sTitle) {
try {
window.external.addFavorite(sURL, sTitle);
}
catch (e) {
try {
window.sidebar.addPanel(sTitle, sURL, "");
}catch (e) {
alert("加入收藏失败,请使用Ctrl+D进行添加");
}