//最后修订版本号:$revision: 28 $ //最后修改人:$author: admin $ //最后修改时间:$date: 2009-07-20 18:03:52 +0800 (星期一, 2009-07-20) $ /*********************************************************************************************/ /*功能:jq插件图片预载入等比居中缩放*/ /*********************************************************************************************/ jquery.fn.loadimage=function(width,height,txtheight,loadpic){ if(loadpic==null)loadpic="/upfiles/system/loading.gif"; return this.each(function(){ var t=$(this); //取父框div.img的内外框值 var parentpadtop=math.round(t.parent().css("padding-top").replace(/\d/g,'')); var parentpadbom=math.round(t.parent().css("padding-bottom").replace(/\d/g,'')); var parentmarbom=math.round(t.parent().css("margin-bottom").replace(/\d/g,'')); var parentmartop=math.round(t.parent().css("margin-top").replace(/\d/g,'')); var parentpadlft=math.round(t.parent().css("padding-left").replace(/\d/g,'')); var parentpadrgt=math.round(t.parent().css("padding-right").replace(/\d/g,'')); var parentmarlft=math.round(t.parent().css("margin-left").replace(/\d/g,'')); var parentmarrgt=math.round(t.parent().css("margin-right").replace(/\d/g,'')); var parentbdrgt=math.round(t.parent().css("border-right-width").replace(/\d/g,'')); var parentbdlft=math.round(t.parent().css("border-left-width").replace(/\d/g,'')); var parentbdtop=math.round(t.parent().css("border-top-width").replace(/\d/g,'')); var parentbdbom=math.round(t.parent().css("border-bottom-width").replace(/\d/g,'')); var boxwidth=parentbdlft+parentpadlft+parentmarlft+parentbdrgt+parentpadrgt+parentmarrgt; var boxheight=parentbdtop+parentpadtop+parentmartop+parentbdbom+parentpadbom+parentmarbom; //设定父级外框a元素高度 var aheight=height+txtheight; t.parent().parent().css({height:aheight,width:width}); var src=$(this).attr("src"); var img=new image(); //alert("loading...") img.src=src; //自动缩放图片 var autoscaling=function(){ if(img.width>0 && img.height>0){ if(img.width/img.height>=width/height){ if(img.width>width){ t.width(width-boxwidth); t.height((img.height*width)/img.width-boxheight); }else{ t.width(img.width-boxwidth); t.height(img.height-boxheight); } } else{ if(img.height>height){ t.height(height-boxwidth); t.width((img.width*height)/img.height-boxheight); }else{ t.width(img.width-boxwidth); t.height(img.height-boxheight); } } } if (t.height()"); t.hide(); t.after(loading); $(img).load(function(){ autoscaling(); loading.remove(); t.attr("src",this.src); t.css() t.show(); //alert("finally!") }); }); } /*********************************************************************************************/ /*功能:jq插件页面漂浮在线qq之类*/ /*********************************************************************************************/ jquery.fn.jfloat = function(o) { o = $.extend({ top:60, //广告距页面顶部距离 left:0,//广告左侧距离 right:0,//广告右侧距离 width:100, //广告容器的宽度 height:360, //广告容器的高度 minscreenw:800,//出现广告的最小屏幕宽度,当屏幕分辨率小于此,将不出现对联广告 position:"left", //对联广告的位置left-在左侧出现,right-在右侧出现 allowclose:true //是否允许关闭 }, o || {}); var h=o.height; var showad=true; var fdiv=$(this); if(o.minscreenw>=$(window).width()){ fdiv.hide(); showad=false; } else{ fdiv.css("display","block") var closehtml='
×
'; switch(o.position){ case "left": if(o.allowclose){ fdiv.prepend(closehtml); $(".closefloat",fdiv).click(function(){$(this).hide();fdiv.hide();showad=false;}) h+=20; } fdiv.css({position:"absolute",left:o.left+"px",top:o.top+"px",width:o.width+"px",height:h+"px",overflow:"hidden"}); break; case "right": if(o.allowclose){ fdiv.prepend(closehtml) $(".closefloat",fdiv).click(function(){$(this).hide();fdiv.hide();showad=false;}) h+=20; } fdiv.css({position:"absolute",left:"auto",right:o.right+"px",top:o.top+"px",width:o.width+"px",height:h+"px",overflow:"hidden"}); break; }; }; function ylfloat(){ if(!showad){return} var windowtop=$(window).scrolltop(); if(fdiv.css("display")!="none") fdiv.css("top",o.top+windowtop+"px"); }; $(window).scroll(ylfloat) ; $(document).ready(ylfloat); } /*********************************************************************************************/ /*功能:jq插件横向滚动使用*/ /*********************************************************************************************/ jquery.fn.jmarquee = function(o) { o = $.extend({ speed:30, step:1,//滚动步长 direction:"up",//滚动方向 visible:1//可见元素数量 }, o || {}); //获取滚动内容内各元素相关信息 var i=0; var div=$(this); var ul=$("ul",div); var tli=$("li",ul); var lisize=tli.size(); if(o.direction=="left") tli.css("float","left"); var liwidth=tli.innerwidth(); var liheight=tli.height(); var ulheight=liheight*lisize; var ulwidth=liwidth*lisize; //如果对象元素个数大于指定的显示元素则进行滚动,否则不滚动。 if(lisize>o.visible){ ul.append(tli.slice(0,o.visible).clone()) //复制前o.visible个li,并添加到ul的最后 li=$("li",ul); lisize=li.size(); //给滚动内容添加相关css样式 div.css({"position":"relative",overflow:"hidden"}); ul.css({"position":"relative",margin:"0",padding:"0","list-style":"none"}); li.css({margin:"0",padding:"0","position":"relative"}); switch(o.direction){ case "left": div.css("width",(liwidth*o.visible)+"px"); ul.css("width",(liwidth*lisize)+"px"); li.css("float","left"); break; case "up": div.css({"height":(liheight*o.visible)+"px"}); ul.css("height",(liheight*lisize)+"px"); break; } var mymar=setinterval(ylmarquee,o.speed); ul.hover( function(){clearinterval(mymar);}, function(){mymar=setinterval(ylmarquee,o.speed);} ); }; function ylmarquee(){ if(o.direction=="left"){ if(div.scrollleft()>=ulwidth){ div.scrollleft(0); } else { var leftnum=div.scrollleft(); leftnum+=parseint(o.step); div.scrollleft(leftnum) } } if(o.direction=="up"){ if(div.scrolltop()>=ulheight){ div.scrolltop(0); } else{ var topnum=div.scrolltop(); topnum+=parseint(o.step); div.scrolltop(topnum); } } }; } /*********************************************************************************************/ /*功能:jq插件页面等高使用*/ /*********************************************************************************************/ $.fn.equalheights = function(px) { $(this).each(function(){ var currenttallest = 0; $(this).children().each(function(i){ if ($(this).height() > currenttallest) { currenttallest = $(this).height(); } }); if (!px || !number.prototype.pxtoem) currenttallest = currenttallest.pxtoem(); //use ems unless px is specified // for ie6, set height since min-height isn't supported if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currenttallest}); } $(this).children().css({'min-height': currenttallest}); }); return this; }; // just in case you need it... $.fn.equalwidths = function(px) { $(this).each(function(){ var currentwidest = 0; $(this).children().each(function(i){ if($(this).width() > currentwidest) { currentwidest = $(this).width(); } }); if(!px || !number.prototype.pxtoem) currentwidest = currentwidest.pxtoem(); //use ems unless px is specified // for ie6, set width since min-width isn't supported if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'width': currentwidest}); } $(this).children().css({'min-width': currentwidest}); }); return this; }; number.prototype.pxtoem = string.prototype.pxtoem = function(settings){ //set defaults settings = jquery.extend({ scope: 'body', reverse: false }, settings); var pxval = (this == '') ? 0 : parsefloat(this); var scopeval; var getwindowwidth = function(){ var de = document.documentelement; return self.innerwidth || (de && de.clientwidth) || document.body.clientwidth; }; if (settings.scope == 'body' && $.browser.msie && (parsefloat($('body').css('font-size')) / getwindowwidth()).tofixed(1) > 0.0) { var calcfontsize = function(){ return (parsefloat($('body').css('font-size'))/getwindowwidth()).tofixed(3) * 16; }; scopeval = calcfontsize(); } else { scopeval = parsefloat(jquery(settings.scope).css("font-size")); }; var result = (settings.reverse == true) ? (pxval * scopeval).tofixed(2) + 'px' : (pxval / scopeval).tofixed(2) + 'em'; return result; }; /*********************************************************************************************/ /*功能:jq插件,幻灯图片*/ /*********************************************************************************************/ jquery.fn.focusimg=function(){ var obj=$(this); objname=obj.attr("id"); obj.children("ul").attr("id",objname+"-fragment"); var num=(obj.children("ul").children("li").length)-1; var temp_b=new string(); for(var i=0;i<=num;i++){ temp_b+=""+(i+1)+""; obj.children("ul").children("li").eq(i).attr("id",objname+"-fragment-"+i) } obj.append(""+temp_b+""); obj.children("span").children("a").eq(num).addclass("a2"); obj.children("span").children("a").click(function(){ obj.children("span").children("a").removeclass("a2"); $(this).addclass("a2"); var id=($(this).attr("id")).replace("button","fragment"); $("#"+id).appendto(obj.children("ul")); return false; }); topboxrun=function(){ obj.children("ul").children("li").eq(num).fadeout("slow",function(){ obj.children("span").children("a").removeclass("a2"); var id=($(this).prev().attr("id")).replace("fragment","button"); $("#"+id).addclass("a2"); $(this).prependto(obj.children("ul")); $(this).show(); }); } var t=setinterval(topboxrun,3000); } /*********************************************************************************************/ /*功能:jq插件,横向竖直两用多级ul li形菜单*/ /*********************************************************************************************/ var ddsmoothmenu={ //specify full url to down and right arrow images (23 is padding-right added to top level lis with drop downs): arrowimages: {down:['downarrowclass', 'down.gif', 23], right:['rightarrowclass', 'right.gif']}, transition: {overtime:300, outtime:300}, //duration of slide in/ out animation, in milliseconds shadow: {enabled:true, offsetx:5, offsety:5}, ///////stop configuring beyond here/////////////////////////// detectwebkit: navigator.useragent.tolowercase().indexof("applewebkit")!=-1, //detect webkit browsers (safari, chrome etc) detectie6: document.all && !window.xmlhttprequest, getajaxmenu:function($, setting){ //function to fetch external page containing the panel divs var $menucontainer=$('#'+setting.contentsource[0]) //reference empty div on page that will hold menu $menucontainer.html("loading menu...") $.ajax({ url: setting.contentsource[1], //path to external menu file async: true, error:function(ajaxrequest){ $menucontainer.html('error fetching content. server response: '+ajaxrequest.responsetext) }, success:function(content){ $menucontainer.html(content) ddsmoothmenu.buildmenu($, setting) } }) }, buildmenu:function($, setting){ var smoothmenu=ddsmoothmenu var $mainmenu=$("#"+setting.mainmenuid+">ul") //reference main menu ul $mainmenu.parent().get(0).classname=setting.classname || "ddsmoothmenu" var $headers=$mainmenu.find("ul").parent() $headers.hover( function(e){ $(this).children('a:eq(0)').addclass('selected') }, function(e){ $(this).children('a:eq(0)').removeclass('selected') } ) $headers.each(function(i){ //loop through each li header var $curobj=$(this).css({zindex: 100-i}) //reference current li header var $subul=$(this).find('ul:eq(0)').css({display:'block'}) this._dimensions={w:this.offsetwidth, h:this.offsetheight, subulw:$subul.outerwidth(), subulh:$subul.outerheight()} this.istopheader=$curobj.parents("ul").length==1? true : false //is top level header? $subul.css({top:this.istopheader && setting.orientation!='v'? this._dimensions.h+"px" : 0}) $curobj.children("a:eq(0)").css(this.istopheader? {paddingright: smoothmenu.arrowimages.down[2]} : {}).append( //add arrow images '' ) if (smoothmenu.shadow.enabled){ this._shadowoffset={x:(this.istopheader?$subul.offset().left+smoothmenu.shadow.offsetx : this._dimensions.w), y:(this.istopheader? $subul.offset().top+smoothmenu.shadow.offsety : $curobj.position().top)} //store this shadow's offsets if (this.istopheader) $parentshadow=$(document.body) else{ var $parentli=$curobj.parents("li:eq(0)") $parentshadow=$parentli.get(0).$shadow } this.$shadow=$('
').prependto($parentshadow).css({left:this._shadowoffset.x+'px', top:this._shadowoffset.y+'px'}) //insert shadow div and set it to parent node for the next shadow div } $curobj.hover( function(e){ var $targetul=$(this).children("ul:eq(0)") this._offsets={left:$(this).offset().left, top:$(this).offset().top} var menuleft=this.istopheader && setting.orientation!='v'? 0 : this._dimensions.w menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader && setting.orientation!='v'? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft //calculate this sub menu's offsets from its parent if ($targetul.queue().length<=1){ //if 1 or less queued animations $targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).animate({height:'show',opacity:'show'}, ddsmoothmenu.transition.overtime) if (smoothmenu.shadow.enabled){ var shadowleft=this.istopheader? $targetul.offset().left+ddsmoothmenu.shadow.offsetx : menuleft var shadowtop=this.istopheader?$targetul.offset().top+smoothmenu.shadow.offsety : this._shadowoffset.y if (!this.istopheader && ddsmoothmenu.detectwebkit){ //in webkit browsers, restore shadow's opacity to full this.$shadow.css({opacity:1}) } this.$shadow.css({overflow:'', width:this._dimensions.subulw+'px', left:shadowleft+'px', top:shadowtop+'px'}).animate({height:this._dimensions.subulh+'px'}, ddsmoothmenu.transition.overtime) } } }, function(e){ var $targetul=$(this).children("ul:eq(0)") $targetul.animate({height:'hide', opacity:'hide'}, ddsmoothmenu.transition.outtime) if (smoothmenu.shadow.enabled){ if (ddsmoothmenu.detectwebkit){ //in webkit browsers, set first child shadow's opacity to 0, as "overflow:hidden" doesn't work in them this.$shadow.children('div:eq(0)').css({opacity:0}) } this.$shadow.css({overflow:'hidden'}).animate({height:0}, ddsmoothmenu.transition.outtime) } } ) //end hover }) //end $headers.each() $mainmenu.find("ul").css({display:'none', visibility:'visible'}) }, init:function(setting){ if (typeof setting.customtheme=="object" && setting.customtheme.length==2){ //override default menu colors (default/hover) with custom set? var mainmenuid='#'+setting.mainmenuid var mainselector=(setting.orientation=="v")? mainmenuid : mainmenuid+', '+mainmenuid document.write('') } this.shadow.enabled=(document.all && !window.xmlhttprequest)? false : true //in ie6, always disable shadow jquery(document).ready(function($){ //ajax menu? if (typeof setting.contentsource=="object"){ //if external ajax menu ddsmoothmenu.getajaxmenu($, setting) } else{ //else if markup menu ddsmoothmenu.buildmenu($, setting) } }) } } //end ddsmoothmenu variable //initialize menu instance(s): /*********************************************************************************************/ /*功能:jq插件,轻便ul li下拉菜单*/ /*********************************************************************************************/ jquery.jfastmenu = function(id){ $(id + ' ul li').hover(function(){ $(this).find('ul:first').animate({height:'show'}, 'fast'); }, function(){ $(this).find('ul:first').animate({height:'hide', opacity:'hide'}, 'slow'); }); } /*********************************************************************************************/ /*功能:折叠菜单使用*/ /*********************************************************************************************/ function ulshow(vid) { if(document.getelementbyid("ul"+vid).style.display=="none"){ document.getelementbyid("ul"+vid).style.display=""; document.getelementbyid("f"+vid).src=document.getelementbyid("f"+vid).src.replace("+","-") } else{ document.getelementbyid("ul"+vid).style.display="none"; document.getelementbyid("f"+vid).src=document.getelementbyid("f"+vid).src.replace("-","+") } return; } /*********************************************************************************************/ /*功能:搜索页使用*/ /*********************************************************************************************/ function getweblist2(url,domid,pagenum){ var currentfunpath; var susername; var sguid; if(typeof(videopathroot)=="undefined"){currentfunpath=""}else{currentfunpath=videopathroot} if(typeof(videousername)=="undefined"){susername=""}else{susername=videousername} if(typeof(videoguid)=="undefined"){sguid=""}else{sguid=videoguid} var objectn="#"+domid; var targeturl="http://www.51g3.com/news/remote3.0.asp?callback=?&page="+pagenum+"&pagenum="+url+"&ntimest="+math.random()+"&guid="+sguid+"&u="+susername; $.getjson(targeturl,function(d){ $(objectn).html(d.jsonobj[0]); }); } function autoplay(url,pagenum){ var currentfunpath; var susername; var sguid; if(typeof(videopathroot)=="undefined"){currentfunpath=""}else{currentfunpath=videopathroot} if(typeof(videousername)=="undefined"){susername=""}else{susername=videousername} if(typeof(videoguid)=="undefined"){sguid=""}else{sguid=videoguid} var videobaseurl; if (currentfunpath=="") {videobaseurl=currentfunpath} else { if(currentfunpath.indexof('://')>=0) {videobaseurl = currentfunpath; } else {videobaseurl = 'http://'+window.location.host+'/';} } var targeturl=""+videobaseurl+"inc/ajaxtv.asp?callback=?&page="+pagenum+"&pagenum="+url+"&ntimest="+math.random()+"&guid="+sguid+"&u="+susername+"&action=p"; //alert('调试模式'); if (pagenum==1){ $.getjson(targeturl,function(d){ player(d.jsonobj[0]); }); } } function getweblist(url,domid,pagenum){ var currentfunpath; var susername; var sguid; if(typeof(videopathroot)=="undefined"){currentfunpath=""}else{currentfunpath=videopathroot} if(typeof(videousername)=="undefined"){susername=""}else{susername=videousername} if(typeof(videoguid)=="undefined"){sguid=""}else{sguid=videoguid} var objectn="#"+domid; var videobaseurl; if (currentfunpath=="") {videobaseurl=currentfunpath} else { if(currentfunpath.indexof('://')>=0) {videobaseurl = currentfunpath; } else {videobaseurl = 'http://'+window.location.host+'/';} } var targeturl=""+videobaseurl+"inc/ajaxtv.asp?callback=?&page="+pagenum+"&pagenum="+url+"&ntimest="+math.random()+"&guid="+sguid+"&u="+susername; $.getjson(targeturl,function(d){ $(objectn).html(d.jsonobj[0]);autoplay(url,pagenum) }); } function player(flvname){ //播放器 , 播放器id,宽 , 高, var s1 = new swfobject("video/mediaplayer.swf","player_id",tvwidth,tvheight,"7"); s1.addparam("allowfullscreen","true");//是否允许全屏播放 s1.addvariable("file",flvname);//单文件播放 s1.addvariable("image","/video/preview.jpg");//背景图片 s1.addvariable("displayheight",tvheight);//播放区域高度 s1.addvariable("width",tvwidth); s1.addvariable("height",tvheight); s1.addvariable("backcolor","0x000000"); s1.addvariable("frontcolor","0xcccccc"); s1.addvariable("lightcolor","0x557722"); s1.addvariable("enablejs","true");//是否允许javascript脚本控制flash s1.addvariable("javascriptid","javascript_id");//控制脚本javascriptid s1.write("myplayer");//将播放器写入到myplayer } function g(o){return document.getelementbyid(o);} function hoverli(n){for(var i=1;i<=2;i++){g('tb_'+i).classname='normaltab';g('tbc_0'+i).classname='undis';}g('tbc_0'+n).classname='dis';g('tb_'+n).classname='hovertab';} // //搜索ajax函数 function getajaxpage(url,keywords,perpagenum,ccid,action,pagenum){ var objectn=".indexproductinner"; var currentfunpath; var susername; var sguid; if(typeof(videopathroot)=="undefined"){currentfunpath=""}else{currentfunpath=videopathroot} if(typeof(videousername)=="undefined"){susername=""}else{susername=videousername} if(typeof(videoguid)=="undefined"){sguid=""}else{sguid=videoguid} var videobaseurl; if (currentfunpath=="") {videobaseurl=currentfunpath} else { if(currentfunpath.indexof('://')>=0) {videobaseurl = currentfunpath; } else {videobaseurl = 'http://'+window.location.host+'/';} } var targeturl=""+videobaseurl+"inc/ajaxsearch.asp?callback=?&action="+action+"&ccid="+ccid+"&perpagenum="+perpagenum+"&pagenum="+pagenum+"&ntimest="+math.random()+"&guid="+sguid+"&u="+susername+"&keywords="+keywords; $.getjson(targeturl,function(d){ $(objectn).html(d.jsonobj[0]);getajaxpagecomelete(objectn) }); } //取得静态页参数函数 function getquerystring(querystringname) { var returnvalue=""; var urlstring=new string(document.location); var serachlocation=-1; var querystringlength=querystringname.length; do { serachlocation=urlstring.indexof(querystringname+"\="); if (serachlocation!=-1) { if ((urlstring.charat(serachlocation-1)=='?') || (urlstring.charat(serachlocation-1)=='&')) { urlstring=urlstring.substr(serachlocation); break; } urlstring=urlstring.substr(serachlocation+querystringlength+1); } } while (serachlocation!=-1) if (serachlocation!=-1) { var seperatorlocation=urlstring.indexof("&"); if (seperatorlocation==-1) { returnvalue=urlstring.substr(querystringlength+1); } else { returnvalue=urlstring.substring(querystringlength+1,seperatorlocation); } } return returnvalue; }