/*自定义函数库@dragonshen*/ $(function(){ //禁用右键、文本选择功能、复制按键、刷新 $.fn.isCopy=function(){ $(document).bind("contextmenu",function(){return false;}); $(document).bind("selectstart",function(){return false;}); $(document).keydown(function(){ if(event.keyCode==116){//屏蔽F5刷新键 event.keyCode=0; event.returnValue=false; } return key(arguments[0]) }); }; //$(this).isCopy(); /*图片错误加载默认图片*/ $.fn.errorImg=function(i){ $(this).error(function(e) { if(i==0){ $(this).attr('src','data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==') .css({'background':'url(skin/images/logo.jpg) no-repeat center center #f0f0f0','border':'#ddd 1px solid'}).fadeIn("slow"); }else{ $(this).attr('src','data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==') .css({'background':'url(skin/images/logo.jpg) no-repeat center center #f0f0f0','border':'#ddd 1px solid','width':$(this).width()-2,'height':$(this).height()-2}).fadeIn("slow"); } }); }; $("img").errorImg(0); /*文本框得到焦点则清空文本,失去焦点则显示文本*/ $.fn.onfocus=function(){ $(this).focus(function(){ if($(this).val()==$(this).attr("tips")){ $(this).val("");} }).focusout(function(){ if($(this).val()==$(this).attr("tips") || $(this).val()==""){ $(this).val($(this).attr("tips"));} }); }; $(".txt").onfocus(); /*鼠标悬停 图片透明半透明*/ $.fn.transImg=function(i){ var _self=$(this); if(i==0){ _self.find("img").css("opacity","0.65").hover( function(){ $(this).stop().animate({opacity: '1'},300); }, function(){ $(this).stop().animate({opacity: '0.65'},200);} ) }else{ _self.mouseenter(function(){ var opacity=0.65; $(this).find("img").css("opacity",opacity); $(this).find("img").hover( function(){ $(this).stop().animate({opacity: '1'},300); }, function(){ $(this).stop().animate({opacity: opacity},200);} ) }).mouseleave( function(){ $(this).find("img").stop().css("opacity","1") }) } }; $(".Animg").transImg(1); /*导航下拉菜单*/ $.fn.pullDownlMenu=function(){ $(this).each(function() { var m = 180; if($(this).children("ol").size()){ $(this).hover( function(){ $(this).children("a").addClass('on'); $(this).children('ol').stop(false, true).slideDown(m); }, function(){ $(this).children("a").removeClass('on'); $(this).children('ol').stop(false, true).slideUp(m); } ) } }); }; //$(".navi ul li").pullDownlMenu(); /*导航位置固定 如 kumic导航*/ $.fn.float=function(){ //获取要定位元素距离浏览器顶部的距离 var _touch=$(this); var navH = _touch.offset().top; //滚动条事件 $(window).scroll(function(){ //获取滚动条的滑动距离 var scroH = $(this).scrollTop(); //滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离,就固定,反之就不固定 if(scroH>navH){ _touch.addClass("floatop"); }else if(scroH<=navH){ _touch.removeClass("floatop"); } console.log(scroH==navH); }); }; //$(".header").float(); /*加入收藏*/ $.fn.addfavorite=function(){ $(this).click(function(){ var sURL=window.location.href; var sTitle=document.title; try { window.external.addFavorite(sURL, sTitle); }catch(e){ try { window.sidebar.addPanel(sTitle, sURL, ""); }catch(e) { alert("加入收藏失败,请使用Ctrl+D进行添加"); } } }); }; $("#favorite").addfavorite(); /*打印*/ $.fn.printpage=function(){ $(this).click(function(){ window.print(); }) }; $("#print").printpage(); /*获取get的值**调用方式$.get("name")*/ $.extend({ get:function(name){ var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } }); /*验证邮件格式**调用方式$.isEmailFormat("obj")*/ $.extend({ isEmailFormat:function(obj){ reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/; if(!reg.test(obj)) { return false }else{ return true; } } }); /*鼠标经过函数**调用方式$(divString).isSelected();*/ $.fn.isSelected=function(type){ var _seft=$(this); _seft.each(function() { switch(type){ case 1: /*鼠标经过*/ $(this).hover( function(){ $(this).addClass('select');}, function(){$(this).removeClass('select')} ); break; case 2: /*点击选中,再次点击不选中*/ $(this).click( function(){ if($(this).attr("class").indexOf("select")==-1){ $(this).addClass('select'); }else{ $(this).removeClass('select'); } } ); break; case 3: /*点击同时只能选中一个*/ $(this).click( function(){ $(this).addClass('select').siblings().removeClass("select"); } ); break; } }); } $("divselect").isSelected(1); /*抖动效果*/ $.fn.shake=function(){ $(this).hover( function(){ var s=20; /*单次颤抖时间 单位微秒*/ var j=3; /*抖动次数*/ var r_t={"margin-top":"-1px","margin-left":"1"}; /*右上*/ var r_b={"margin-top":"1px","margin-left":"1"}; /*右下*/ var l_b={"margin-top":"1px","margin-left":"-1"}; /*左下*/ var l_t={"margin-top":"-1px","margin-left":"-1"}; /*左上*/ var doz={ sk:function(divclass){ divclass.animate(r_t,s).animate(r_b,s).animate(l_b,s).animate(l_t,s); }}; $(this).css({"display":"inline-block","*display":"inline","*zoom":"1"}); for(i=1;i<=j;i++){doz.sk($(this));} $(this).animate({"margin":"0 0 0 0"},s); },function(){$(this).animate({"margin":"0 0 0 0"},0).stop();} ); }; //$(".navi ul li a").shake(); //图片居中放大 $.fn.enlarge=function(){ var img=$(this); var _width=img.width(); var _height=img.height(); var j=1.2; /*放大倍数*/ var s=0.5; /*放大速度,单位秒*/ $(this).hover( function(){ var par=$(this).parent().attr("class"); if(par!="wp"){ $(this).wrap('');} $(this).parent().css({"width":_width,"height":_height,"overflow":"hidden"}) var _parm={"width":_width*j,"height":_height*j,"margin-top":-(_height*(j-1)*0.5),"margin-left":-_width*(j-1)*0.5}; $(this).stop().animate(_parm,s*1000); }, function(){ var _parm2={"width":_width,"height":_height,"margin-top":0,"margin-left":0}; $(this).stop().animate(_parm2,s*1000)/*.unwrap()*/; } ); } //$(".product_tx ul li .imge img").enlarge(); /*网站未接尾款,上传测试阶段,显示提示*/ $.fn.demoTest=function(s){ var s=10; /*进入页面,等待s分钟开始出现提醒,单位秒*/ setTimeout(function (){ $("body").append(' '); },s*1000); $("#NoAccount .box i a").live("click",function(){ $(this).parent().parent().parent().remove();}); }; //$(this).demoTest(10); //禁止输入法 $.fn.disIme=function(){ $(this).keydown(function(e) { if ($.browser.msie) { // 判断浏览器 if (((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 8)) { // 判断键值 return true; } else { return false; } } else { if (((e.which > 47) && (e.which < 58)) || (e.which == 8) || (event.keyCode == 17)) { return true; } else { return false; } } }).focus(function() { this.style.imeMode = 'disabled'; // 禁用输入法,禁止输入中文字符 }); } $(".rmb").disIme(); })