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 code = '2'; | |
var name; | |
if (code === '2') { | |
name = '张三'; | |
} else if (code === '3') { | |
name = '李四'; | |
} else if (code === '4') { | |
name = '王五'; |
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
<body class="preload"> | |
.preload * { | |
-webkit-transition: none !important; | |
-moz-transition: none !important; | |
-ms-transition: none !important; | |
-o-transition: none !important; | |
} | |
$("window").load(function() { | |
$("body").removeClass("preload"); | |
}); |
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 interval; | |
$('div').mousedown(mouseState).mouseup(mouseState); | |
function mouseState(e) { | |
if (e.type == "mouseup") { | |
clearInterval(interval); | |
} | |
if (e.type == "mousedown") { | |
//code triggers on hold |
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 delaySetClass(elementId, delayTime, classToAdd, classToRemove, callback) { | |
var element = document.getElementById(elementId); | |
if (element == null) { | |
console.log(elementId + 'does not exit!'); | |
return; | |
} | |
var delayTimeout = setTimeout(function() { | |
var oldClassName = element.className, |
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 addEvent = window.attachEvent||window.addEventListener; | |
var event = window.attachEvent ? 'onclick' : 'click'; | |
addEvent(event, function(){ | |
alert('Hello!') | |
}); | |
// another | |
if (!someElement.addEventListener) { | |
_checkbox.attachEvent("onclick", setCheckedValues); |
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
.Center-Container.is-Inline { | |
text-align: center; | |
width: 100%; | |
height: 100%; | |
position: absolute; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
font-size: 0; |
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 isRetina = function(){ | |
var mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\ | |
(min--moz-device-pixel-ratio: 1.5),\ | |
(-o-min-device-pixel-ratio: 3/2),\ | |
(min-resolution: 1.5dppx)"; | |
if (window.devicePixelRatio > 1) | |
return true; | |
if (window.matchMedia && window.matchMedia(mediaQuery).matches) |
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
/** | |
* 播放序列帧图片 | |
* @param {string} elementId 元素id | |
* @param {number} playTime 播放时间/ms | |
* @param {number} totalSpriteHeight 序列帧图片高度/px | |
* @param {number} startFrame 播放开始帧数(0为空白帧) | |
* @param {number} endFrame 播放结束帧数(总帧数+1为空白帧) | |
* @return {null} 没有返回值 | |
*/ | |
function playSpriteAni(elementId, playTime, totalSpriteHeight, startFrame, endFrame) { |
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
$.fn.stopAnimte = function() { | |
var endEvent = $.fx.transitionEnd; | |
this.css('transition', 'none').unbind(endEvent); | |
return this; | |
} |
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 current = window.getComputedStyle || window.currentStyle; | |
xxx.current(prop); |