Table of Contents
分享
请选择您的分享方式:
Home Web Front-end HTML Tutorial 移动端使用百度分享代码_html/css_WEB-ITnose

移动端使用百度分享代码_html/css_WEB-ITnose

Jun 24, 2016 am 11:33 AM

最近看了一些关于分享自媒体的代码,最后在在项目中使用了百度的分享代码,百度分享的代码格式,如下

<div class="bdsharebuttonbox" data-tag="share_1">    <!-- 此处添加展示按钮 --></div><script>    window._bd_share_config = {    //此处添加分享具体设置    }    //以下为js加载部分    with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];</script>
Copy after login

通过config,可以对分享链接、分享图片、分享描述、分享渠道等信息进行配置。具体可以参考百度分享代码的文档

http://share.baidu.com/code/advance#config

我这边在实际使用中,并没有进行过多的配置,而是采用css重写部分样式的方式来制作。

以下我这边的demo展示效果图

大概就是长这个样式,具体代码如下:

html:

<!DOCTYPE html><html><head lang="cn">    <meta charset="UTF-8">    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">    <meta name="apple-mobile-web-app-capable" content="yes">    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">    <title>移动百度分享demo</title>    <link rel="stylesheet" href="css/index.css" /></head><body>    <h2 id="分享">        分享    </h2>    <section class="screenW">        <div class="subW">            <div class="info">                <div class="shareBox">                    <h2 id="请选择您的分享方式">请选择您的分享方式:</h2>                    <div class="bdsharebuttonbox">                        <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间">QQ空间</a>                        <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博">新浪微博</a>                        <a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友">QQ</a>                        <a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博">腾讯微博</a>                        <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信">微信</a>                    </div>                    <div class="bdsharebuttonbox">                        <a href="#" onclick="return false;" class="popup_more" data-cmd="more"></a>                    </div>                </div>            </div>            <div class="close">关闭</div>        </div>    </section>    <script src="js/zepto.min.js"></script>    <script src="js/main.js"></script></body></html>
Copy after login

css

html{font-size:10px;}html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video { margin:0; padding:0; border:0; font-weight: normal; vertical-align:baseline;}article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {display:block;}body {font-family:"Microsoft YaHei", Arial, Helvetica, sans-serif; background:#f5f5f5;}ol, ul { list-style:none;}em, i{font-style: normal;}blockquote, q { quotes:none;}blockquote:before, blockquote:after, q:before, q:after { content:''; content:none;}table { border-collapse:collapse; border-spacing:0;}* {    tap-highlight-color:rgba(0, 0, 0, 0);    -webkit-tap-highlight-color:rgba(0, 0, 0, 0);    -webkit-box-sizing:border-box;    box-sizing:border-box;}input, textarea { outline:0; resize:none; -webkit-appearance: none;}img{vertical-align: middle;}a{display: block; color: #333; text-decoration: none;}/*以下是样式代码*/#share{margin: 50px;text-align: center;}.screenW{width: 100%; height: 100%; position: fixed; left: 0; top: 0; background-color: rgba(0,0,0,0.5); z-index: 999; display: none;}.subW{width: 100%; height: 260px; position: absolute; left: 0; bottom: -260px; background-color: #FFF; z-index: 999;}.subW.move{    animation:sidebar-move .5s ease;    -webkit-animation:sidebar-move .5s ease;    bottom:0px;}.subW.back{    animation:sidebar-back .5s ease;    -webkit-animation:sidebar-back .5s ease;    bottom:-260px;}.subW .title{width: 100%; height: 40px; line-height: 40px; text-align: center; font-size: .4rem;}.subW .close{width: 100%; height: 40px; line-height: 40px; text-align: center; font-size: .4rem; color: #FFF; background: #2fc7c9;}.subW .info{width:100%; height: 220px; padding: 0 10px;}/*以下是对百度自带样式的改造*/.shareBox .bdshare-button-style0-16{    background-image: -webkit-linear-gradient(bottom,rgba(0,0,0,.1) 50%,transparent 50%);    background-image: linear-gradient(bottom,rgba(0,0,0,.1) 50%,transparent 50%);    background-size:  100% 1px;    background-repeat: no-repeat;    background-position: left bottom;    display: -webkit-box;    display: -moz-box;    display: -ms-flexbox;    display: -webkit-flex;    display: flex;}.shareBox .bdshare-button-style0-16:last-child{background: none;}.shareBox .bdshare-button-style0-16:after{    content: "";    visibility: hidden;    display: none;    height: 0;    clear: both;}.shareBox .bdshare-button-style0-16 a{    text-align: center;    float: none;    font-size: 12px;    padding: 35px 0 0 0;    line-height: normal;    height: auto;    cursor: pointer;    margin: 10px 0;    position: relative;    background: none;    -webkit-box-flex:1;    -webkit-flex:1;    flex:1;}.shareBox .bdshare-button-style0-16 a:after{    content: " ";    width:30px;    height:30px;    position: absolute;    left: 50%;    top: 0px;    -webkit-transform: translate(-50%,0);    transform: translate(-50%,0);}.shareBox .bdshare-button-style0-16 a.bds_qzone:after{    background: url("../img/icon_qqkongjian_yellow.png") no-repeat; background-size: 100%;}.shareBox .bdshare-button-style0-16 a.bds_tsina:after{    background: url("../img/icon_xinlangweibo_red.png") no-repeat; background-size: 100%;}.shareBox .bdshare-button-style0-16 a.bds_sqq:after{    background: url("../img/icon_qqhaoyou_blue.png") no-repeat; background-size: 100%;}.shareBox .bdshare-button-style0-16 a.bds_tqq:after{    background: url("../img/icon_qqweibo_green.png") no-repeat; background-size: 100%;}.shareBox .bdshare-button-style0-16 a.bds_weixin:after{    background: url("../img/icon_weixin_green.png") no-repeat; background-size: 100%;}.shareBox .bdshare-button-style0-16 a.popup_more{width: 100%; margin: 20px 0;}.shareBox .bdshare-button-style0-16 a.popup_more:after{    width:40px;    height:40px;    position: absolute;    left: 50%;    top: 0px;    background: url("../img/icon_more_orange.png") no-repeat; background-size: 100%;}/*动画*/@keyframes sidebar-move {    0% {        bottom:-260px;    }    100% {        bottom:0px;    }}@keyframes sidebar-back {    0% {        bottom:0px;    }    100% {        bottom:-260px;    }}@-webkit-keyframes sidebar-move {    0% {        bottom:-260px;    }    100% {        bottom:0px;    }}@-webkit-keyframes sidebar-back {    0% {        bottom:0px;    }    100% {        bottom:-260px;    }}
Copy after login

js

(function() {    var main = {        node: {            closeBtn: $('.close'),            screenW: $('.screenW'),            subW: $('.subW'),            share: $('#share'),            shareBox: $('.shareBox')        },        /*入口*/        init: function() {            var self = this;            self.closeTap();            self.shareTap();        },        /*分享点击弹窗*/        shareTap: function() {            var self = this;            self.node.share.on('tap', function() {                self.wShow();                self.node.shareBox.show().siblings().hide();            });        },        /*点击关闭弹窗*/        closeTap: function() {            var self = this;            self.node.closeBtn.on('tap', function() {                self.wHide();            });        },        /*窗口显示*/        wShow: function() {            var self = this;            self.node.screenW.show();            self.node.subW.addClass('move').removeClass('back');        },        /*窗口隐藏*/        wHide: function() {            var self = this;            self.node.subW.addClass('back').removeClass('move');            setTimeout(function() {                self.node.screenW.hide();            }, 500);        }    };    /*商品js入口*/    main.init();    /*百度分享js*/    window._bd_share_config = {        "common": {            "bdSnsKey": {},            "bdText": "",            "bdMini": "2",            "bdMiniList": false,            "bdPic": "",            "bdStyle": "0",            "bdSize": "16"        },        "share": {},        "image": {            "viewList": ["qzone", "tsina", "sqq", "tqq", "weixin"],            "viewText": "分享到:",            "viewSize": "16"        },        "selectShare": {            "bdContainerClass": null,            "bdSelectMiniList": ["qzone", "tsina", "sqq", "tqq", "weixin"]        }    };    with(document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];})();
Copy after login

 

下载地方放到csdn上去了,地址为

http://download.csdn.net/detail/hufengsky123/9270163

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

See all articles