Wordpress怎样将选中内容分享到新浪微博?
本文实例讲述了Wordpress将选中内容分享到新浪腾讯微博的办法。分享给各人供各人参考。详细办法以下:
保举:《wordpress教程》
一、引入jQuery,置信年夜少数WordPress博客都曾经引入了jQuery,那就能够间接进行第二步了.
二、正在页面底部,或许更切实的说,正在引入jQuery库的前面加之这样一段JS,你就能够看到以及本站同样的成果了.
选中即分享的性能看下来比拟初级,其实完成是相称简略的,此中的会让人头年夜,普通人也没有感兴味的原理这里就间接跳过,这个js文字选中后分享到新浪微博的性能我简略的封装了下,办法名是:$sinaMiniBlogShare
实例代码以下:
代码以下:
var miniBlogShare = function() { //指定地位驻入节点 $('<img id="imgSinaShare" class="img_share" title="将选中内容分享到新浪微博" src="1328255868614.gif" /><img id="imgQqShare" class="img_share" title="将选中内容分享到腾讯微博" src="/1328255868314.png" />').appendTo('body'); //默许款式 $('.img_share').css({ display : 'none', position : 'absolute', cursor : 'pointer' }); //选中文字 var funGetSelectTxt = function() { var txt = ''; if(document.selection) { txt = document.selection.createRange().text; } else { txt = document.getSelection(); } return txt.toString(); }; //选中文字后显示微博图标 $('html,body').mouseup(function(e) { if (e.target.id == 'imgSinaShare' || e.target.id == 'imgQqShare') { return } e = e || window.event; var txt = funGetSelectTxt(), sh = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0, left = (e.clientX - 40 < 0) ? e.clientX + 20 : e.clientX - 40, top = (e.clientY - 40 < 0) ? e.clientY + sh + 20 : e.clientY + sh - 40; if (txt) { $('#imgSinaShare').css({ display : 'inline', left : left, top : top }); $('#imgQqShare').css({ display : 'inline', left : left + 30, top : top }); } else { $('#imgSinaShare').css('display', 'none'); $('#imgQqShare').css('display', 'none'); } }); //点击新浪微博 $('#imgSinaShare').click(function() { var txt = funGetSelectTxt(), title = $('title').html(); if (txt) { window.open('http://v.t.sina.com.cn/share/share.php?title=' + txt + ' —— 转载自:' + title + '&url=' + window.location.href); } }); //点击腾讯微博 $('#imgQqShare').click(function() { var txt = funGetSelectTxt(), title = $('title').html(); if (txt) { window.open('http://v.t.qq.com/share/share.php?title=' + encodeURIComponent(txt + ' —— 转载自:' + title) + '&url=' + window.location.href); } }); }();
能够看到$sinaMiniBlogShare办法有两个参数,eleShare以及eleContainer,此中,前一个参数是必需的,指的是文字选中后呈现的浮动层元素(正在本文demo中就是新浪眼睛图标),前面一个参数指文字抉择的容器元素,可选参数,假如没有设置则指document元素,也就是整个页面文字选中城市触发分享的性能.
假定新浪微博分享图标的HTML以下:
代码以下:
<img id="imgSinaShare" class="img_sina_share" title="将选中内容分享到新浪微博" src="http://simg.sinajs.cn/blog7style/images/co妹妹on/share.gif" />
则间接应用以下代码:
代码以下:
$sinaMiniBlogShare(document.getElementById("imgSinaShare"));
心愿本文所述对各人的WordPress建站有所协助。
以上就是Wordpress怎样将选中内容分享到新浪微博的具体内容,更多请存眷资源魔其它相干文章!
标签: WordPress wordpress教程 wordpress自学 wordpress技术