Skip to content

Instantly share code, notes, and snippets.

View hacke2's full-sized avatar
🐜
ant has power

hacke2 hacke2

🐜
ant has power
View GitHub Profile
@hacke2
hacke2 / animate.js
Created August 25, 2014 13:48
从左上角弹出
$box.animate({
width: this.mWidth "px",
height: this.mHeight "px",
"left": browserWidth / 2 - this.mWidth / 2 "px",
"top": browserHeight / 2 - this.mHeight / 2 "px"
}, 300);
@hacke2
hacke2 / randomMN.js
Created August 25, 2014 13:48
m-n的随机数
parseInt(Math.random())*(n-m)+m;
@hacke2
hacke2 / htmlEscape.js
Created August 25, 2014 13:47
处理一些文本里的HTML标签
function htmlEscape(text) {
return text.replace(/[<>"&]/g, function(match, pos, originalText){
switch(match) {
case "<" : return "&lt;";
case ">" : return "&gt;";
case "\"" : return "&amp;";
case "&" : return "&quot;";
}
});
}
@hacke2
hacke2 / drag.js
Created August 25, 2014 13:47
拖拽
var drag = document.getElementById('drag');
var inputX = document.getElementById('x');
var inputY = document.getElementById('y');
if(document.attachEvent){
drag.attachEvent('onmousedown',dragHandle);
}else{
drag.addEventListener('mousedown', dragHandle,false);
}
function dragHandle(event){
var event = event||window.event;