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

scrollPic.js 8.8 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. var sina = {
  2. $ : function (objName) {
  3. if (document.getElementById) {
  4. return eval('document.getElementById("' + objName + '")')
  5. } else {
  6. return eval('document.all.' + objName)
  7. }
  8. },
  9. isIE : navigator.appVersion.indexOf("MSIE") != -1 ? true : false,
  10. addEvent : function (l, i, I) {
  11. if (l.attachEvent) {
  12. l.attachEvent("on" + i, I)
  13. } else {
  14. l.addEventListener(i, I, false)
  15. }
  16. },
  17. delEvent : function (l, i, I) {
  18. if (l.detachEvent) {
  19. l.detachEvent("on" + i, I)
  20. } else {
  21. l.removeEventListener(i, I, false)
  22. }
  23. },
  24. readCookie : function (O) {
  25. var o = "",
  26. l = O + "=";
  27. if (document.cookie.length > 0) {
  28. var i = document.cookie.indexOf(l);
  29. if (i != -1) {
  30. i += l.length;
  31. var I = document.cookie.indexOf(";", i);
  32. if (I == -1)
  33. I = document.cookie.length;
  34. o = unescape(document.cookie.substring(i, I))
  35. }
  36. };
  37. return o
  38. },
  39. writeCookie : function (i, l, o, c) {
  40. var O = "",
  41. I = "";
  42. if (o != null) {
  43. O = new Date((new Date).getTime() + o * 3600000);
  44. O = "; expires=" + O.toGMTString()
  45. };
  46. if (c != null) {
  47. I = ";domain=" + c
  48. };
  49. document.cookie = i + "=" + escape(l) + O + I
  50. },
  51. readStyle : function (I, l) {
  52. if (I.style[l]) {
  53. return I.style[l]
  54. } else if (I.currentStyle) {
  55. return I.currentStyle[l]
  56. } else if (document.defaultView && document.defaultView.getComputedStyle) {
  57. var i = document.defaultView.getComputedStyle(I, null);
  58. return i.getPropertyValue(l)
  59. } else {
  60. return null
  61. }
  62. }
  63. };
  64. //滚动图片构造函数
  65. //UI&UE Dept. mengjia
  66. //080623
  67. function ScrollPic(scrollContId, arrLeftId, arrRightId, dotListId) {
  68. this.scrollContId = scrollContId;
  69. this.arrLeftId = arrLeftId;
  70. this.arrRightId = arrRightId;
  71. this.dotListId = dotListId;
  72. this.dotClassName = "dotItem";
  73. this.dotOnClassName = "dotItemOn";
  74. this.dotObjArr = [];
  75. this.pageWidth = 0;
  76. this.frameWidth = 0;
  77. this.speed = 10;
  78. this.space = 10;
  79. this.pageIndex = 0;
  80. this.autoPlay = true;
  81. this.autoPlayTime = 5;
  82. var _autoTimeObj,
  83. _scrollTimeObj,
  84. _state = "ready";
  85. this.stripDiv = document.createElement("DIV");
  86. this.listDiv01 = document.createElement("DIV");
  87. this.listDiv02 = document.createElement("DIV");
  88. if (!ScrollPic.childs) {
  89. ScrollPic.childs = []
  90. };
  91. this.ID = ScrollPic.childs.length;
  92. ScrollPic.childs.push(this);
  93. this.initialize = function () {
  94. if (!this.scrollContId) {
  95. throw new Error("必须指定scrollContId.");
  96. return
  97. };
  98. this.scrollContDiv = sina.$(this.scrollContId);
  99. if (!this.scrollContDiv) {
  100. throw new Error("scrollContId不是正确的对象.(scrollContId = \"" + this.scrollContId + "\")");
  101. return
  102. };
  103. this.scrollContDiv.style.width = this.frameWidth + "px";
  104. this.scrollContDiv.style.overflow = "hidden";
  105. this.listDiv01.innerHTML = this.listDiv02.innerHTML = this.scrollContDiv.innerHTML;
  106. this.scrollContDiv.innerHTML = "";
  107. this.scrollContDiv.appendChild(this.stripDiv);
  108. this.stripDiv.appendChild(this.listDiv01);
  109. this.stripDiv.appendChild(this.listDiv02);
  110. this.stripDiv.style.overflow = "hidden";
  111. this.stripDiv.style.zoom = "1";
  112. this.stripDiv.style.width = "32766px";
  113. if(-[1,]){
  114. this.listDiv01.style.cssFloat = "left";
  115. this.listDiv02.style.cssFloat = "left";
  116. }else{
  117. this.listDiv01.style.styleFloat = "left";
  118. this.listDiv02.style.styleFloat = "left";
  119. }
  120. sina.addEvent(this.scrollContDiv, "mouseover", Function("ScrollPic.childs[" + this.ID + "].stop()"));
  121. sina.addEvent(this.scrollContDiv, "mouseout", Function("ScrollPic.childs[" + this.ID + "].play()"));
  122. if (this.arrLeftId) {
  123. this.arrLeftObj = sina.$(this.arrLeftId);
  124. if (this.arrLeftObj) {
  125. sina.addEvent(this.arrLeftObj, "mousedown", Function("ScrollPic.childs[" + this.ID + "].rightMouseDown()"));
  126. sina.addEvent(this.arrLeftObj, "mouseup", Function("ScrollPic.childs[" + this.ID + "].rightEnd()"));
  127. sina.addEvent(this.arrLeftObj, "mouseout", Function("ScrollPic.childs[" + this.ID + "].rightEnd()"))
  128. }
  129. };
  130. if (this.arrRightId) {
  131. this.arrRightObj = sina.$(this.arrRightId);
  132. if (this.arrRightObj) {
  133. sina.addEvent(this.arrRightObj, "mousedown", Function("ScrollPic.childs[" + this.ID + "].leftMouseDown()"));
  134. sina.addEvent(this.arrRightObj, "mouseup", Function("ScrollPic.childs[" + this.ID + "].leftEnd()"));
  135. sina.addEvent(this.arrRightObj, "mouseout", Function("ScrollPic.childs[" + this.ID + "].leftEnd()"))
  136. }
  137. };
  138. if (this.dotListId) {
  139. this.dotListObj = sina.$(this.dotListId);
  140. if (this.dotListObj) {
  141. var pages = Math.round(this.listDiv01.offsetWidth / this.frameWidth + 0.4),
  142. i,
  143. tempObj;
  144. for (i = 0; i < pages; i++) {
  145. tempObj = document.createElement("span");
  146. this.dotListObj.appendChild(tempObj);
  147. this.dotObjArr.push(tempObj);
  148. if (i == this.pageIndex) {
  149. tempObj.className = this.dotClassName
  150. } else {
  151. tempObj.className = this.dotOnClassName
  152. };
  153. tempObj.title = "第" + (i + 1) + "页";
  154. sina.addEvent(tempObj, "click", Function("ScrollPic.childs[" + this.ID + "].pageTo(" + i + ")"))
  155. }
  156. }
  157. };
  158. if (this.autoPlay) {
  159. this.play()
  160. }
  161. };
  162. this.leftMouseDown = function () {
  163. if (_state != "ready") {
  164. return
  165. };
  166. _state = "floating";
  167. _scrollTimeObj = setInterval("ScrollPic.childs[" + this.ID + "].moveLeft()", this.speed)
  168. };
  169. this.rightMouseDown = function () {
  170. if (_state != "ready") {
  171. return
  172. };
  173. _state = "floating";
  174. _scrollTimeObj = setInterval("ScrollPic.childs[" + this.ID + "].moveRight()", this.speed)
  175. };
  176. this.moveLeft = function () {
  177. if (this.scrollContDiv.scrollLeft + this.space >= this.listDiv01.scrollWidth) {
  178. this.scrollContDiv.scrollLeft = this.scrollContDiv.scrollLeft + this.space - this.listDiv01.scrollWidth
  179. } else {
  180. this.scrollContDiv.scrollLeft += this.space
  181. };
  182. this.accountPageIndex()
  183. };
  184. this.moveRight = function () {
  185. if (this.scrollContDiv.scrollLeft - this.space <= 0) {
  186. this.scrollContDiv.scrollLeft = this.listDiv01.scrollWidth + this.scrollContDiv.scrollLeft - this.space
  187. } else {
  188. this.scrollContDiv.scrollLeft -= this.space
  189. };
  190. this.accountPageIndex()
  191. };
  192. this.leftEnd = function () {
  193. if (_state != "floating") {
  194. return
  195. };
  196. _state = "stoping";
  197. clearInterval(_scrollTimeObj);
  198. var fill = this.pageWidth - this.scrollContDiv.scrollLeft % this.pageWidth;
  199. this.move(fill)
  200. };
  201. this.rightEnd = function () {
  202. if (_state != "floating") {
  203. return
  204. };
  205. _state = "stoping";
  206. clearInterval(_scrollTimeObj);
  207. var fill = -this.scrollContDiv.scrollLeft % this.pageWidth;
  208. this.move(fill)
  209. };
  210. this.move = function (num, quick) {
  211. var thisMove = num / 5;
  212. if (!quick) {
  213. if (thisMove > this.space) {
  214. thisMove = this.space
  215. };
  216. if (thisMove < -this.space) {
  217. thisMove = -this.space
  218. }
  219. };
  220. if (Math.abs(thisMove) < 1 && thisMove != 0) {
  221. thisMove = thisMove >= 0 ? 1 : -1
  222. } else {
  223. thisMove = Math.round(thisMove)
  224. };
  225. var temp = this.scrollContDiv.scrollLeft + thisMove;
  226. if (thisMove > 0) {
  227. if (this.scrollContDiv.scrollLeft + thisMove >= this.listDiv01.scrollWidth) {
  228. this.scrollContDiv.scrollLeft = this.scrollContDiv.scrollLeft + thisMove - this.listDiv01.scrollWidth
  229. } else {
  230. this.scrollContDiv.scrollLeft += thisMove
  231. }
  232. } else {
  233. if (this.scrollContDiv.scrollLeft - thisMove <= 0) {
  234. this.scrollContDiv.scrollLeft = this.listDiv01.scrollWidth + this.scrollContDiv.scrollLeft - thisMove
  235. } else {
  236. this.scrollContDiv.scrollLeft += thisMove
  237. }
  238. };
  239. num -= thisMove;
  240. if (Math.abs(num) == 0) {
  241. _state = "ready";
  242. if (this.autoPlay) {
  243. this.play()
  244. };
  245. this.accountPageIndex();
  246. return
  247. } else {
  248. this.accountPageIndex();
  249. setTimeout("ScrollPic.childs[" + this.ID + "].move(" + num + "," + quick + ")", this.speed)
  250. }
  251. };
  252. this.next = function () {
  253. if (_state != "ready") {
  254. return
  255. };
  256. _state = "stoping";
  257. this.move(this.pageWidth, true)
  258. };
  259. this.play = function () {
  260. if (!this.autoPlay) {
  261. return
  262. };
  263. clearInterval(_autoTimeObj);
  264. _autoTimeObj = setInterval("ScrollPic.childs[" + this.ID + "].next()", this.autoPlayTime * 1000)
  265. };
  266. this.stop = function () {
  267. clearInterval(_autoTimeObj)
  268. };
  269. this.pageTo = function (num) {
  270. if (_state != "ready") {
  271. return
  272. };
  273. _state = "stoping";
  274. var fill = num * this.frameWidth - this.scrollContDiv.scrollLeft;
  275. this.move(fill, true)
  276. };
  277. this.accountPageIndex = function () {
  278. this.pageIndex = Math.round(this.scrollContDiv.scrollLeft / this.frameWidth);
  279. if (this.pageIndex > Math.round(this.listDiv01.offsetWidth / this.frameWidth + 0.4) - 1) {
  280. this.pageIndex = 0
  281. };
  282. var i;
  283. for (i = 0; i < this.dotObjArr.length; i++) {
  284. if (i == this.pageIndex) {
  285. this.dotObjArr[i].className = this.dotClassName
  286. } else {
  287. this.dotObjArr[i].className = this.dotOnClassName
  288. }
  289. }
  290. }
  291. };

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...