You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

445 lines
16 KiB

  1. function rgb_color(){//����rgbɫ���ɺ���������ֵΪrgb��ɫ�ַ���
  2. var r=parseInt(Math.random()*255);
  3. var g=parseInt(Math.random()*255);
  4. var b=parseInt(Math.random()*255);
  5. var newcolor="rgb("+r+","+g+","+b+")";
  6. return newcolor;
  7. }
  8. function rgba_color(){//����rgbaɫ���ɺ���������ֵΪrgba��ɫ�ַ���
  9. var r=parseInt(Math.random()*255);
  10. var g=parseInt(Math.random()*255);
  11. var b=parseInt(Math.random()*255);
  12. var a=Math.random();
  13. var newcolor="rgba("+r+","+g+","+b+","+a+")";
  14. return newcolor;
  15. }
  16. function getbyclass(parent,classname){//ͨ��������ȡԪ�غ���������Ϊ��Ԫ�ء�����������ֵΪԪ������
  17. var result=new Array();
  18. var allclass=parent.getElementsByTagName('*');
  19. for (var i=0; i<allclass.length;i++ )
  20. {
  21. if(classname==allclass[i].className)
  22. result.push(allclass[i]);
  23. }
  24. return result;
  25. }
  26. function getbyclassname(tagname,classname){//ͨ��������ȡԪ�غ���������Ϊ��ǩ��������������ֵΪԪ������
  27. var result=new Array();
  28. var allclass=document.getElementsByTagName(tagname);
  29. for (var i=0; i<allclass.length;i++ )
  30. {
  31. if(classname==allclass[i].className)
  32. result.push(allclass[i]);
  33. }
  34. return result;
  35. }
  36. function index(current, obj)
  37. { //��ȡԪ������ֵ
  38. for (var i = 0; i < obj.length; i++)
  39. {
  40. if (obj[i] == current)
  41. {
  42. return i;
  43. }
  44. }
  45. }
  46. function win(attr)
  47. {//��ȡ�������ߴ磬����Ϊheight|width
  48. switch(attr)
  49. {
  50. case 'height'://��ȡ���ڸ߶�
  51. if (window.innerHeight)
  52. {
  53. winHeight = window.innerHeight;return winHeight;
  54. }else if ((document.body) && (document.body.clientHeight)){
  55. winHeight = document.body.clientHeight;return winHeight;
  56. }
  57. if (document.documentElement && document.documentElement.clientHeight)
  58. {
  59. winHeight = document.documentElement.clientHeight;return winHeight;
  60. }
  61. break;
  62. case 'width'://��ȡ���ڿ���
  63. if (window.innerWidth){
  64. winWidth = window.innerWidth;return winWidth;
  65. }else if ((document.body) && (document.body.clientWidth)){
  66. winWidth = document.body.clientWidth; return winWidth;
  67. }//ͨ������Document�ڲ���body���м��⣬��ȡ���ڴ�С
  68. if (document.documentElement &&document.documentElement.clientWidth)
  69. {
  70. winWidth = document.documentElement.clientWidth;return winWidth;
  71. }
  72. break;
  73. case 'scrollTop':
  74. var scrollTop;
  75. if(typeof window.pageYOffset != 'undefined'){
  76. scrollTop = window.pageYOffset;
  77. }
  78. else
  79. if(typeof document.compatMode != 'undefined' &&
  80. document.compatMode != 'BackCompat'){
  81. scrollTop = document.documentElement.scrollTop;
  82. }
  83. else
  84. if(typeof document.body != 'undefined'){
  85. scrollTop = document.body.scrollTop;
  86. }
  87. return scrollTop;break;
  88. default :return 0;break;
  89. }
  90. }
  91. /**************************************************�˶�����*****************************************************/
  92. function css(obj, attr, value)
  93. {
  94. var re=[];
  95. if(arguments.length==2)
  96. {
  97. switch(attr){
  98. case 'opacity':re.push(Math.round(100*parseFloat(obj.currentStyle?obj.currentStyle[attr]:document.defaultView.getComputedStyle(obj, false)[attr])));return re;break;
  99. case 'backgroundPosition':var res=obj.currentStyle?obj.currentStyle[attr]:document.defaultView.getComputedStyle(obj, false)[attr];res=res.split(" ");res[0]=parseInt(res[0]);res[1]=parseInt(res[1]);return res;break;
  100. case 'rotate':var transformstr=obj.currentStyle?obj.currentStyle['transform']:document.defaultView.getComputedStyle(obj, false)['webkitTransform']||document.defaultView.getComputedStyle(obj, false)['msTransform']||document.defaultView.getComputedStyle(obj, false)['MozTransform']||document.defaultView.getComputedStyle(obj, false)['OTransform']||document.defaultView.getComputedStyle(obj, false)['transform']+"";
  101. var matrixarray=transformstr.split(",");
  102. re.push(Math.ceil(Math.acos(matrixarray[3])/Math.PI*180));return re;break;
  103. case 'translate':
  104. var transformstr=obj.currentStyle?obj.currentStyle['transform']:document.defaultView.getComputedStyle(obj, false)['webkitTransform']||document.defaultView.getComputedStyle(obj, false)['msTransform']||document.defaultView.getComputedStyle(obj, false)['MozTransform']||document.defaultView.getComputedStyle(obj, false)['OTransform']||document.defaultView.getComputedStyle(obj, false)['transform']+"";
  105. var matrixarray=transformstr.split(",");
  106. re.push(parseInt(matrixarray[4]));re.push(parseInt(matrixarray[5]));return re;break;
  107. case 'translateX'://transform 2dת���е�translateX
  108. var transformstr=obj.currentStyle?obj.currentStyle['transform']:document.defaultView.getComputedStyle(obj, false)['webkitTransform']||document.defaultView.getComputedStyle(obj, false)['msTransform']||document.defaultView.getComputedStyle(obj, false)['MozTransform']||document.defaultView.getComputedStyle(obj, false)['OTransform']||document.defaultView.getComputedStyle(obj, false)['transform']+"";
  109. var matrixarray=transformstr.split(",");
  110. re.push((parseInt(matrixarray[4])));return re;break;
  111. case 'translateY'://transform 2dת���е�translateY
  112. var transformstr=obj.currentStyle?obj.currentStyle['transform']:document.defaultView.getComputedStyle(obj, false)['webkitTransform']||document.defaultView.getComputedStyle(obj, false)['msTransform']||document.defaultView.getComputedStyle(obj, false)['MozTransform']||document.defaultView.getComputedStyle(obj, false)['OTransform']||document.defaultView.getComputedStyle(obj, false)['transform']+"";
  113. var matrixarray=transformstr.split(",");
  114. re.push((parseInt(matrixarray[5])));return re;break;
  115. case 'transform'://transform 2d matrix����
  116. var transformstr=obj.currentStyle?obj.currentStyle['transform']:document.defaultView.getComputedStyle(obj, false)['webkitTransform']||document.defaultView.getComputedStyle(obj, false)['msTransform']||document.defaultView.getComputedStyle(obj, false)['MozTransform']||document.defaultView.getComputedStyle(obj, false)['OTransform']||document.defaultView.getComputedStyle(obj, false)['transform']+"";
  117. var matrixarray=transformstr.split(",");
  118. re.push(parseInt(matrixarray[0].match(/-?\d+(\.\d+)?/g)[0]*10000));//����������һ���ַ����е�����
  119. re.push(parseInt(matrixarray[1].match(/-?\d+(\.\d+)?/g)[0]*10000));
  120. re.push(parseInt(matrixarray[2].match(/-?\d+(\.\d+)?/g)[0]*10000));
  121. re.push(parseInt(matrixarray[3].match(/-?\d+(\.\d+)?/g)[0]*10000));
  122. re.push(parseInt(matrixarray[4].match(/-?\d+(\.\d+)?/g)[0]*10000));
  123. re.push(parseInt(matrixarray[5].match(/-?\d+(\.\d+)?/g)[0]*10000));
  124. // console.log(parseInt(matrixarray[0].match(/-?\d+(\.\d+)?/g)[0]*10000)+" "+
  125. // parseInt(matrixarray[1].match(/-?\d+(\.\d+)?/g)[0]*10000)+" "+
  126. // parseInt(matrixarray[2].match(/-?\d+(\.\d+)?/g)[0]*10000)+" "+
  127. // parseInt(matrixarray[3].match(/-?\d+(\.\d+)?/g)[0]*10000)+" "+
  128. // parseInt(matrixarray[4].match(/-?\d+(\.\d+)?/g)[0]*10000)+" "+
  129. // parseInt(matrixarray[5].match(/-?\d+(\.\d+)?/g)[0]*10000));
  130. return re;break;
  131. default :
  132. re.push(parseInt(obj.currentStyle?obj.currentStyle[attr]:document.defaultView.getComputedStyle(obj, false)[attr]));return re;break;
  133. }
  134. }
  135. else if(arguments.length==3)
  136. switch(attr)
  137. {
  138. case 'width':
  139. case 'height':
  140. case 'paddingLeft':
  141. case 'paddingTop':
  142. case 'paddingRight':
  143. case 'paddingBottom':
  144. value[0]=Math.max(value[0],0);
  145. case 'left':
  146. case 'top':
  147. case 'marginLeft':
  148. case 'marginTop':
  149. case 'marginRight':
  150. case 'marginBottom':
  151. obj.style[attr]=value[0]+'px';
  152. break;
  153. case 'opacity':
  154. obj.style.filter="alpha(opacity:"+value[0]+")";
  155. obj.style.opacity=value[0]/100;
  156. break;
  157. case 'backgroundPosition':
  158. obj.style.backgroundPosition=value[0]+'px '+value[1]+'px';break;
  159. case 'rotate':
  160. obj.style.webkitTransform="rotate(" + value[0]+ "deg)";
  161. obj.style.msTransform="rotate(" + value[0]+ "deg)";
  162. obj.style.MozTransform="rotate(" + value[0] + "deg)";
  163. obj.style.OTransform="rotate(" + value[0]+ "deg)";
  164. obj.style.transform="rotate(" + value[0] + "deg)";
  165. break;
  166. case 'translate':
  167. obj.style.webkitTransform="translate(" + value[0] + "px,"+value[1]+"px)";
  168. obj.style.msTransform="translate(" + value[0] + "px,"+value[1]+"px)";
  169. obj.style.MozTransform="translate(" + value[0] + "px,"+value[1]+"px)";
  170. obj.style.OTransform="translate(" + value[0] + "px,"+value[1]+"px)";
  171. obj.style.transform="translate(" + value[0] + "px,"+value[1]+"px)";
  172. break;
  173. case 'translateX':obj.style.webkitTransform="translateX(" + value[0] + "px)";
  174. obj.style.msTransform="translateX(" + value[0] + "px)";
  175. obj.style.MozTransform="translateX(" + value[0] + "px)";
  176. obj.style.OTransform="translateX(" + value[0] + "px)";
  177. obj.style.transform="translateX(" + value[0] + "px)";
  178. break;
  179. case 'translateY':obj.style.webkitTransform="translateY(" + value[0] + "px)";
  180. obj.style.msTransform="translateY(" + value[0] + "px)";
  181. obj.style.MozTransform="translateY(" + value[0] + "px)";
  182. obj.style.OTransform="translateY(" + value[0] + "px)";
  183. obj.style.transform="translateY(" + value[0] + "px)";
  184. break;
  185. case 'transform':obj.style.webkitTransform="matrix(" + value[0] + ","+value[1] + ","+value[2] + ","+value[3] + ","+value[4] + ","+value[5] +")";
  186. obj.style.msTransform="matrix(" + value[0] + ","+value[1] + ","+value[2] + ","+value[3] + ","+value[4] + ","+value[5] +")";
  187. obj.style.MozTransform="matrix(" + value[0] + ","+value[1] + ","+value[2] + ","+value[3] + ","+value[4] + ","+value[5] +")";
  188. obj.style.OTransform="matrix(" + value[0] + ","+value[1] + ","+value[2] + ","+value[3] + ","+value[4] + ","+value[5] +")";
  189. obj.style.transform="matrix(" + value[0] + ","+value[1] + ","+value[2] + ","+value[3] + ","+value[4] + ","+value[5] +")";
  190. break;
  191. default:
  192. obj.style[attr]=value[0];
  193. }
  194. return function (attr_in, value_in){css(obj, attr_in, value_in)};
  195. }
  196. function stop(obj)
  197. {
  198. clearInterval(obj.timer);
  199. }
  200. function move(obj, oTarget, iType, fnCallBack, fnDuring)
  201. {
  202. var fnMove=null;
  203. if(obj.timer)
  204. {
  205. clearInterval(obj.timer);
  206. }
  207. switch(iType)
  208. {
  209. case "buffer":
  210. fnMove=do_buffer_move;
  211. break;
  212. case "flex":
  213. fnMove=do_flex_move;
  214. break;
  215. default:
  216. fnMove=do_buffer_move;
  217. break;
  218. }
  219. obj.timer=setInterval(function (){
  220. fnMove(obj, oTarget, fnCallBack, fnDuring);
  221. }, 30);
  222. }
  223. /*------------------------------------�˶������е�ȫ�ֱ���-------------------------------------------*/
  224. var attr='';
  225. var next=[];
  226. var cur;
  227. var stopBtn=false;
  228. function do_buffer_move(obj, oTarget, fnCallBack, fnDuring)
  229. {
  230. stopBtn=false;var count=0;
  231. if(!obj.speed)obj.speed={};//�ö������ٶ����ԣ�������������ֵ�ٶȣ�����δ����������
  232. for(attr in oTarget)
  233. {
  234. if(!obj.speed[attr]){obj.speed[attr]=[];}//�ö�����ijһ���Ե��ٶ�ֵ��ֵΪ�����Ե��ٶ�ֵ������
  235. cur=css(obj, attr);
  236. if (attr=='transform')
  237. {
  238. for (var j=0;j<cur.length ;j++)
  239. {
  240. if(undefined==obj.speed[attr][j])obj.speed[attr][j]=0;//�ڸö���Ŀǰ�������У���ijһ�ٶȲ���δ���壬������
  241. var temp=parseInt(oTarget[attr][j]*10000);
  242. if(Math.abs(temp-cur[j])>1000)//����С���������ԣ��޷���֤����һ�£�������Сʱ���Բ���
  243. {
  244. obj.speed[attr][j]=(temp-cur[j])/5;
  245. obj.speed[attr][j]=obj.speed[attr][j]>0?Math.ceil(obj.speed[attr][j]):Math.floor(obj.speed[attr][j]);
  246. next[j]=(cur[j]+obj.speed[attr][j])/10000;
  247. //console.log(j+" "+attr+" "+cur[j]+' '+obj.speed[attr][j]+' '+next[j]+' '+oTarget[attr][j]) ;//�˶������еIJ���ֵ
  248. }
  249. else{
  250. next[j]=parseInt(oTarget[attr][j]*10000)/10000;//�Ѿ�����Ŀ����ֵ����
  251. count++;//��¼�ԴﵽĿ���ĸ���
  252. //console.log(attr+"count"+count);
  253. }
  254. }
  255. }
  256. else{
  257. for (var j=0;j<cur.length ;j++)
  258. {
  259. if(undefined==obj.speed[attr][j])obj.speed[attr][j]=0;//�ڸö���Ŀǰ�������У���ijһ�ٶȲ���δ���壬������
  260. if(oTarget[attr][j]!=cur[j])
  261. {
  262. oTarget[attr][j]=parseInt(oTarget[attr][j]);
  263. obj.speed[attr][j]=(oTarget[attr][j]-cur[j])/5;
  264. obj.speed[attr][j]=obj.speed[attr][j]>0?Math.ceil(obj.speed[attr][j]):Math.floor(obj.speed[attr][j]);
  265. next[j]=cur[j]+obj.speed[attr][j];
  266. //console.log(j+" "+attr+" "+cur[j]+' '+obj.speed[attr][j]+' '+next[j]+' '+oTarget[attr][j]) ;//�˶������еIJ���ֵ
  267. }
  268. else{
  269. next[j]=oTarget[attr][j];//�Ѿ�����Ŀ����ֵ����
  270. count++;//��¼�ԴﵽĿ���ĸ���
  271. //console.log(attr+"count"+count);
  272. }
  273. }
  274. }
  275. css(obj,attr,next);
  276. }
  277. var allattr=0;//�������Լ���������
  278. for(attr in oTarget)
  279. {
  280. for (var i=0;i<oTarget[attr].length; i++)
  281. {
  282. allattr++;//�������������Ը���
  283. }
  284. }
  285. //console.log(count+" "+allattr);//�Դ��������ܸ����Ա�
  286. if(count==allattr){stopBtn=true;}//���������Զ��ﵽĿ��ʱֹͣ���ش���
  287. if(fnDuring)fnDuring.call(obj);
  288. if(stopBtn)
  289. {
  290. obj.speed={};
  291. //console.log("�����˶�����");
  292. clearInterval(obj.timer);
  293. if(fnCallBack)fnCallBack.call(obj);
  294. }
  295. }
  296. function do_flex_move(obj, oTarget, fnCallBack, fnDuring)
  297. {
  298. stopBtn=false;var count=0;//�й��Ƿ��˶��ı���
  299. if(!obj.speed)obj.speed={};//�ö������ٶ����ԣ�������������ֵ�ٶȣ�����δ����������
  300. for(attr in oTarget)
  301. {
  302. if(!obj.speed[attr]){obj.speed[attr]=[];}//�ö�����ijһ���Ե��ٶ�ֵ��ֵΪ�����Ե��ٶ�ֵ������
  303. //console.log(obj.speed[attr]);
  304. cur=css(obj, attr);
  305. if (attr=='transform')
  306. {
  307. for (var j=0;j<cur.length ;j++)
  308. {
  309. if(undefined==obj.speed[attr][j])obj.speed[attr][j]=1;//�ڸö���Ŀǰ�������У���ijһ�ٶȲ���δ���壬������
  310. var temp=parseInt(oTarget[attr][j]*10000);
  311. if(Math.abs(parseInt(obj.speed[attr][j]))!=0)
  312. {
  313. obj.speed[attr][j]+=(temp-cur[j])/5;
  314. obj.speed[attr][j]*=0.7;
  315. obj.speed[attr][j]=parseInt(obj.speed[attr][j]);
  316. next[j]=(cur[j]+obj.speed[attr][j])/10000;
  317. //console.log(j+" "+attr+" "+cur[j]+' '+obj.speed[attr][j]+' '+next[j]+' '+oTarget[attr][j]) ;//�˶������еIJ���ֵ
  318. }
  319. else
  320. {
  321. next[j]=parseInt(oTarget[attr][j]*10000)/10000;//�Ѿ�����Ŀ����ֵ����
  322. count++;//��¼�ԴﵽĿ���ĸ���
  323. //console.log(attr+"count"+count);
  324. }
  325. }
  326. }else{
  327. for (var j=0;j<cur.length ;j++)
  328. {
  329. if(undefined==obj.speed[attr][j])obj.speed[attr][j]=1;//�ڸö���Ŀǰ�������У���ijһ�ٶȲ���δ���壬������
  330. if(Math.abs(obj.speed[attr][j])!=0)
  331. {
  332. obj.speed[attr][j]+=(oTarget[attr][j]-cur[j])/5;
  333. obj.speed[attr][j]*=0.7;
  334. obj.speed[attr][j]=parseInt(obj.speed[attr][j]);
  335. next[j]=cur[j]+obj.speed[attr][j];
  336. //console.log(j+" attr "+attr+" "+cur[j]+' '+obj.speed[attr][j]+' '+next[j]+' '+oTarget[attr][j]) ;//�˶������еIJ���ֵ
  337. }
  338. else
  339. {
  340. next[j]=oTarget[attr][j];//�Ѿ�����Ŀ����ֵ����
  341. count++;//��¼�ԴﵽĿ���ĸ���
  342. //console.log(attr+"count"+count);
  343. }
  344. }
  345. }
  346. css(obj,attr,next);
  347. }
  348. var allattr=0;//�������Լ���������
  349. for(attr in oTarget)
  350. {
  351. for (var i=0;i<oTarget[attr].length; i++)
  352. {
  353. allattr++;//�������������Ը���
  354. }
  355. }
  356. //console.log(count+" "+allattr);//�Դ��������ܸ����Ա�
  357. if(count==allattr){stopBtn=true;}//���������Զ��ﵽĿ��ʱֹͣ���ش���
  358. if(fnDuring)fnDuring.call(obj);
  359. if(stopBtn)
  360. {
  361. obj.speed={};
  362. //console.log("�����˶�����");
  363. clearInterval(obj.timer);
  364. if(fnCallBack)fnCallBack.call(obj);
  365. }
  366. }
  367. function drag_throw_move(obj,speedX,speedY){//��ק+�׳��˶���ʹ��ʱ�����ȶ���timer��ʱ��������������ˮƽ�ٶȺ���ֱ�ٶ�
  368. timer=setInterval(function (){
  369. speedY+=3;//���������ƣ�y�����ٶȻ�������������������
  370. var left=obj.offsetLeft+speedX;//���㶨λֵ
  371. var top=obj.offsetTop+speedY;
  372. if (top>=(win('height')-obj.offsetHeight))//��ײ���ײ���y���ٶȷ�����x���ٶȼ�С
  373. {
  374. speedY*=-0.8;
  375. speedX*=0.8;
  376. top=(win('height')-obj.offsetHeight);
  377. }else if (top<=0)//��ײ��������y���ٶȷ�����x���ٶȼ�С
  378. {
  379. speedY*=-0.8;
  380. speedX*=0.8;
  381. top=0;
  382. }
  383. if (left>=(win('width')-obj.offsetWidth))//��ײ���Ҳ࣬X���ٶȷ����Ҽ�С
  384. {
  385. speedX*=-0.8;
  386. left=(win('width')-obj.offsetWidth);
  387. }else if (left<=0)//��ײ�����࣬X���ٶȷ����Ҽ�С
  388. {
  389. speedX*=-0.8;
  390. left=0;
  391. }
  392. if (Math.abs(speedX)<1)//�ٶȺ�Сʱ��Ϊֹͣ
  393. {
  394. speedX=0;
  395. }
  396. if (Math.abs(speedY)<1)//�ٶȺ�Сʱ��Ϊֹͣ
  397. {
  398. speedY=0;
  399. }
  400. if(speedX==0&&speedY==0&&top==(win('height')-obj.offsetHeight)){//�˶�����ֹͣ
  401. clearInterval(timer);
  402. }
  403. obj.style.left=left+'px';//Ӧ�ö�λ
  404. obj.style.top=top+'px';
  405. },30);
  406. }
  407. function drag(obj){//ʵ����ק������Ϊ����
  408. obj.onmousedown=function (ev){//��������
  409. var oev=ev||event;
  410. var disX=oev.clientX-obj.offsetLeft;
  411. var disY=oev.clientY-obj.offsetTop;
  412. document.onmousemove=function (ev){//�϶�����
  413. var oev=ev||event;
  414. var left=oev.clientX-disX;
  415. var top=oev.clientY-disY;
  416. obj.style.left=left+'px';//���¶�����λ��
  417. obj.style.top=top+'px';
  418. }
  419. document.onmouseup=function (){//̧������
  420. document.onmousemove=null;
  421. document.onmouseup=null;
  422. }
  423. }
  424. }
  425. /**************************************************�˶����ܽ���*****************************************************/