JS+C33 间隔无缝滚动适合【图片Banner+文字滚动】
- <style>
- #elUl{ border:1px #000 solid; position:absolute; right:10px; top:0;}
- @-webkit-keyframes scro{from{top:0;}to{top:-30px;}}
- </style>
- <script type="text/javascript">
- window.onload=function(){
- var elUl=document.getElementById("elUl");
- //alert(elUl)
- if(elUl!=null){
- setInterval(function(){
- elUl.style.WebkitAnimation='scro 0.5s linear forwards';
- elUl.style.MozAnimation="scro 0.5s linear forwards";
- elUl.style.msAnimation='scro 0.5s linear forwards';
- elUl.style.OAnimation='scro 0.5s linear forwards';
- elUl.style.animation='scro 0.5s linear forwards';
- //oUl.style.transform='translateY(-100px)';
- //oUl.addEventListener("webkitAnimationEnd",end);
- if(elUl.offsetTop<=-30){
- elUl.style.WebkitAnimation='';
- var b=elUl.children[0];
- elUl.appendChild(b);
- //clearInterval(timer)
- }
- },3000);
- }
- }
- </script>
注明:elUl.offsetTop 是检测DOM距离顶部的距离,如果符合条件自动清除CSS3动画,如果左右滚动Banner可以使用:elUl.offsetLeft
JS 事件委托
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>js性能优化</title>
- <style>
- #list{ border:1px solid #000;}
- </style>
- </head>
- <body id='list'>
- <ul >
- <li>精通css</li>
- <li>精通js</li>
- <li>精通html</li>
- ......
- </ul>
- </body>
- </html>
- <script type="text/javascript">
- (function(){
- var a=document.getElementById('list');
- a.addEventListener('click',function(e){
- var b = e.target;
- alert(b.innerHTML);
- },false);
- })();
- </script>
JS批量变量转换成图片模版+JS批量遍历表情符号并进行替换
- var Expression = (function () {
- return {
- images: [{className:'face_1',text: '微笑'},
- {className:'face_2',text: '害羞'},
- {className:'face_3',text: '喜欢'},
- {className:'face_4',text: '快哭了'},
- {className:'face_5',text: '爱心'},
- {className:'face_6',text: '擦汗'},{className:'face_7',text: '愤怒'},
- {className:'face_8',text: '可爱'},{className:'face_9',text: '小可怜'},{className:'face_10',text: '尴尬'},{className:'face_11',text: '呲牙'},
- {className:'face_12',text: '红唇'},{className:'face_13',text: '难过'},{className:'face_14',text: '亲亲'},{className:'face_15',text: '委屈'},
- {className:'face_16',text: '疑惑'},{className:'face_17',text: '拥抱'},{className:'face_18',text: '再见'},{className:'face_19',text: '咖啡'},
- {className:'face_20',text: '礼物'},{className:'face_21',text: '玫瑰'}],
- initBox: function ($selector) {
- $.each(Expression.images, function () {
- if(this.className=="face_1" || this.className=="face_11"){
- return true;
- }
- var li = $('<li></li>').data('express', this.text).append('<i class="icon '+this.className +'"></i>');
- $selector.append(li);
- });
- },
- replaceHtml: function ($selector) {
- var html = $selector.html();
- $.each(Expression.images, function () {
- var re = new RegExp("\\["+this.text+"\\]","g");
- html = html.replace(re, '<i class="icon ' + this.className + '"></i>');
- });
- $selector.html(html);
- }
- }
- })();
- $(function () {
- $('body').on("tap", '[data-express]', function () {
- var txt = $(this).data('express'), text = $('textarea');
- text.val(text.val() + '[' + txt + ']');
- var len = text.val().length;
- $('#provide').text(len + "/240字");
- text.focus();
- });
- });
- Expression.replaceHtml($('#chat_list'));
- Expression.initBox($('#face'))
服务器端判断客户端浏览器类型
如何判断微信内置浏览器,首先需要获取微信内置浏览器的User Agent,经过在 iPhone 上微信的浏览器的检测,它的 User Agent 是:
Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B329 MicroMessenger/5.0.1
所以通过识别 MicroMessenger 这个关键字来确定是否微信内置的浏览器了。
JAVA 判断是否微信浏览器
- <%
- String ua=((HttpServletRequest) request).getHeader("user-agent").toLowerCase();
- if (ua.indexOf("micromessenger") > 0) {// 是微信浏览器
- validation = true;
- }
- %>
- /***************************************************
- * 判断浏览器类型是否是IE,是则返回true,不是返回false
- * ServletActionContext是struts2上下文对象
- * @return boolean
- **************************************************/
- public static boolean isIE(){
- return ServletActionContext.getRequest().getHeader( "USER-AGENT" ).toLowerCase().indexOf( "msie" )>0?true:false ;
- }
方案一:正则表达式
通过观察规律,得出以下表达式:
- ;\s?([^;]+?)\s?(Build)?/
Java代码:
- Pattern pattern = Pattern.compile(";\\s?(\\S*?\\s?\\S*?)\\s?(Build)?/");
- Matcher matcher = pattern.matcher(userAgent);
- String model = null;
- if (matcher.find()) {
- model = matcher.group(1).trim();
- log.debug("通过userAgent解析出机型:" + model);
- }
以下为部分UserAgent,供测试,可以直接在EditPlus里验证。
Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; R8007 Build/JLS36C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; R8007 Build/JLS36C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 V1_AND_SQ_5.0.0_146_YYB_D QQ/5.0.0.2215
Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; SM-N9009 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.3 Mobile Safari/537.36
Mozilla/5.0 (Linux; Android 4.2.2; zh-cn; SCH-I959 Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Version/1.0 Chrome/18.0.1025.308 Mobile Safari/535.19
Mozilla/5.0 (Linux; U; Android 4.3; zh-CN; SM-N9009 Build/JSS15J) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.2.467 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 4.1.2; zh-CN; Coolpad 5891 Build/JZO54K) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.3.478 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 4.1.2; zh-cn; Coolpad 5891 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 V1_AND_SQ_5.0.0_146_YYB2_D QQ/5.0.0.2215
Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53
Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257 QQ/5.0.0.165
Mozilla/5.0 (Linux; Android 4.3; zh-cn; SAMSUNG-GT-I9308_TD/1.0 Android/4.3 Release/11.15.2013 Browser/AppleWebKit534.30 Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 SogouMSE,SogouMobileBrowser/3.2.3
Mozilla/5.0 (Linux; U; Android 4.2.2; zh-cn; SCH-I959 Build/JDQ39) AppleWebKit/534.24 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.24 T5/2.0 baidubrowser/5.0.3.10 (Baidu; P1 4.2.2)
Mozilla/5.0 (Linux; U; Android 4.2.2; zh-cn; SCH-I959 Build/JDQ39) AppleWebKit/534.24 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.24 T5/2.0
Mozilla/5.0 (Linux; Android 4.3; SM-N9009 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.117 Mobile Safari/537.36 OPR/24.0.1565.82529
Mozilla/5.0 (Linux; U; Android 4.4.4; zh-CN; Nexus 4 Build/KTU84P) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.2.467 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HUAWEI C8825D Build/HuaweiC8825D) AppleWebKit/534.24 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.24 T5/2.0 baidubrowser/5.2.3.0 (Baidu; P1 4.0.4)
Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HUAWEI C8825D Build/HuaweiC8825D) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.3 Mobile Safari/537.36
Mozilla/5.0 (Linux; Android 4.0.4; HUAWEI C8825D Build/HuaweiC8825D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.117 Mobile Safari/537.36
Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HUAWEI C8825D Build/HuaweiC8825D) AppleWebKit/535.19 (KHTML, like Gecko) Version/4.0 LieBaoFast/2.12.0 Mobile Safari/535.19
Opera/9.80 (Android; Opera Mini/7.0.31907/34.2499; U; zh) Presto/2.8.119 Version/11.10
Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HW-HUAWEI_C8825D/C8825DV100R001C92B943SP01; 480*800; CTC/2.0) AppleWebKit/534.30 Mobile Safari/534.30
Mozilla/5.0 (Linux; U; Android 4.4.2; zh-CN; SGP521 Build/17.1.2.A.0.314) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.2.467 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; Android 4.4.2; SGP521 Build/17.1.2.A.0.314) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.117 Safari/537.36
Mozilla/5.0 (Linux; U; Android 4.0.4; zh-CN; HUAWEI C8825D Build/HuaweiC8825D) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.8.5.442 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Mozilla/5.0 (Linux; Android 4.4.2; zh-cn; SAMSUNG-SM-N9009 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36
Mozilla/5.0 (Linux; U; Android 4.2.2; zh-CN; HTC HTL22 Build/JDQ39) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.2.467 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; Android 4.3; SM-N9009 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.117 Mobile Safari/537.36
Mozilla/5.0 (Linux; U; Android 4.2.1; zh-cn; AMOI A920W Build/JOP40D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Mozilla/5.0 (Linux; Android 4.3; SM-N9009 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.135 Mobile Safari/537.36
Mozilla/5.0 (Linux; U; Android 4.1.1; zh-CN; GT-N7100 Build/JRO03C) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.2.467 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; R8007 Build/JLS36C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Huawei U8800 Android 2.3.3 Baidu 2.2 Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn) AppleWebKit/530.17 (KHTML, like Gecko) FlyFlow/2.2 Version/4.0 Mobile Safari/530.17 有用(0)
Huawei U8800 Android 2.3.3 UC 8.7 Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) UC AppleWebKit/534.31 (KHTML, like Gecko) Mobile Safari/534.31 有用(0)
Meizu MX M031 Android 4.0.3 Chrome 18 Mozilla/5.0 (Linux; Android 4.0.3; M031 Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19 有用(0)
Meizu MX M031 Android 4.0.3 Opera 12.1 Opera/9.80 (Android 4.0.3; Linux; Opera Mobi/ADR-1210241511) Presto/2.11.355 Version/12.10 有用(0)
Meizu MX M031 Android 4.0.3 -built-in * Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 有用(0)
Meizu MX M031 Android 4.0.3 Baidu 2.2 Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn) AppleWebKit/530.17 (KHTML, like Gecko) FlyFlow/2.2 Version/4.0 Mobile Safari/530.17 有用(0)
Meizu MX M031 Android 4.0.3 UC 8.7 Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) UC AppleWebKit/534.31 (KHTML, like Gecko) Mobile Safari/534.31 有用(0)
Meizu M9 Android 4.0.3 QQ 3.7 MQQBrowser/3.7/Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M9 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 Normal Mode 有用(0)
Meizu M9 Android 4.0.3 QQ 3.5 MQQBrowser/3.5/Adr (Linux; U; 4.0.3; zh-cn; M9 Build/Flyme 1.0.1;640*960) Speed Mode 有用(0)
Meizu M9 Android 4.0.3 -built-in * Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M9 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 有用(0)
Meizu M9 Android 4.0.3 QQ 3.5 MQQBrowser/3.5/Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M9 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 Normal Mode 有用(0)
Meizu MX M031 Android 4.0.3 Maxthon 2.7 Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 有用(0)
Huawei U8800 Android 2.3.3 Maxthon 2.7 Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 有用(0)
Huawei U8800 Android 2.3.3 QQ 3.7 MQQBrowser/3.7/Adr (Linux; U; 2.3.5; zh-cn; U8800 Build/U8800V100R001C00B528G002;480*800) Speed Mode 有用(0)
Huawei U8800 Android 2.3.3 Dolphin 9.1 Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 有用(0)
Huawei U8800 Android 2.3.3 QQ 3.7 MQQBrowser/3.7/Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 Normal Mode 有用(0)
Huawei U8800 Android 2.3.3 -built-in * Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Samsung P6200(GALAXY Tab) Android 3.2 -built-in * Mozilla/5.0 (Linux; U; Android 3.2; zh-cn; GT-P6200 Build/HTJ85B) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13 有用(0)
Huawei U8800 Android 2.3.3 Maxthon 4.0 Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 有用(0)
Meizu MX M031 Android 4.0.3 Baidu 2.3 Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) AppleWebKit/530.17 (KHTML, like Gecko) FlyFlow/2.3 Version/4.0 Mobile Safari/530.17 baidubrowser/023_1.41.3.2_diordna_069_046/uzieM_51_3.0.4_130M/1200a/963E77C7DAC3FA587DF3A7798517939D%7C408994110686468/1 有用(0)
Huawei U8800 Android 2.3.3 Baidu 2.3 Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/530.17 (KHTML, like Gecko) FlyFlow/2.3 Version/4.0 Mobile Safari/530.17 baidubrowser/042_1.6.3.2_diordna_008_084/IEWAUH_01_5.3.2_0088U/1001a/BE44DF7FABA8768B2A1B1E93C4BAD478%7C898293140340353/1 有用(0)
Huawei U8800 Android 2.3.3 Dolphin 9.2 Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 有用(0)
HTC S720e(One X) Android 4.0.3 -built-in * Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HTC S720e Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 有用(1)
HTC S720e(One X) Android 4.0.3 UC 8.7 Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HTC S720e Build/IMM76D) UC AppleWebKit/534.31 (KHTML, like Gecko) Mobile Safari/534.31 有用(0)
Meizu MX M031 Android 4.0.3 Dolphin Min 2.3 Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 有用(0)
Meizu MX M031 Android 4.0.3 QQ 4.0 MQQBrowser/4.0/Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) AppleWebKit/533.1 (KHTML, like Gecko) Mobile Safari/533.1 有用(0)
Meizu M9 Android 4.0.3 QQ 3.7 MQQBrowser/3.7/Adr (Linux; U; 4.0.3; zh-cn; M9 Build/Flyme 1.0.1;640*960)
Meizu MX2 M040 Android 4.1 UC 9.4 Mozilla/5.0 (Linux; U; Android 4.1.1; zh-CN; M040 Build/JRO03H) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.4.1.362 U3/0.8.0 Mobile Safari/533.1 有用(0)
Meizu MX2 M040 Android 4.1 Chrome 31 Mozilla/5.0 (Linux; Android 4.1.1; M040 Build/JRO03H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36 有用(0)
Meizu MX2 M040 Android 4.1 猎豹 2.8 Mozilla/5.0 (Linux; Android 4.1.1; M040 Build/JRO03H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.64 Mobile Safari/537.36 有用(0)
Meizu MX2 M040 Android 4.1 Baidu 4.1 Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; M040 Build/JRO03H) AppleWebKit/534.24 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.24 T5/2.0 baidubrowser/4.2.4.0 (Baidu; P1 4.1.1) 有用(0)
Meizu MX M031 Android 4.1 -built-in * Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; M031 Build/JRO03H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 有用(1)
Meizu MX M031 Android 4.1 UC 8.8 Mozilla/5.0 (Linux; U; Android 4.1.1; zh-CN; M031 Build/JRO03H) AppleWebKit/534.31 (KHTML, like Gecko) UCBrowser/8.8.3.278 U3/0.8.0 Mobile Safari/534.31 有用(0)
Meizu MX2 M040 Android 4.1 QQ 4.1 Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; M040 Build/JRO03H) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/4.1 Mobile Safari/533.1 有用(0)
Meizu MX2 M040 Android 4.1 -built-in * Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; M040 Build/JRO03H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 有用(2)
Samsung P6200(GALAXY Tab) Android 3.2 QQ HD 2.1 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 有用(0)
Samsung P6200(GALAXY Tab) Android 3.2 UC HD 2.3 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3) AppleWebKit/534.31 (KHTML, like Gecko) Chrome/17.0.558.0 Safari/534.31 UCBrowser/2.3.1.257
通过验证,成功率95%以上。
PHP 判断是否微信浏览器
- function is_weixin(){
- if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !==false){
- return true;
- }
- return false;
- }
JavaScript判断是否微信浏览器
- function is_weixin(){
- var ua=navigator.userAgent.toLowerCase();
- if(ua.match(/MicroMessenger/i)=="micromessenger"){
- return true;
- }else{
- return false;
- }
- }
JAVA 使用转义符替换字符串/ JAVA 构建HTTP跨越接口
1. 调用广告平台要对超链接字符串局部进行替换,如下:
2. 对广告HTTP接口需要改造成支持跨越,在回调方法内部插入JSON数据,回调名:Jsoncallback 如下:
- @RequestParam(value = "Jsoncallback", required = true) String jsonCallBack,
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("userList", userList);
- String strResult = jsonCallBack+"("+jsonObject.toString()+")";
- return strResult;
JS获取浏览器窗口大小 获取屏幕,浏览器,网页高度宽度
网页可见区域宽:document.body.clientWidth
- 实现代码
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>请调整浏览器窗口</title>
- <meta http-equiv="content-type" content="text/html; charset=gb2312">
- </head>
- <body>
- <h2 align="center">请调整浏览器窗口大小</h2><hr>
- <form action="#" method="get" name="form1" id="form1">
- <!--显示浏览器窗口的实际尺寸-->
- 浏览器窗口 的 实际高度: <input type="text" name="availHeight" size="4"><br>
- 浏览器窗口 的 实际宽度: <input type="text" name="availWidth" size="4"><br>
- </form>
- <script type="text/javascript">
- <!--
- var winWidth = 0;
- var winHeight = 0;
- function findDimensions() //函数:获取尺寸
- {
- //获取窗口宽度
- if (window.innerWidth)
- winWidth = window.innerWidth;
- else if ((document.body) && (document.body.clientWidth))
- winWidth = document.body.clientWidth;
- //获取窗口高度
- if (window.innerHeight)
- winHeight = window.innerHeight;
- else if ((document.body) && (document.body.clientHeight))
- winHeight = document.body.clientHeight;
- //通过深入Document内部对body进行检测,获取窗口大小
- if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
- {
- winHeight = document.documentElement.clientHeight;
- winWidth = document.documentElement.clientWidth;
- }
- //结果输出至两个文本框
- document.form1.availHeight.value= winHeight;
- document.form1.availWidth.value= winWidth;
- }
- findDimensions();
- //调用函数,获取数值
- window.onresize=findDimensions;
- //-->
- </script>
- </body>
- </html>
原生JS实现AJAX、JSONP及DOM加载完成事件
- ajax({
- url:"http://192.168.66.90:8080/php/test5.php",
- type:"POST",
- data:{GUID:"288350897",subFlag:"1"},
- dataType:"jsonp",
- callback:"Jsoncallback",
- success:function(data){
- if(data.sex==0){
- var userSex="帅哥";
- }
- if(data.sex==1){
- var userSex="美女";
- }
- if(data.switch==0){
- $(".Mbox .mailInfo .text_").html('<span style="color:#fbff83">'+data.mailInfo+'</span>封'+userSex+'来信');
- $(".Mbox").addClass("ty");
- mbox.addEventListener("webkitAnimationEnd",function(){ //动画结束时事件
- var timer=setInterval(function(){
- if(mbox.offsetTop==-60){
- mbox.className='Mbox tyy';
- clearInterval(timer)
- }
- },1000)
- },false);
- }
- //alert(data.switch)
- },
- fail:function(status){
- // 此处放失败后执行的代码
- }
- });
- /***********************************
- 公共ajax方法支持跨越请求
- ************************************/
- function ajax(options) {
- options = options||{};
- if (!options.url||!options.callback){
- throw new Error("参数不合法");
- }
- //创建 script 标签并加入到页面中
- var callbackName=('jsonp_'+Math.random()).replace(".","");
- var oHead=document.getElementsByTagName('head')[0];
- options.data[options.callback]=callbackName;
- var params=formatParams(options.data);
- var oS=document.createElement('script');
- oHead.appendChild(oS);
- //创建jsonp回调函数
- window[callbackName]=function(json){
- oHead.removeChild(oS);
- clearTimeout(oS.timer);
- window[callbackName]=null;
- options.success&&options.success(json);
- };
- //发送请求
- oS.src=options.url+'?'+params;
- //超时处理
- if(options.time){
- oS.timer=setTimeout(function(){
- window[callbackName]=null;
- oHead.removeChild(oS);
- options.fail&&options.fail({message:"超时"});
- },time);
- }
- };
- //格式化参数
- function formatParams(data){
- var arr=[];
- for(var name in data){
- arr.push(encodeURIComponent(name)+"="+encodeURIComponent(data[name]));
- }
- return arr.join('&');
- }
jQuery制作从左到右从新排列内容动画特效
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>jQuery制作从左到右从新排列内容动画特效</title>
- <style>
- body{ height: 3000px; padding: 0; margin: 0; }
- div{ background: #000; margin: 20px 0; width: 100px; height: 30px; color: #fff; line-height: 30px; text-align: center; }
- </style>
- </head>
- <script src="js/jquery.min.js"></script>
- <body>
- <div class="op1">111</div>
- <div class="op2">222</div>
- <div class="op3">333</div>
- <div class="op4">444</div>
- <div class="op5">555</div>
- <div class="op6">666</div>
- <div class="op7">777</div>
- <input type="button" value="stop!!!" />
- <script>
- var _width = ($(document).width() - $('div').width()) + "px";
- var animateList=[
- function(){ $('.op1').delay(500).animate({marginLeft:_width},500,queueList); },
- function(){ $('.op2').delay(300).animate({marginLeft:_width},500,queueList); },
- function(){ $('.op3').delay(300).animate({marginLeft:_width},500,queueList); },
- function(){ $('.op4').delay(700).animate({marginLeft:_width},500,queueList); },
- function(){ $('.op5').delay(300).animate({marginLeft:_width},500,queueList); },
- function(){ $('.op6').delay(200).animate({marginLeft:_width},500,queueList); },
- function(){ $('.op7').delay(300).animate({marginLeft:_width},500,function(){ alert('动画队列结束'); } );}
- ];
- $(document).queue('_queueList',animateList);
- var queueList=function(){
- $(document).dequeue('_queueList');
- };
- queueList();
- $(':button').click(function(){
- $(document).clearQueue('_queueList');
- });
- </script>
- </body>
- </html>
Linux复制本地文件到远程
scp -r /www/next.youyuan.com2 root@192.168.3.162:/www/
JSON 常用类型处理
- var str='{"weatherinfo": [{"city": "北京","city_en": "beijing", "cityid": "101130101","date": "","date_y": "2014年1月23日", "wind6": "微风"}]}';
- var obj=JSON.parse(str);
- var yy=JSON.stringify(obj);
- alert(yy)