ASP.NET MVC+Bootstrap個人博客之文章打賞(六)


  看到新浪微博、百度百家等等平台上都帶有文章“打賞”功能,覺得很新鮮,於是也想在自己的博客中加入“打賞”功能。

  當然,加入打賞功能並非是真的想要讓別人打賞。因為只有那些真正能引起共鳴,發人深思,讓人受益匪淺的文章才值得打賞,值得點贊。而我的博客站僅僅是用作記錄筆記,當做自己的知識庫(如果能不經意間幫助別人那是再好不過了)。

  加入打賞功能純粹是“覺得好玩”,就是這么簡單,Just have a fun!(博主喜歡折騰,看見一個酷炫的功能就想去實現它)

     先看一下這個打賞的Icon長什么樣吧! 去站點試試打賞?=>www.zynblog.com

      (小站地址:http://www.zynblog.com)

  點擊“打賞Icon”后會彈出一個二維碼界面,各位老板可以選擇使用是使用支付寶打賞還是微信打賞:

具體代碼如下:(時間倉促,並為將其擴展為插件) 

 HTML:

        <!--打賞按鈕-->
        <div style="margin-bottom:20px;">
         <a title="打賞,支持一下" class="dashang" onclick="dashangToggle()" href="javascript:void(0)">

         </a>
        </div>

  打賞遮罩層HTML:

<div class="content">
    <div class="hide_box"><!--遮罩--></div>
    <div class="shang_box">
        <a class="shang_close" href="javascript:void(0)" onclick="dashangToggle()" title="關閉">
            <img src="/Content/dashangimg/close.jpg" alt="取消">
        </a>
        <div class="shang_tit">
            <p>感謝您的支持,我會繼續努力的!</p>
        </div>

        <div class="shang_payimg">
            <img src="/Content/dashangimg/alipayimg.jpg" alt="掃碼支持" title="掃一掃">
        </div>
        <div class="pay_explain">掃碼打賞,你說多少就多少</div>

        <div class="shang_payselect">
            <div class="pay_item checked" data-id="alipay">
                <span class="radiobox"></span>
                <span class="pay_logo">
                    <img src="/Content/dashangimg/alipay.jpg" alt="支付寶">
                </span>
            </div>
            <div class="pay_item" data-id="weixinpay">
                <span class="radiobox"></span>
                <span class="pay_logo">
                    <img src="/Content/dashangimg/wechat.jpg" alt="微信">
                </span>
            </div>
        </div>

        <div class="shang_info">
            <p>打開<span id="shang_pay_txt">支付寶</span>掃一掃,即可進行掃碼打賞哦</p>
        </div>
    </div>
</div>

  主要的JS:

 //打賞
jQuery(".pay_item").click(function () {
     jQuery(this).addClass('checked').siblings('.pay_item').removeClass('checked');
     var dataid = jQuery(this).attr('data-id');
     jQuery(".shang_payimg img").attr("src", "/Content/dashangimg/" + dataid + "img.jpg");
     jQuery("#shang_pay_txt").text(dataid == "alipay" ? "支付寶" : "微信");
 });
 function dashangToggle() {
    jQuery(".hide_box").fadeToggle();
    jQuery(".shang_box").fadeToggle();
 };

   順帶提供CSS:

  1 .hide_box {
  2     z-index: 999;
  3     filter: alpha(opacity=50);
  4     background: #666;
  5     opacity: 0.5;
  6     -moz-opacity: 0.5;
  7     left: 0;
  8     top: 0;
  9     height: 99%;
 10     width: 100%;
 11     position: fixed;
 12     display: none;
 13 }
 14 
 15 .shang_box {
 16     width: 540px;
 17     height: 540px;
 18     padding: 10px;
 19     background-color: #fff;
 20     border-radius: 10px;
 21     position: fixed;
 22     z-index: 1000;
 23     left: 50%;
 24     top: 50%;
 25     margin-left: -280px;
 26     margin-top: -280px;
 27     border: 1px dotted #dedede;
 28     display: none;
 29 }
 30 
 31     .shang_box img {
 32         border: none;
 33         border-width: 0;
 34     }
 35 
 36 .dashang {
 37     display: block;
 38     margin: 5px auto;
 39     text-align: center;
 40     transition: all 0.3s;
 41     width:50px;
 42     height:50px;
 43      background: url(../dashangimg/dashang.png) no-repeat scroll 0% 0% transparent;
 44 }
 45 
 46 .dashang:hover {
 47         background: url(../dashangimg/dashanghover.png) no-repeat scroll 0% 0% transparent;
 48     }
 49 
 50 .shang_close {
 51     float: right;
 52     display: inline-block;
 53 }
 54 
 55 .shang_logo {
 56     display: block;
 57     text-align: center;
 58     margin: 20px auto;
 59 }
 60 
 61 .shang_tit {
 62     width: 100%;
 63     height: 75px;
 64     text-align: center;
 65     line-height: 66px;
 66     color: #a3a3a3;
 67     font-size: 16px;
 68     background: url('../dashangimg/cy-reward-title-bg.jpg');
 69     font-family: 'Microsoft YaHei';
 70     margin-top: 7px;
 71     margin-right: 2px;
 72 }
 73 
 74     .shang_tit p {
 75         color: #a3a3a3;
 76         text-align: center;
 77         font-size: 16px;
 78     }
 79 
 80 .shang_payimg {
 81     width: 150px;
 82     height: 150px;
 83     border: 6px solid #EA5F00;
 84     margin: 0 auto;
 85     border-radius: 3px;
 86 }
 87 
 88     .shang_payimg img {
 89         display: block;
 90         text-align: center;
 91         width: 140px;
 92         height: 140px;
 93     }
 94 
 95 .pay_explain {
 96     text-align: center;
 97     margin: 10px auto;
 98     font-size: 12px;
 99     color: #545454;
100 }
101 
102 .radiobox {
103     width: 16px;
104     height: 16px;
105     background: url('../dashangimg/radio2.jpg');
106     display: block;
107     float: left;
108     margin-top: 5px;
109     margin-right: 14px;
110 }
111 
112 .checked .radiobox {
113     background: url('../dashangimg/radio1.jpg');
114 }
115 
116 .shang_payselect {
117     text-align: center;
118     margin: 0 auto;
119     margin-top: 40px;
120     cursor: pointer;
121     height: 60px;
122     width: 280px;
123 }
124 
125     .shang_payselect .pay_item {
126         display: inline-block;
127         margin-right: 10px;
128         float: left;
129     }
130 
131 .shang_info {
132     clear: both;
133 }
134 
135     .shang_info p, .shang_info a {
136         color: #C3C3C3;
137         text-align: center;
138         font-size: 12px;
139         text-decoration: none;
140         line-height: 2em;
141     }
打賞樣式

   最后再提供幾個打賞圖標吧,喜歡的話就收藏起來吧:

 

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM