自制簡易打賞功能的實例
1、申請開通cnblogs的JS代碼支持

2、將微信收款碼圖片上傳到cnblogs

3、將如下代碼中的http://files.cnblogs.com/files/eritpang/weixin.bmp替換為剛剛上傳的收款碼圖片的鏈接地址,然后將代碼添加到設(shè)置->博客側(cè)邊欄公告(支持HTML代碼)(支持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;" />
<title>打賞</title>
<style type="text/css">
#dsSidebar {
z-index: 999999;
top: 18%;
width: 200px;
height: 200px;
position: fixed;
right: -200px;
}
#dsBtn {
z-index: 999999;
width: 30px;
height: 58px;
left: -30px;
top: 80px;
line-height: 28px;
position: absolute;
}
.dsPanels {
margin: 0px auto;
overflow: hidden;
}
.dsPanel {
float: left;
margin: 0px 0px;
padding: 12px 0px;
text-align: center;
background: #ffeedd;
border-color: #ffeedd;
border-radius: 8px;
}
.dsPanel-highlight {
margin-top: 0;
margin-bottom: 0;
padding-left: 10px;
padding-right: 10px;
width: 160px;
border: 8px solid #fd935c;
}
.dsPanel-button {
display: block;
font-size: 16px;
font-weight: 500;
color: #ffeedd;
text-align: center;
text-decoration: none;
text-shadow: 0 1px rgba(black, .1);
background: #fd935c;
border-bottom: 2px solid #cf7e3b;
border-color: rgba(black, .15);
border-radius: 4px;
}
.dsPanel-title {
width: 128px;
margin: -15px auto 15px;
padding-bottom: 0px;
line-height: 22px;
font-size: 14px;
font-weight: bold;
color: #ffeedd;
text-shadow: 0 1px rgba(black, .05);
background: #fd935c;
border-radius: 0 0 4px 4px;
}
</style>
<script>
function moveBtn() {
var dsBtn = document.getElementById("dsBtn");
var now = new Date();
var times = now.getTime();
var offsetSize = Math.sin(times / 380.0) * 15 + 45;
var radius = Math.sin(times / 380.0) * 18 + 24;
dsBtn.style.left = -offsetSize + 'px';
dsBtn.style.width = offsetSize + 'px';
dsBtn.style.borderRadius = radius + 'px';
setTimeout(moveBtn, 60);
}
var dsSidebarTimer = null;
var dsSidebarOffsetRight = -200;
function startMove(dsSidebarTarget, dsSidebarSpeed) {
clearTimeout(dsSidebarTimer);
function doMove() {
var dsSidebar = document.getElementById('dsSidebar');
dsSidebarSpeed *= 0.9;
if (dsSidebarSpeed > -1 && dsSidebarSpeed < 0) {
dsSidebarSpeed = -1;
} else if (dsSidebarSpeed < 1 && dsSidebarSpeed > 0) {
dsSidebarSpeed = 1;
}
dsSidebarOffsetRight = dsSidebarOffsetRight + dsSidebarSpeed;
if (dsSidebarSpeed > 0 && dsSidebarOffsetRight >= dsSidebarTarget) {
dsSidebarOffsetRight = dsSidebarTarget;
dsSidebar.style.right = dsSidebarOffsetRight + 'px';
} else if (dsSidebarSpeed < 0 && dsSidebarOffsetRight <= dsSidebarTarget) {
dsSidebarOffsetRight = dsSidebarTarget;
dsSidebar.style.right = dsSidebarOffsetRight + 'px';
} else {
dsSidebar.style.right = dsSidebarOffsetRight + 'px';
dsSidebarTimer = setTimeout(doMove, 30);
}
}
doMove();
}
document.getElementById('dsImg').onload = function () {
var dsSidebar = document.getElementById('dsSidebar');
dsSidebar.onmouseover = function () {
startMove(0, 24);
}
dsSidebar.onmouseout = function () {
startMove(-200, -24);
}
moveBtn();
}
</script>
</head>
<body>
<div id="dsSidebar">
<div class="dsPanels">
<div class="dsPanel dsPanel-highlight">
<p class="dsPanel-title">喜歡請用微信打賞</p>
<img id='dsImg' src="http://files.cnblogs.com/files/eritpang/weixin.bmp" alt="" width="160" height="160" />
</div>
</div>
<span class="dsPanel-button" id='dsBtn'><b>打<br/>賞</b></span>
</div>
</body>
</html>
4、效果如下。

以上這篇自制簡易打賞功能的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript 申明函數(shù)的三種方法 每個函數(shù)就是一個對象(一)
JavaScript 申明函數(shù)的三種方法 每個函數(shù)就是一個對象(一)2009-12-12
JS實現(xiàn)保留n位小數(shù)的四舍五入問題示例
這篇文章主要介紹了JS實現(xiàn)保留n位小數(shù)的四舍五入問題,結(jié)合完整實例形式分析了javascript針對小數(shù)四舍五入操作技巧,需要的朋友可以參考下2016-08-08
數(shù)據(jù)結(jié)構(gòu)中的各種排序方法小結(jié)(JS實現(xiàn))
下面小編就為大家?guī)硪黄獢?shù)據(jù)結(jié)構(gòu)中的各種排序方法小結(jié)(JS實現(xiàn))。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-07-07
javascript使用正則控制input輸入框允許輸入的值方法大全
在做項目的時候,我們經(jīng)常會遇到控制input輸入框允許輸入的值為數(shù)字,字母,漢字或者混排的情況,那么我們怎么來處理呢,下面我們就來探討怎么通過用javascript正則來實現(xiàn)2014-06-06

