本文為大家總結了一下在我們日常開發微信專案的過程中,常常需要用到的一些js方法,都是些使用頻率很高,而且非常簡單的方法,這裡推薦給大家。
1.網頁圖片集合左右滑動查看圖片,如下範例:
js效果
程式碼如下:
var pictures = []; angular.forEach(pitctures,function(k,i){ pictures[i] = k.imgPath; }); $scope.previewPics = function(currentUrl){ if (typeof window.WeixinJSBridge != 'undefined') { //微信图片集查看 WeixinJSBridge.invoke('imagePreview', { 'current':currentUrl, //当前地址 'urls':pictures //组 }); } else { alert( "请在微信中查看", null, function () {}); } }
頁面元素:
程式碼如下:
<p class="infoPics"> <p class="picImg" ng-repeat="picture in info.infoContent.pitctures"> <img ng-src="{{picture.imgPath}}" ng-click="previewPics(picture.imgPath)"> </p> </p>
2.微信視窗關閉事件
WeixinJSBridge.invoke('closeWindow',{},function(res){ //alert(res.err_msg); });
var lineLink = 'http://../..', imgUrl = 'http://../..', shareTitle = '页面标题', descContent='内容简介', appid = ''; //判断是否支持微信js if(typeof WeixinJsBridge == 'undefined'){ if(document.addEventListener){ document.addEventListener('WeixinJsBridgeReady',onBridgeReady,false); }else if(document.attachEvent){ document.attachEvent('WeixinJsBridgeReady',onBridgeReady); document.attachEvent('onWeixinJsBridgeReady',onBridgeReady); } }else{ onBridgeReady(); } function onBridgeReady (){ WeixinJsBridgeReady.on('menu:share:appmessage',wx_shareFriend);//分享朋友 WeixinJsBridgeReady.on('menu:share:timeline',wx_shareTimeline);//分享到朋友圈 WeixinJsBridgeReady.on('menu:share:weibo',wx_shareWeibo);//分享朋友 } function wx_shareFriend (){ WeixinJsBridge.invoke('sendAppMessage',{ "appid":appid, "img_url":imgurl, "img_width":'640', "img_height":'500', "link":lineLink, "desc":descContent, "title":shareTitle },function(res){ console.log(res.err_msg); } }); } function wx_shareTimeline (){ WeixinJsBridge.invoke('sendTimeline',{ "appid":appid, "img_url":imgurl, "img_width":'640', "img_height":'500', "link":lineLink, "desc":descContent, "title":shareTitle },function(res){ console.log(res.err_msg); } }) } function wx_shareWeibo (){ WeixinJsBridge.invoke('sendWeibo',{ "appid":appid, "img_url":imgurl, "img_width":'640', "img_height":'500', "link":lineLink, "desc":descContent, "title":shareTitle },function(res){ console.log(res.err_msg); } }) }
WeixinJsBridge.call('hideOptionMenu');
WeixinJsBridge.call('hideToolbar');
WeixinJsBridge.invoke('getNetworkType',{},function(e){ console.log(e.err_msg); })
WeixinJsBridge.invoke('disabledShare',{},function(e){ })
// true or false var flag = WeixinApi.openInWeixin();
以上是微信開發中常用的js方法匯總的詳細內容。更多資訊請關注PHP中文網其他相關文章!