index.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. auto=null;
  2. timer=null;
  3. var focus=new Function();
  4. focus.prototype={
  5. init:function(){
  6. this.aTime=this.aTime || 10;
  7. this.sTime=this.sTime || 5000;
  8. this.oImg=document.getElementById('focus_m').getElementsByTagName("ul")[0];
  9. this.oImgLi=this.oImg.getElementsByTagName("li");
  10. this.oL=document.getElementById('focus_l');
  11. this.oR=document.getElementById('focus_r');
  12. this.createTextDom();
  13. this.target=0;
  14. this.autoMove();
  15. this.oAction();
  16. },
  17. createTextDom:function(){
  18. var that=this;
  19. this.oText=document.createElement("div");
  20. this.oText.className="focus_s";
  21. var ul=document.createElement('ul');
  22. var frag=document.createDocumentFragment();
  23. for (var i=0;i<this.oImgLi.length;i++) {
  24. var li=document.createElement("li");
  25. li.innerHTML='<b></b>';
  26. if (i==0) {
  27. li.className="active";
  28. };
  29. frag.appendChild(li);
  30. };
  31. ul.appendChild(frag);
  32. this.oText.appendChild(ul);
  33. this.o.insertBefore(this.oText,this.o.firstChild);
  34. this.oTextLi=this.oText.getElementsByTagName("li");
  35. },
  36. autoMove:function(){
  37. var that = this;
  38. auto=setInterval(function(){that.goNext()},that.sTime);
  39. },
  40. goNext:function() {
  41. this.target=this.nowIndex();
  42. this.target==this.oTextLi.length-1 ? this.target=0:this.target++;
  43. this.aStep=(this.target-this.nowIndex())*this.step;
  44. this.removeClassName();
  45. this.oTextLi[this.target].className="active";
  46. this.startMove();
  47. },
  48. goPrev:function() {
  49. this.target=this.nowIndex();
  50. this.target==0 ? this.target=this.oTextLi.length-1 : this.target--;
  51. this.aStep=(this.target-this.nowIndex())*this.step;
  52. this.removeClassName();
  53. this.oTextLi[this.target].className="active";
  54. this.startMove();
  55. },
  56. startMove:function (){
  57. var that=this;
  58. var t=0;
  59. this.timer='';
  60. function set(){
  61. if (t>100) {
  62. clearInterval(that.timer);
  63. }else {
  64. for (var i=0;i<that.oImgLi.length;i++) {
  65. that.oImgLi[i].style.display='none';
  66. };
  67. that.oImgLi[that.target].style.display='block';
  68. that.setOpacity(that.oImg,t);
  69. t+=5;
  70. };
  71. };
  72. timer=setInterval(set,that.aTime);
  73. },
  74. setOpacity:function(elem,level){
  75. if(elem.filters){
  76. elem.style.filter = 'alpha(opacity=' + level + ')';
  77. elem.style.zoom = 1;
  78. } else {
  79. elem.style.opacity = level / 100;
  80. };
  81. },
  82. nowIndex:function(){
  83. for (var i=0;i<this.oTextLi.length;i++) {
  84. if (this.oTextLi[i].className=='active') {
  85. return i;
  86. break;
  87. }
  88. };
  89. },
  90. oAction:function(){
  91. var that=this;
  92. for (var i=0;i<this.oTextLi.length;i++) {
  93. this.oTextLi[i].index=i;
  94. this.oTextLi[i].onclick=function(){
  95. clearInterval(auto);
  96. clearInterval(timer);
  97. that.setOpacity(that.oImg,100);
  98. that.target=this.index;
  99. that.removeClassName();
  100. this.className='active';
  101. that.startMove();
  102. }
  103. };
  104. mouseEnter (that.o,'mouseleave',function(e){
  105. clearInterval(auto);
  106. that.autoMove();
  107. }
  108. );
  109. //this.oL.onclick=function(){
  110. // that.goPrev();
  111. // };
  112. // this.oR.onclick=function(){
  113. // that.goNext();
  114. // };
  115. },
  116. removeClassName:function(){
  117. for (var i=0;i<this.oTextLi.length;i++) {
  118. this.oTextLi[i].className=""
  119. };
  120. }
  121. };
  122. var focusRun=new focus();
  123. focusRun.o=document.getElementById("focus");
  124. function mouseEnter(ele,type,func){
  125. if(window.document.all)
  126. ele.attachEvent('on'+type,func);
  127. else{//ff
  128. if(type==='mouseenter')
  129. ele.addEventListener('mouseover',this.withoutChildFunction(func),false);
  130. else if(type==='mouseleave')
  131. ele.addEventListener('mouseout',this.withoutChildFunction(func),false);
  132. else
  133. ele.addEventListener(type,func,false);
  134. };
  135. };
  136. function withoutChildFunction(func){
  137. return function(e){
  138. var parent=e.relatedTarget;
  139. while(parent!=this&&parent){
  140. try{
  141. parent=parent.parentNode;}
  142. catch(e){
  143. break;
  144. }
  145. }
  146. if(parent!=this)
  147. func(e);
  148. };
  149. };
  150. //重要通知
  151. //主函数
  152. var s=function(){
  153. var interv=2000; //切换间隔时间
  154. var interv2=10; //切换速度
  155. var opac1=80; //文字背景的透明度
  156. var source="show" //焦点轮换图片容器的id名称
  157. //获取对象
  158. function getTag(tag,obj){
  159. if(obj==null){
  160. return document.getElementsByTagName(tag);
  161. }else{
  162. return obj.getElementsByTagName(tag);
  163. }
  164. }
  165. function getid(id){
  166. return document.getElementById(id);
  167. };
  168. var opac=0,j=0,t=63,num,scton=0,timer,timer2,timer3;
  169. var id=getid(source);
  170. id.removeChild(getTag("div",id)[0]);
  171. var li=getTag("li",id);
  172. var div=document.createElement("div");
  173. var title=document.createElement("div");
  174. var span=document.createElement("span");
  175. var button=document.createElement("div");
  176. button.className="button";
  177. for(var i=0;i<li.length;i++){
  178. var a=document.createElement("a");
  179. a.innerHTML=i+1;
  180. a.onclick=function(){
  181. clearTimeout(timer);
  182. clearTimeout(timer2);
  183. clearTimeout(timer3);
  184. j=parseInt(this.innerHTML)-1;
  185. scton=0;
  186. t=63;
  187. opac=0;
  188. fadeon();
  189. };
  190. a.className="b1";
  191. a.onmouseover=function(){
  192. this.className="b2";
  193. };
  194. a.onmouseout=function(){
  195. this.className="b1";sc(j);
  196. };
  197. button.appendChild(a);
  198. }
  199. //控制图层透明度
  200. function alpha(obj,n){
  201. if(document.all){
  202. obj.style.filter="alpha(opacity="+n+")";
  203. }else{
  204. obj.style.opacity=(n/100);
  205. }
  206. }
  207. //控制焦点按钮
  208. function sc(n){
  209. for(var i=0;i<li.length;i++){
  210. button.childNodes[i].className="b1";
  211. };
  212. button.childNodes[n].className="b2";
  213. }
  214. title.className="num_list";
  215. title.appendChild(span);
  216. alpha(title,opac1);
  217. id.className="d1";
  218. div.className="d2";
  219. id.appendChild(div);
  220. id.appendChild(title);
  221. id.appendChild(button);
  222. //渐显
  223. var fadeon=function(){
  224. opac+=5;
  225. div.innerHTML=li[j].innerHTML;
  226. span.innerHTML=getTag("img",li[j])[0].alt;
  227. alpha(div,opac);
  228. if(scton==0){
  229. sc(j);
  230. num=-2;
  231. scrolltxt();
  232. scton=1;
  233. };
  234. if(opac<100){
  235. timer=setTimeout(fadeon,interv2);
  236. }else{
  237. timer2=setTimeout(fadeout,interv);
  238. }
  239. };
  240. //渐隐
  241. var fadeout=function(){
  242. opac-=5;
  243. div.innerHTML=li[j].innerHTML;
  244. alpha(div,opac);
  245. if(scton==0){
  246. num=2;
  247. scrolltxt();
  248. scton=1;
  249. }
  250. if(opac>0){
  251. timer=setTimeout(fadeout,interv2);
  252. }else{
  253. if(j<li.length-1){
  254. j++;
  255. }else{
  256. j=0;
  257. }
  258. fadeon();
  259. }
  260. };
  261. //滚动文字
  262. var scrolltxt=function(){
  263. t+=num;
  264. span.style.marginTop=t+"px";
  265. if(num<0 && t>3){
  266. timer3=setTimeout(scrolltxt,interv2);
  267. }else if(num>0 && t<62){
  268. timer3=setTimeout(scrolltxt,interv2);
  269. }else{
  270. scton=0
  271. }
  272. };
  273. fadeon();
  274. }
  275. window.onload=function(){
  276. s();
  277. focusRun.init();
  278. };
  279. //视频轮播
  280. // banner1切换
  281. var banner_a = 0; //当前显示的图片的索引
  282. var banner_img_number = $('#img_list a').size();
  283. $('#num span').mouseover(function(){
  284. clearInterval(banner_timer1);
  285. var span_a = $(this).index();
  286. banner_a = span_a;
  287. toggle_image1();
  288. }).mouseout(function(){
  289. banner_timer1 = setInterval(toggle_image1,5000);
  290. })
  291. function toggle_image1()
  292. {
  293. $('#img_list a').not(':eq('+banner_a+')').hide();
  294. $('#img_list a').eq(banner_a).show();
  295. $('#num span').removeClass('lh_hover').eq(banner_a).addClass('lh_hover');
  296. banner_a++;
  297. if(banner_a >= banner_img_number) banner_a = 0;
  298. }
  299. $('#num span').eq(0).mouseover();
  300. var banner_timer1 = setInterval(toggle_image1,5000);
  301. //图片轮播
  302. var banner_i = 0; //当前显示的图片的索引
  303. var banner_img_number = $('#img_list2 a').size();
  304. $('#num2 b').mouseover(function(){
  305. clearInterval(banner_timer);
  306. var span_i = $(this).index();
  307. banner_i = span_i;
  308. toggle_image();
  309. }).mouseout(function(){
  310. banner_timer = setInterval(toggle_image,5000);
  311. })
  312. function toggle_image()
  313. {
  314. $('#img_list2 a').not(':eq('+banner_i+')').hide();
  315. $('#img_list2 a').eq(banner_i).show();
  316. $('#num2 b').removeClass('lh_hover').eq(banner_i).addClass('lh_hover');
  317. banner_i++;
  318. if(banner_i >= banner_img_number) banner_i = 0;
  319. }
  320. $('#num2 span').eq(0).mouseover();
  321. var banner_timer = setInterval(toggle_image,5000);
  322. $(function(){
  323. //tab切换
  324. $(".tab_list").eq(0).show();
  325. $(".lie_tab a").hover(
  326. function(){
  327. $(".tab_list").eq($(this).index()).show().siblings(".tab_list").hide();
  328. $(this).addClass('xx').siblings().removeClass('xx');
  329. }
  330. );
  331. //重要活动轮播
  332. $('.my-slider').unslider({
  333. speed: 500,
  334. delay: 3000,
  335. autoplay:1
  336. });
  337. });