分享功能可以利用插件share.js插件,也可以自己定义。只要知道各平台的分享地址及相应的参数赋值就可以了。
//第一种方法 //引入插件 <script src="../libs/jquery/jquery/dist/jquery.share.min.js"></script> //分享功能 $scope.sharePoster = function(platform){ //获取需要分享的图片地址 var posterUrl=angular.element("#myPoster").attr("src"); if(!posterUrl){ var layer=document.createElement("div"); layer.id="layer"; layer.innerHTML="请先上传图片再分享哦!" var style= { background:"#000000", color:"#ffffff", position:"absolute", zIndex:10, width:"484px", height:"62px", lineHeight:"61px", textAlign:"center", fontSize:"18px", borderRadius:"10px", opacity: 0.75, left:"38%", top:"45%" } for(var i in style) layer.style[i]=style[i]; if(document.getElementById("layer")==null) { document.body.appendChild(layer); setTimeout("document.body.removeChild(layer)",2000) } return } var link = '填入当前页面路径'; var image = posterUrl; var title = '好好学习天天向上'; $('#shareposter').share({ url: link, title: shareTitle, description: shareTitle, image: image, sites: ['weibo','qq','qzone','douban'] }); var shareLink = $('#shareposter').find('.icon-'+platform).attr('href'); window.open(shareLink,'_blank'); } //第二种方法 $scope.sharePoster = function(platform){ var link = '当前页面路径'; var image = '图片地址'; var title = '好好学习天天向上'; if (platform == "weibo") { window.open("http://v.t.sina.com.cn/share/share.php?url=" + link + "&title=" + title + "&content=utf8&pic=" + image); } if (platform == "qq") { window.open("https://connect.qq.com/widget/shareqq/index.html?url=" + link + "&title=" + title + "&pics=" + image); } if (platform == "qzone") { window.open("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + link + "&title=" + title + "&pics=" + image +"&desc=" +title); } if (platform == "douban") { window.open("http://www.douban.com/recommend/?url=" + link + "&title=" + title + "&image=" + image); } }