这次给大家带来用JS实现简易打赏功能,用JS实现简易打赏功能的注意事项有哪些,下面就是实战案例,一起来看一下。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;"/>
<title>打赏</title>
<styletype="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() {
vardsSidebar=document.getElementById('dsSidebar');
dsSidebar.onmouseover=function() {
startMove(0, 24);
}
dsSidebar.onmouseout=function() {
startMove(-200, -24);
}
moveBtn();
}
</script>
</head>
<body>
<pid="dsSidebar">
<pclass="dsPanels">
<pclass="dsPanel dsPanel-highlight">
<pclass="dsPanel-title">喜欢请用微信打赏</p>
<imgid='dsImg'src="http://files.cnblogs.com/files/eritpang/weixin.bmp"alt=""width="160"height="160"/>
</p>
</p>
<spanclass="dsPanel-button"id='dsBtn'><b>打<br/>赏</b></span>
</p>
</body>
</html>相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
一直想做一款后台管理系统,看了很多优秀的开源项目但是发现没有合适自己的。于是利用空闲休息时间开始自己写一套后台系统。如此有了若依管理系统。她可以用于所有的Web应用程序,如网站管理后台,网站会员中心,CMS,CRM,OA。所有前端后台代码封装过后十分精简易上手,出错效率低。同时支持移动客户端访问。系统会陆续更新一些实用功能。 您是否在找一套合适后台管理系统。 您是否在找一套代码易读易懂后台
885
以上就是用JS实现简易打赏功能的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号