Giter Site home page Giter Site logo

poprlz / share.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from overtrue/share.js

0.0 2.0 0.0 605 KB

一键分享到微博、QQ空间、QQ好友、微信、腾讯微博、豆瓣、Facebook、Twitter、Linkedin、Google+、点点等

Home Page: http://overtrue.me/share.js/

License: MIT License

HTML 5.82% JavaScript 88.10% CSS 6.08%

share.js's Introduction

一键分享到微博、QQ空间、QQ好友、微信、腾讯微博、豆瓣、Facebook、Twitter、Linkedin、Google+、点点等社交网站。

qq20151127-1 2x

DEMO

或者直接浏览我的博客 http://overtrue.me 或者 http://laravel.so 内容页查看效果。

安装

有3种安装方式:

  1. 使用 npm

    npm install social-share.js
  2. 使用 cdnjs,引入 share.min.cssshare.min.js 两个链接就好。 (感谢 @mdluo)

  3. 手动下载或者 git clone 本项目。

使用

HTML:

<div class="social-share"></div>

<!--  css & js -->
<link href="dist/css/share.min.css">
<script src="dist/js/share.min.js"></script>

// 当你使用类名为 `social-share` 时不需要手动初始化

自定义配置

所有配置可选, 通常默认就满足需求:

可用的配置有:

url                 : '', // 网址,默认使用 window.location.href
source              : '', // 来源(QQ空间会用到), 默认读取head标签:<meta name="site" content="http://overtrue" />
title               : '', // 标题,默认读取 document.title 或者 <meta name="title" content="share.js" />
description         : '', // 描述, 默认读取head标签:<meta name="description" content="PHP弱类型的实现原理分析" />
image               : '', // 图片, 默认取网页中第一个img标签
sites               : ['qzone', 'qq', 'weibo','wechat', 'douban'], // 启用的站点
disabled            : ['google', 'facebook', 'twitter'], // 禁用的站点
wechatQrcodeTitle   : '微信扫一扫:分享', // 微信二维码提示文字
wechatQrcodeHelper  : '<p>微信里点“发现”,扫一下</p><p>二维码便可将本文分享至朋友圈。</p>'

以上选项均可通过标签 data-xxx 来设置:

驼峰转为中横线,如wechatQrcodeHelper 的data标签为data-wechat-qrcode-helper

禁用 google、twitter、facebook 并设置分享的描述
<div class="share-component" data-disabled="google,twitter,facebook" data-description="Share.js - 一键分享到微博,QQ空间,腾讯微博,人人,豆瓣"></div>
设置微信二维码标题
<div class="social-share" data-wechat-qrcode-title="请打开微信扫一扫"></div>
针对特定站点使用不同的属性(title, url, description,image...)
<div class="social-share" data-weibo-title="这个标题只有的分享到微博时有用,其它标题为全局标题" data-qq-title="分享到QQ时用此标题"></div>

你也可以自定义图标

使用: data-initialized="true" 标签或者 initialized 配置项来禁用自动生成icon功能。

<div class="social-share" data-initialized="true">
    <a href="#" class="social-share-icon icon-weibo"></a>
    <a href="#" class="social-share-icon icon-qq"></a>
    <a href="#" class="social-share-icon icon-qzone"></a>
</div>

以上a标题会自动加上分享链接(a 标签必须带 icon-NAME 属性,不然分享链接不会自动加上)。

如果你想在分享icon列表中内置一些元素,比如放一个收藏按钮在分享按钮的后面:

<div class="social-share">
    <a href="javascript:;" class="social-share-icon icon-heart"></a>
</div>

这样并没有实现,因为结果是所有的分享按钮都创建在了收藏按钮的后面了,这时候你就可以用 data-mode="prepend" 来确定分享按钮创建的方式。

<div class="social-share" data-mode="prepend">
    <a href="javascript:;" class="social-share-icon icon-heart"></a>
</div>

这样,所有的分享图标就会创建在容器的内容前面,反之可以用 append 创建在容器内容后面,当然这是默认的,也不需要这么做。

指定移动设备上显示的图标

<div class="share-component" data-mobile-sites="weibo,qq,qzone,tencent"></div>

当在手机上打开该页面的时候就只会显示这4个图标了。

欢迎贡献代码及提建议!

引用

本项目中二维码生成部分用到了开源组件:lrsjng/jquery-qrcode (MIT License)

License

MIT

share.js's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.