javascript實作類別似百度分享功能的方法_javascript技巧

來源:互聯網
上載者:User

本文執行個體講述了javascript實作類別似百度分享功能的方法。分享給大家供大家參考。具體如下:

像騰訊,開心社區都提供這種分享介面的,做百度分享功能很簡單的
一般網站要接入分享功能,大部分都用百度分享和addthis的代碼,可是自己定製性太差,該分享功能樣式都可以自己修改,簡潔沒過多js代碼,大大提高網頁載入速度。

運行效果如下圖所示:

<!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>網路分享代碼分享</title><style type="text/css">/** * 分享代碼樣式 * by kily */#ak_share  { padding:10px 0; font-size:12px; }.ak_share  { height:1%; overflow:hidden; }.ak_share dt { float:left; font-weight:bold; color:#A5A5A5; height:16px; line-height:16px; }.ak_share dd { margin-right:10px; margin-left:0; height:16px; float:left; }.ak_share a:hover { color:#ed7811; text-decoration:underline;}.ak_share a { float:left; height:16px; line-height:16px; padding-left:18px; background:url(http://www.yem120.com/images/share.gif) left top no-repeat; color:#666; text-decoration:none; }.ak_share .t_163_s  { background-position: 0 -16px; }.ak_share .t_qq_s  { background-position: 0 -32px; }.ak_share .qzone_s  { background-position: 0 -48px; }.ak_share .douban_s { background-position: 0 -64px; }</style></head><body><div id="ak_share">  <dl class="ak_share">    <dt>分享:</dt>    <dd>      <a class="t_sina_s" href="javascript:(function(){window.open('http://v.t.sina.com.cn/share/share.php?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href)+'&source=bookmark','_blank','width=450,height=400');})()" title="分享到新浪微博" rel="nofollow">新浪微博</a>    </dd>    <dd>      <a class="t_163_s" href="javascript:(function(){window.open('http://t.163.com/article/user /checkLogin.do?link=http://news.163.com/&source=' + '&info='+encodeURIComponent(document.title)+' '+encodeURIComponent(location.href),'_blank','width=510,height=300');})()" title="分享到網易微博" rel="nofollow">網易微博</a>     </dd>    <dd>      <a class="t_qq_s" href="javascript:(function(){window.open('http://v.t.qq.com/share/share.php?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href)+'&source=bookmark','_blank','width=610,height=350');})()" title="分享到騰訊微博" rel="nofollow">騰訊微博</a>    </dd>    <dd>      <a class="qzone_s" href="javascript:void(window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+encodeURIComponent(document.location.href)));" title="分享到QQ空間" rel="nofollow">QQ空間</a>    </dd>    <dd>      <a class="douban_s" href="javascript:void(function(){var%20d=document,e=encodeURIComponent,s1=window.getSelection,s2=d.getSelection,s3=d.selection,s=s1?s1():s2?s2():s3?s3.createRange().text:' ',r='http://www.douban.com/recommend/?url='+e(d.location.href)+'&title='+e(d.title)+'&sel='+e(s)+'&v=1',x=function(){if(!window.open(r,'douban','toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330'))location.href=r+'&r=1'};if(/firefox/.test(navigator.userAgent)){setTimeout(x,0)}else{x()}})()" title="推薦到豆瓣" rel="nofollow">豆瓣</a>    </dd>  </dl></div></body></html>

希望本文所述對大家的javascript程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.