(function(){ let url = window.location.href; //分享到微博 function shareWeibo() { layer.open({ type:2, title:'分享到微博', content:'//service.weibo.com/share/share.php?url=中国工程院院士馆:'+encodeURIComponent(url), closeBtn:1, area:['640px','480px'] }); } //分享到QQ空间 function shareQQZone(){ let baseURL = 'https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?'; baseURL = baseURL + 'url=' + encodeURIComponent(url); baseURL = baseURL + '&sharesource=qzone' baseURL = baseURL + '&title=' + encodeURIComponent('中国工程院院士馆'); //baseURL = baseURL + '&summary=' + encodeURIComponent('中国院士馆'); //QQ空间用LAYER打开貌似会报错 window.open(baseURL,'_blank'); } /* 生成二维码 */ $("#qrcode").qrcode({ text: url, //设置二维码内容 render: "table", //设置渲染方式 width: 100, //设置宽度,默认生成的二维码大小是 256×256 height: 100, //设置高度 typeNumber: -1, //计算模式 background: "#ffffff", //背景颜色 foreground: "#000000" //前景颜色 }); /* 显示二维码 */ function wxShow() { $('.wx-qrcode-wrapper').show() } /* 隐藏二维码 */ function wxHide() { $('.wx-qrcode-wrapper').hide() } //给分享按钮绑定事件 $('.shareWeiboIcon').on('click',function(){shareWeibo();}); $('.shareQQIcon').on('click',function(){shareQQZone();}); $('.shareWeixiIcon').on('mouseover',function(){wxShow();}); $('.shareWeixiIcon').on('mouseout',function(){wxHide();}); })();