function YmCmsAd60(PID){ this.ID = PID; this.PosID = 0; this.AdNum = 0; this.Width = 0; this.Height = 0; this.SiteID = 0; this.ADContent = ''; //广告内容 this.Stat = statAD; this.showAD = showADContent; this.SlidShow = new Object(); //外层壳 this.ShowNumber = new Object(); //数字 this.Timer = null; //定时器 this.iNow = 0; //正在展示的图片索引 this.play = autoPlay; } function statAD() { } function showADContent(id) { //写入样式 var css = '.slideShow{border: 1px #eeeeee solid;position: relative;overflow: hidden;}\n' + '\t\t.slideShow ul{position: relative;margin: 0;padding:0;}\n' + '\t\t.slideShow img{max-width:100%;max-height:100%;width:100%;height:100%;}\n' + '\t\t.slideShow ul li{float: left;width: 346px;list-style: none;}\n' + '\t\t.slideShow .showNav{position: absolute;right: 10px;bottom: 5px;text-align:center;font-size: 12px;line-height: 20px;}\n' + '\t\t.slideShow .showNav span{cursor: pointer;display: block;float: left;width: 20px;height: 20px;background: #ff5a28;margin-left: 2px;color: #fff;}\n' + '\t\t.slideShow .showNav .active{background: #b63e1a;}'; var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = css; document.getElementsByTagName('HEAD').item(0).appendChild(style); var content = this.ADContent; var AD = eval('('+content+')'); var rand = Math.ceil(Math.random()*1000); var str = '
'; $.each(AD,function(index,btn){ if(index == 0){ str += '1'; }else{ str += ''+ (index +1) +''; } }); str += '
'; document.write(str); this.SlidShow = $("#slide_"+ rand); var ul = this.SlidShow.find('ul'); //设置尺寸 this.SlidShow.css('width',this.Width).css('height',this.Height); ul.css('width',this.Width * (this.AdNum+1)).css('height',this.Height); this.SlidShow.find('ul li').css('width',this.Width).css('height',this.Height); //this.showNumber = this.SlidShow.find(".showNav span"); //获取按钮 this.showNumber = $("#showNav_"+ rand +" span"); var oneWidth = this.SlidShow.find("ul li").eq(0).width(); //获取每个图片的宽度 console.log('dftNow',this.iNow); that = this; //按钮点击 this.showNumber.on("click",function(){ $(this).addClass("active").siblings().removeClass("active"); var index = $(this).index(); that.iNow = index; ul.animate({ "left":-oneWidth* that.iNow, }) }); //鼠标悬停 this.SlidShow.hover(function(){ console.log('slidHover'); clearInterval(that.timer); },function(){ console.log('slidOverOut') that.play() }); } //生成从minNum到maxNum的随机数 function randomNum(minNum,maxNum){ switch(arguments.length){ case 1: return parseInt(Math.random()*minNum+1,10); break; case 2: return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); break; default: return 0; break; } } function autoPlay(){ //console.log('autoINum'+ this.ID,this.iNow); //console.log('dot.length', that.showNumber.length); var numObj = that.showNumber; var index = that.iNow; //var rand = randomNum(1500,3000); var rand = 4000; var adNum = that.AdNum; var timer=setInterval(function(){ //打开定时器 //console.log('now Index',index) index++; //让图片的索引值次序加1,这样就可以实现顺序轮播图片 if(index > adNum-1){ //当到达最后一张图的时候,让iNow赋值为第一张图的索引值,轮播效果跳转到第一张图重新开始 index=0; } numObj.eq(index).trigger('click'); //模拟触发数字按钮的click },rand); //2000为轮播的时间 } if(typeof jQuery == 'undefined'){ var ref = document.createElement('script'); ref.setAttribute('type','text/javascript'); ref.setAttribute('src','http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js'); document.getElementsByTagName('HEAD').item(0).appendChild(ref); } var ymAD_60 = new YmCmsAd60('ymcms_AD_60'); ymAD_60.Width = 1200; //广告位宽度 ymAD_60.Height = 80; //广告位高度 ymAD_60.AdNum = 2; //广告数量 ymAD_60.ADContent = '[{"imgAlt":"\u7f51\u7edc\u4e2d\u56fd\u8282\u6625\u8282","linkUrl":"https:\/\/ads.xxrb.com.cn\/Ads\/ad\/412","imgSrc":"https:\/\/ads.xxrb.com.cn\/uploads\/20240206\/65c1b5c607818.jpg"},{"imgAlt":"\u91cd\u8981\u6307\u793a","linkUrl":"https:\/\/ads.xxrb.com.cn\/Ads\/ad\/382","imgSrc":"https:\/\/ads.xxrb.com.cn\/uploads\/20231228\/658d407712b2d.jpg"}]'; ymAD_60.showAD(); ymAD_60.play();