本文主要是介绍那些年,哥私藏的源代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.英文截断
p{height: 24px;overflow: hidden;width: 100%;word-wrap:break-word;word-break:break-all;}
2.css reset
/*reset*/
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, pre, a, code, del, em, img, strong, sub, sup, b, u, i, dl, dt, dd, ol, ul, li, fieldset, form, label, table, tbody, tfoot, thead, tr, th, td{ margin:0; padding:0; border:0; outline:0; font-size: 100%; vertical-align: baseline; }
table { border-collapse:collapse; border-spacing:0px; }
ol, ul {list-style:none;}
th,td{vertical-align:middle;}
3.clearfix 清除浮动
.clearfix:after{content:'.';display:block;height:0;clear:both;overflow:hidden;}
.clearfix{*zoom:1;}
4.body default
body {margin:0px auto; font-family:"宋体",Arial,Helvetica,sans-serif; font-size:12px;background:#f0f1f1;}
html,html body{_background-image:url(about:blank);_background-attachment:fixed;}
5.a样式
a{ text-decoration:none; color:#333333; }
a:hover{color:#E53434 !important; text-decoration:underline;}
a:hover img{text-decoration:none;}
6.来个css整套的(www.meilele.com 版权所有)
/*reset*/
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, pre, a, code, del, em, img, strong, sub, sup, b, u, i, dl, dt, dd, ol, ul, li, fieldset, form, label, table, tbody, tfoot, thead, tr, th, td{ margin:0; padding:0; border:0; outline:0; font-size: 100%; vertical-align: baseline; }
table { border-collapse:collapse; border-spacing:0px; }
ol, ul {list-style:none;}
th,td{vertical-align:middle;}
/*common*/
.Left { float:left; }
.Right { float:right; }
.r{text-align:right!important;}
.c{text-align:center!important;}
.l{text-align:left!important;}
a{ text-decoration:none; color:#333333; }
.red, a.red { color:#e53434; }
.gray, a.gray { color:#787878; }
.orange, a.orange { color:#F60; }
.black, a.black { color:#333; }
.white,a.white{ color:#FFF;}
.scarlet,a.scarlet{ color:#E53434;}
a:hover{color:#E53434 !important; text-decoration:underline;}
a:hover img{text-decoration:none;}
.none{ display:none;}
.clearfix:after{content:'.';display:block;height:0;clear:both;overflow:hidden;}
.clearfix{*zoom:1;}
.clear{clear:both }
.center{text-align:center;}
.w{width:980px; margin-left:auto;margin-right:auto;}
.height5 { height:5px; line-height:1px; }
.height10 { height:10px; line-height:1px; }
.height15 { height:15px; }
.height20 { height:20px; }
.height25 { height:25px; }
.height30 { height:30px; }
.height40 { height:40px; }
.mt10{margin-top:10px;}
.mt15{margin-top:15px;}
.mb10{margin-bottom:10px;}
.mt20{margin-top:20px;}
.inline_block { display:inline-block; }
.bold { font-weight:bold; }
.f14 { font-size:14px; }
.f16 { font-size:16px; }
.fline { text-decoration:line-through }
.uline{ text-decoration:underline;}
.yen{font-family:Arial;}
.pointer { cursor:pointer; }
.MLL_lazy{ border:none; color:#FFF; background:url(../zxwimg20121022/ajax-loader.gif) center center no-repeat; overflow:hidden; border:1px solid #999; padding:0px; line-height:1px; font-size:1px;}
.indent{ text-indent:-9999px; overflow:hidden;}
.w970{width:970px; margin-left:auto;margin-right:auto;}
img{background:#eee;overflow:hidden;vertical-align:top;}
.yahei{font-family: 'Microsoft YaHei',微软雅黑}body {margin:0px auto; font-family:"宋体",Arial,Helvetica,sans-serif; font-size:12px;background:#f0f1f1;}
html,html body{_background-image:url(about:blank);_background-attachment:fixed;}
7.操作cookie
/*** 设置cookie* @param {string} name key* @param {string} value value* @param {string/number} Days 有效期,或者'session'* @param {string} domain 作用域。默认meilele.com*/setCookie : function (name, value, Days, domain ,path) {Days = Days || 360;path = path || '/';domain = domain?";domain="+domain:";domain=meilele.com";var expDay = new Date();expDay.setTime(expDay.getTime() + parseInt(Days) * 24 * 60 * 60 * 1000);document.cookie = name + "=" + encodeURIComponent(value) + (Days == "session" ? "" : ";expires=" + expDay.toGMTString()) + domain + ";path="+path;},/** 获取cookie* @param {string} name key* @return {string} cookie值*/getCookie : function (name) {var cookieValue;if (document.cookie && document.cookie != '') {var cookies = document.cookie.split(';');var cookieLength = cookies.length;for (var i = 0; i < cookieLength; i++) {var cookie = cookies[i].replace(/(^\s*)|(\s*$)/g, "");if (cookie.substring(0, name.length + 1) == (name + '=')) {cookieValue = decodeURIComponent(cookie.substring(name.length + 1));break;}}}return cookieValue;},
8,设置为首页,加入收藏
/** @设为首页*/setHome : function(){var url = window.location.href;try {obj.style.behavior = 'url(#default#homepage)';obj.setHomePage(url);}catch(e) {if (window.netscape) {try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}catch(e) {alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");}var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);prefs.setCharPref('browser.startup.homepage', url);}}},/** @加入收藏*/addFavorites : 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进行添加");}}},
//将json格式数据转化为字符串jsonToString: function( json ) {var strTemp = [];if ( typeof json != "object" ) {return;}for ( var k in json ) {strTemp.push( '\"' + k + '\":' + '\"' + json[k] + '\"' );}return "{" + strTemp.join(",") + "}";},
10.设置透明度
/** @设置透明度* @param: target {objext} 目标对象* @param: value {number} 透明度值*/setOpacity : function( target, value ){if( document.documentElement.filters ){target.style.filter = "alpha(opacity="+value+")";}else{target.style.opacity = value/100;}},
11.元素距离顶部偏移量
offsetTop:function (obj) {var offsetParent = obj;if(!obj)return 0;var top = 0;while (offsetParent != null && offsetParent != document.body) {top += offsetParent.offsetTop;offsetParent = offsetParent.offsetParent;}return top;},
12.取消事件默认行为
if ( e && e.preventDefault ){ e.preventDefault();} else { window.event.returnValue = false;}
13.阻止事件冒泡
function stopPP(e){var evt = e|| window.event;//IE用cancelBubble=true来阻止而FF下需要用stopPropagation方法evt.stopPropagation ?evt.stopPropagation() : (evt.cancelBubble=true);}
14.clearfix
/*clearfix*/
.clearfix:before, .clearfix:after {display: table;line-height: 0;content: "";
}.clearfix:after {clear: both;
}.clearfix:after {content: ".";display: block;height: 0;clear: both;visibility: hidden;
}
.clearfix {*zoom:1;
}
15.img hover
/*img hover*/
img:hover {opacity: 0.85;
}
img {-ms-interpolation-mode: bicubic;/*ie7 专用,消除图片锯齿*/-webkit-transition: all 200ms ease-in;-moz-transition: all 200ms ease-in;-o-transition: all 200ms ease-in;transition: all 200ms ease-in;
}
16,jquery 同步控制
$.ajaxSetup({ async : false
});
$.ajaxSetup({ async : true });
这篇关于那些年,哥私藏的源代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!