查看文章 |
以前写的一段JS,查阅了不少资料,留备份
2008-01-24 15:56
var oBtnPic = new BtnPic(); oBtnPic.Initialize(); //BtnPic类 function BtnPic(){ this.ContentName = "HotelPictureContent"; //控件容器名称 this.PicSrc = new Array(); //图片地址 this.PicBtn = new Array(); //图片显示控件 this.PicName = new Array(); //图片名称 this.PicLabel = new Array(); //图片名称显示控件 this.Btn = $("DefaultImage"); //大图显示控件 this.Path = ""; this.Initialize = Initialize; //初始化 this.Load = Load; //加载数据 this.Left = Left; //左移 this.Right = Right; //右移 this.Select = Select; //选中 this.Error = Error; //错误发生时 this.BtnLeft = $("ImgGoLeft"); this.BtnRight = $("ImgGoRight"); this.ErrorImage = "/skin/default070524/442x349.jpg"; } //返回对象引用 function $(id){ return document.getElementById(id); } //初始化数据,此应包含"大堂,外观,客厅"的图与图库里的图; function Initialize(){ //图片数据初始化 1,小图,2,大图,3图片名称 var rootNode = document.getElementById("XmlPhotos").XMLDocument.documentElement; if(rootNode == null) return; for( var i=0; i<rootNode.selectNodes( "//photo" ).length; i++ ){ if(rootNode.selectNodes("//photo")[i].childNodes[4].text == 0){//默认显示,值0 this.PicSrc.push(rootNode.selectNodes( "//photo" )[i].childNodes[1].text);//smallfilename this.PicName.push(rootNode.selectNodes( "//photo" )[i].childNodes[3].text);//photoname } } //控件初始化,显示图片 var oControl = $(this.ContentName).getElementsByTagName("img"); if(oControl == null || oControl == undefined) return; var oData = new Array(); for(var p=0;p<oControl.length;p++){ if(oControl[p].id.toLowerCase().indexOf("listimage") > -1){ oData.push(oControl[p].id); } } this.PicBtn = oData; oData=null; oControl=null; //控件初始化,显示图片名称 var iControl = $(this.ContentName).getElementsByTagName("span"); if(iControl == null || iControl == undefined) return; var iData = new Array(); for(var j=0;j<iControl.length;j++){ if(iControl[j].id.toLowerCase().indexOf("listspan") > -1){ iData.push(iControl[j].id); } } this.PicLabel = iData; iData=null; iControl=null; if(this.PicSrc.length<=3){ this.BtnLeft.style.display = "none"; this.BtnRight.style.display = "none"; }else{ this.BtnLeft.style.display = "block"; this.BtnRight.style.display = "block"; } if(this.PicSrc[0] == null || this.PicSrc[0] == undefined || this.PicSrc[0].indexOf("skin") != -1) this.Btn.src = this.ErrorImage; else this.Btn.src = this.Path + this.PicSrc[0].replace("/Thumb",""); this.Load(); } //加载图片 function Load(){ for(var i=0;i<this.PicBtn.length;i++){ $(this.PicBtn[i]).src = this.Path + this.PicSrc[i]; $(this.PicLabel[i]).innerText = this.PicName[i]; } } //左移 function Left(){ this.PicSrc.push(this.PicSrc[0]);//将第一项添加到数组最后 this.PicSrc.shift();//删除第一项 this.PicName.push(this.PicName[0]); this.PicName.shift(); this.Load(); } //右移 function Right(){ this.PicSrc.unshift(this.PicSrc[this.PicSrc.length-1]);//将最后一项添加至开头 this.PicSrc.pop();//删除最后一项 this.PicName.unshift(this.PicName[this.PicName.length-1]); this.PicName.pop(); this.Load(); } //选中的图片 function Select(oBtn){ //处理小图与大图的路径 if(oBtn.src.indexOf("skin") == -1){ this.Btn.src = oBtn.src.replace("/Thumb","");//oPath + "/Thubm" + oName; }else{ this.Error(); } } //错误发生时 function Error(){ this.Btn.src = this.ErrorImage;//大图 return; } |
类别:asp/asp.net
| 浏览()
| 评论 (0)