为自己的博客增加打赏功能之EMLOG博客教程

2016-8-12 / 63 评论 / 24523 阅读

经常在一些博客中看到有一个打赏功能。今天舍力也写了一个简单的打赏功能代码,需要注意的是,博客必须加载js,emlog博客默认为include/lib/js/jquery/jquery-1.7.1.js,不确定是否会与你们本身的主题特效有冲突。还有的就是,动手之前,记得备份,养成好习惯!

第一步:在js中写入下面代码

function dashangToggle(){$(".shang_box").fadeToggle();}function changeItem(i){var k = 3;for(var j = 0;j < k;j++){if(j == i){document.getElementById("sl_shang" + j).style.display = "block";}else{document.getElementById("sl_shang" + j).style.display = "none";}}}function opay(){document.getElementById("sl_shang").target="_parent";}//舍力制作打赏js


第2步:在css中插入如下代码

.sy_shang{clear:both;overflow:hidden;}.shang_box{width:300px;height:300px;padding:10px;background-color:#fff;border-radius:10px;position:fixed;z-index:1000;left:50%;top:50%;margin-left:-200px;margin-top:-200px;border:1px dotted #dedede;display:none;}.dashang{display:block;width:100px;margin:5px auto;height:25px;line-height:25px;padding:10px;background-color:#E74851;color:#fff;text-align:center;text-decoration:none;border-radius:10px;font-weight:bold;font-size:16px;transition:all 0.3s;}.dashang:hover{opacity:0.8;padding:15px;font-size:18px;}#sl_shang0,#sl_shang1,#sl_shang2{text-align:center;}#sl_shang0 img,#sl_shang1 img,#sl_shang2 img{max-width:260px;}.sl_shang{overflow:hidden;}.sl_shang b{font-size:18px;}.sl_shang ul{margin-top:10px; clear:both; overflow:hidden;}.sl_shang li{float:left;margin-left:10px;}


第3步:在需要放置的地方插入下面代码,注意把其中的图片地址改为你自己的哦。

<div class="sy_shang"><a href="javascript:void(0)" onclick="dashangToggle()" class="dashang" title="打赏,支持一下">打赏</a>
<div class="shang_box"><a href="javascript:void(0)" onclick="dashangToggle()" title="关闭" style="float:right;">X</a>
<div id="sl_shang" onsubmit="return postcheck()"><div class="sl_shang"><b>打赏方式:</b><ul><li><input type="radio" name="paytype" onclick="opay();return changeItem(0);"  checked="checked" />支付宝</li><li><input type="radio" name="paytype" onclick="opay();return changeItem(1);" />微信</li><li><input type="radio" name="paytype" onclick="opay();return changeItem(2);"  />QQ红包</li></ul></div>
<div id="sl_shang0"><img src="http://www.shuyong.net/content/uploadfile/images/shang/zfb.jpg"><br>打开支付宝扫一扫</div><div id="sl_shang1" style="display:none;"><img src="http://www.shuyong.net/content/uploadfile/images/shang/wx.jpg"><br>使用微信扫一扫</div><div id="sl_shang2" style="display:none;"><img src="http://www.shuyong.net/content/uploadfile/images/shang/qq.jpg"><br>打开QQ扫一扫</div>
</div></div>
</div>


以上3步就完成了。

    1. 头像
      筱米奇
      第35楼
      想学习一下
      回复
    1. 头像
      爱情鸟
      第34楼
      为恶趣味请问请问!!!!!!
      回复
    1. 头像
      愤怒男孩
      第33楼
      楼主好人一生平安
      回复
    1. 头像
      微心理
      第32楼
      为恶趣味请问请问
      回复
    1. 头像
      Damon胡东东
      第31楼
      准备抛弃畅言的,查看下
      回复
    1. 头像
      西门吹雪
      第30楼
      很好     一直在找哦。。
      回复
    1. 头像
      西门吹雪
      第29楼
      一直在找哦。。。
      回复
    1. 头像
      爱盛
      第28楼
      来学习学习。
      回复
    1. 头像
      森七博客
      第27楼
      再次支持博主
      回复
    1. 头像
      森七博客
      第26楼
      经过无数跳转来到这里,支持博主
      回复
      1. 头像
        森七博客
        @森七博客:显示是显示了,点了没反应,js和css都加了
        回复
      1. 头像
        舍力
        @森七博客:如何只是点了没有反应的话,应该是js没有加载的原因或者冲突了
        回复
      1. 头像
        森七博客
        @舍力:我是emlog。和这个说明一模一样,可是我这主题没有关于这方面的文件,怎么会冲突了
        回复
    1. 头像
      卡麦NLY博客
      第25楼
      卡麦NLY娱乐分享网希望与贵站成友链
      回复
    1. 头像
      贝壳
      第24楼
      奇怪了,我加上去不显示。。
      回复
      1. 头像
        舍力
        @贝壳:不会呀,是不是哪里弄错了呢。还有可能是js冲突。检查一下。
        回复
    1. 头像
      贝壳
      第23楼
      正需要这个功能
      回复
    1. 头像
      有哥哥
      第22楼
      看看
      回复
    1. 头像
      emlog大博客
      第21楼
      仓促的来了
      回复
    1 2 3 4