function getStyle(eleObj, attr) {
return eleObj.currentStyle ? eleObj.currentStyle[attr] : window.getComputedStyle(eleObj)[attr];
}
function whellEvent(ev) {
if (ev.wheelDelta) {
return ev.wheelDelta;
} else {
return ev.detail * -40;
}
}
function eventBind(eleObj, eventType, callBack, boolean) {
if (eleObj.addEventListener) {
eleObj.addEventListener(eventType, callBack, boolean);
} else {
eleObj.attachEvent('on' + eventType, callBack);
}
}
function unEventBind(eleObj, eventType, callBack) {
if (eleObj.removeEventListener) {
eleObj.removeEventListener(eventType, callBack);
} else {
eleObj.detachEvent('on' + eventType, callBack);
}
}
function move(eleObj, attr, step, target, interval) {
window.clearInterval(eleObj.timer);
step = parseFloat(getStyle(eleObj, attr)) < target ? step : -step;
eleObj.timer = window.setInterval(function () {
var speed = parseFloat(getStyle(eleObj, attr)) + step;
if ((speed >= target && step > 0) || (speed <= target && step < 0)) {
speed = target;
window.clearInterval(eleObj.timer);
}
eleObj.style[attr] = speed + 'px';
}, interval);
}
function getRandomNumber(n, m) {
n = Number(n);
m = Number(m);
if (isNaN(n) || isNaN(m)) {
throw new TypeError("請輸入數值");
}
if (n > m) {
var temp;
temp = n;
n = m;
m = temp;
}
return Math.round(Math.random() * (m - n) + n);
}
function zero(time) {
return time < 10 ? "0" + time : time;
}
function bubbleSort(arr, bool) {
var flag = false;
for (var i = 0; i < arr.length - 1; i++) {
for (var j = 0; j < arr.length - 1 - i; j++) {
if (bool ? arr[j] > arr[j + 1] : arr[j] < arr[j + 1]) {
var temp;
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
flag = true;
}
}
if (flag) {
flag = false;
} else {
break;
}
}
return arr;
}
function quickSort(arr) {
if (arr.length <= 1) {
return arr;
}
var point = Math.floor(arr.length / 2);
var pointValue = arr.splice(point, 1)[0];
var left = [],
right = [];
for (var i = 0; i < arr.length; i++) {
var cur = arr[i];
cur < pointValue ? left.push(cur) : right.push(cur);
}
return quickSort(left).concat(pointValue, quickSort(right));
}
function arrNoRepeat(arr) {
var obj = {};
for (var i = 0; i < arr.length; i++) {
var cur = arr[i];
if (obj[cur] === cur) {
arr[i] = arr[arr.length - 1];
arr.length--;
i--;
continue;
}
obj[cur] = cur;
}
return arr;
}
function getChildren(eleObj, tagName) {
var nodes = eleObj.childNodes,
arr = [];
for (var i = 0; i < nodes.length; i++) {
var curNode = nodes[i];
if (typeof tagName === "undefined") {
if (curNode.nodeType === 1) {
arr.push(curNode);
}
} else {
if ((curNode.nodeType === 1) && (curNode.nodeName.toUpperCase() === tagName.toUpperCase())) {
arr.push(curNode);
}
}
}
return arr;
}
function firtChild(eleObj) {
return getChildren(eleObj).length != 0 ? getChildren(eleObj)[0] : null;
}
function lastChild(eleObj) {
return getChildren(eleObj).length != 0 ? getChildren(eleObj)[getChildren(eleObj).length - 1] : null;
}
function prev(eleObj) {
var pre = eleObj.previousSibling;
while (pre && pre.nodeType != 1) {
pre = pre.previousSibling;
}
return pre;
}
function next(eleObj) {
var nex = eleObj.nextSibling;
while (nex && nex.nodeType != 1) {
nex = nex.nextSibling;
}
return nex;
}
function prveAll(eleObj) {
var pre = prev(eleObj);
var arr = [];
while (pre) {
arr.unshift(pre);
pre = prev(pre);
}
return arr;
}
function nextAll(eleObj) {
var nex = next(eleObj);
var arr = [];
while (nex) {
arr.push(nex);
nex = next(nex);
}
return arr;
}
function siblings(eleObj) {
var arr = [];
prev(eleObj) ? arr.push(prev(eleObj)) : null;
next(eleObj) ? arr.push(next(eleObj)) : null;
return arr;
}
function siblingsAll(eleObj) {
return prveAll(eleObj).concat(nextAll(eleObj));
}
function win(attr, value) {
if (typeof value === "undefined") {
return document.documentElement[attr] || document.body[attr];
} else {
document.documentElement[attr] = document.body[attr] = value;
}
}
function drag(eleObj){
eleObj.onmousedown=function(event){
eleObj.setCapture && eleObj.setCapture();
event = event || window.event;
var x= event.clientX - eleObj.offsetLeft;
var y = event.clientY -eleObj.offsetTop;
document.onmousemove=function(event){
event=event||window.event;
var left=event.clientX-x;
var top=event.clientY-y;
eleObj.style.left=left+'px';
eleObj.style.top=top+'px';
}
document.onmouseup=function(){
releaseCapture&&releaseCapture();
document.onmousemove=document.onmouseup=null;
}
return false;
}
}
function drag1(eleObj, eleObj1) {
var arr = [{
myLeft: parseFloat(getStyle(eleObj, 'left')), myTop: parseFloat(getStyle(eleObj, 'top'))
}];
eleObj.onmousedown = function (ev) {
ev = ev || window.event;
eleObj.setCapture && eleObj.setCapture();
var x = ev.clientX - eleObj.offsetLeft;
var y = ev.clientY - eleObj.offsetTop;
document.onmousemove = function (ev) {
ev = ev || window.event;
var left = ev.clientX - x;
var top = ev.clientY - y;
var minLeft = 0, maxLeft = win('clientWidth') - eleObj.offsetWidth;
var minTop = 0, maxTop = win('clientHeight') - eleObj.offsetHeight;
if (left <= minLeft) {
left = minLeft;
} else if (left >= maxLeft) {
left = maxLeft;
}
if (top <= minTop) {
top = minTop;
} else if (top >= maxTop) {
top = maxTop;
}
eleObj.style.left = left + 'px';
eleObj.style.top = top + 'px';
arr.push({ myLeft: left, myTop: top });
}
document.onmouseup = function () {
eleObj.releaseCapture && eleObj.releaseCapture();
document.onmousemove = document.onmouseup = null;
}
return false;
}
eleObj1.onclick = function () {
window.clearInterval(timer);
var timer = window.setInterval(function () {
var curPos = arr.pop();
if (arr.length <= 0) {
eleObj.style.left = curPos.myLeft + 'px';
eleObj.style.top = curPos.myTop + 'px';
window.clearInterval(timer);
} else {
eleObj.style.left = curPos.myLeft + 'px';
eleObj.style.top = curPos.myTop + 'px';
}
}, 20);
}
}
function deMove(eleObj, attr, target, interval){
window.clearInterval(eleObj.timer);
eleObj.timer=window.setInterval(function(){
var cur=parseFloat(getStyle(eleObj,attr));
var speed=(target-cur)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(cur===target){
clearInterval(eleObj.timer);
}
eleObj.style[attr]=cur+speed+'px';
},interval);
}
function bufferMove(eleObj, styleObj, interval, callBack) {
window.clearInterval(eleObj.timer);
console.log("buffferMove")
eleObj.timer = window.setInterval(function () {
console.log("444")
var flag = true;
for (var styleAttr in styleObj) {
var cur = styleAttr === "opacity" ? parseFloat(getStyle(eleObj, styleAttr) * 100) :
parseFloat(
getStyle(
eleObj, styleAttr));
var speed = (styleObj[styleAttr] - cur) / 10;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if (cur !== styleObj[styleAttr]) {
flag = false;
}
if (styleAttr === "opacity") {
eleObj.style.opacity = (cur + speed) / 100;
eleObj.style.filter = "alpha(opacity=" + (cur + speed) + ")";
} else {
eleObj.style[styleAttr] = (cur + speed) + 'px';
}
}
if (flag) {
window.clearInterval(eleObj.timer);
console.log('5555');
callBack && callBack();
}
}, interval);
}