function getversion() { var browser=navigator.appname; var b_version=navigator.appversion; var version=b_version.split(";"); var trim_version=version[1].replace(/[ ]/g,""); return (browser=="microsoft internet explorer" && trim_version=="msie10.0"); } function imagechangenews(uid, width, height, interval, duration, btitle, bsummary, zoomtype, zoomout, iscentercutimg, cutimgparent) { var _this = this; //把this保存下来,以后用_this代替this,这样就不会被this弄晕了 _this.imgs = new array(); //图片组 _this.urls = new array(); //链接组 _this.titles = new array(); //标题组 _this.summarys = new array(); //摘要组 _this.tiptitles = new array(); //鼠标提示 _this.nextindex=0; //下次显示的滚动图 _this.currentindex=-1; //当前显示的滚动图 _this.firstflag = 0; //标识是否为第一次开始执行 _this.currenttimer = null; //标识作用 //图片加载完毕事件 _this.onimgload = function(loadindex) { _this.imgs[loadindex].setattribute("loadedflag", true); if(loadindex == _this.currentindex) { _this.constrainimg(document.getelementbyid(uid + "pic"), _this.imgs[loadindex], document.getelementbyid(uid + "imgdiv")); } } //添加图片 _this.addimg = function(img, url, title, summary,tiptitle) { var imgcount = _this.imgs.length; _this.imgs[imgcount] = new image(); _this.imgs[imgcount].onload = function(){_this.onimgload(imgcount)}; _this.imgs[imgcount].src = img; _this.urls[imgcount] = url; _this.titles[imgcount] = title; _this.summarys[imgcount] = summary; if(tiptitle){ _this.tiptitles[imgcount] = tiptitle; } } //触发图片改变 _this.changeimg = function (n) { if(_this.imgs.length < 1) { return; } if(_this.currenttimer != null) window.clearinterval(_this.currenttimer); //清除用于循环的currenttimer _this.currenttimer = window.setinterval(_this.onchangeimg, interval * 1000);//设置循环周期为4000 _this.nextindex = n; //要显示的id等于传入的n值, _this.onchangeimg(); } //改变图片操作 _this.onchangeimg = function() { try { if(_this.imgs.length < 1) { return; } if(_this.firstflag == 0) { _this.firstflag = 1; } else if(document.all && !getversion()) { var imgfilter = document.getelementbyid(uid + "div").filters[0]; imgfilter.apply(); imgfilter.play(duration); imgfilter.transition=23; } //图片未加载完毕 if(_this.imgs[_this.nextindex].getattribute("loadedflag") == null) { document.getelementbyid(uid + "pic").src = "/system/resource/images/space.gif"; } else { //图片正常加载, 设置图片 _this.constrainimg(document.getelementbyid(uid + "pic"), _this.imgs[_this.nextindex], document.getelementbyid(uid + "imgdiv")); } //设置当前图片编号 _this.currentindex = _this.nextindex; document.getelementbyid(uid + "url").href = _this.urls[_this.nextindex]; btitle = true; if(btitle) { document.getelementbyid(uid + "newstitle").innerhtml = _this.titles[_this.nextindex]; document.getelementbyid(uid + "newstitle").href = _this.urls[_this.nextindex]; if(_this.tiptitles.length > 0){ document.getelementbyid(uid + "newstitle").title =_this.tiptitles[_this.nextindex]; }else{ document.getelementbyid(uid + "newstitle").title =_this.titles[_this.nextindex]; } } if(bsummary) { document.getelementbyid(uid + "newssummary").innerhtml = _this.summarys[_this.nextindex]; document.getelementbyid(uid + "newssummary").href = _this.urls[_this.nextindex]; } //设置所有按钮的样式 for(var i = 0;i < _this.imgs.length; i++) { if(i == _this.nextindex) document.getelementbyid(uid + "selectnode"+i).classname='imagechangenews_fnode'; else document.getelementbyid(uid + "selectnode"+i).classname='imagechangenews_pnode'; } _this.nextindex++; if(_this.nextindex >= _this.imgs.length) { //如果id大于总图片数量。则从头开始循环 _this.nextindex = 0; } } catch(e) { } } //等比例设置图片 _this.constrainimg = function(imgobj, imagevar, imgdiv) { try { var widthrate = imagevar.width / width; var heightrate = imagevar.height / height; var imgwidth = 0; var imgheight = 0; if(widthrate > 1 || heightrate > 1) //图片过大时 { if(!iscentercutimg) { if (zoomtype)//按比例缩小 { var rate = math.max(widthrate, heightrate); imgwidth = math.max(1, math.min(imagevar.width / rate, width)); imgheight = math.max(1, math.min(imagevar.height / rate, height)); } else//拉伸 { imgwidth = width; imgheight = height; } } } else if(widthrate < 1 || heightrate < 1) //图片小 { if(!iscentercutimg) { if (zoomout)//自动放大 { if (zoomtype)//按比例放大 { var rate = math.max(widthrate, heightrate); imgwidth = math.max(1, math.min(imagevar.width / rate, width)); imgheight = math.max(1, math.min(imagevar.height / rate, height)); } else //拉伸 { imgwidth = width; imgheight = height; } } else { imgwidth = imagevar.width; imgheight = imagevar.height; } } } else //大小合适 { imgwidth = width; imgheight = height; } imgobj.src = imagevar.src; if(!iscentercutimg) { imgobj.width = imgwidth; imgobj.height = imgheight; imgdiv.style.paddingtop = (height - imgheight) / 2+"px"; }else{ cutimg(imgobj,"autocut",cutimgparent); } } catch(e) { } } }