点击按钮弹出打赏浮动窗口

第一种效果:点击按钮弹出打赏浮动窗口

弹出层其实是默认隐藏,点击按钮显示。在弹出的窗口里点击支付宝,出现的是支付宝的二维码图片,点击微信是微信支付二维码图片。

完整代码下载

 

第二种效果

实现方法:

样式

<link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<style>
.clear:before,
.clear:after {
  content: "";
  display: table;
}

.clear:after {
  clear: both;
}

.clear {
  clear: both;
}	
.dashang {
  text-align: center;
}


.dashang .dashang-right {
  float:center;
  position: relative;
  top: -1px;
}

.dashang .entry-like,
.dashang .entry-sponsor {
  display: inline-block;
  font-size: 14px;
  margin: 0 2px;
}

.dashang .entry-like a {
  background-color: #76b852;
  border-radius: 3px;
  color: #fff;
  display: inline-block;
  padding: 1px 10px;
}

.dashang .entry-like a:hover {
  opacity: 0.85;
}

.dashang .entry-like a.liked {
  background-color: #bbb;
}

.dashang .entry-like a.liked:hover {
  opacity: 1;
}

.dashang .entry-sponsor span {
  background-color: #ffbe02;
  border-radius: 3px;
  color: #fff;
  display: inline-block;
  padding: 1px 10px;
  cursor: pointer;
}

.dashang .entry-sponsor span:hover {
  opacity: 0.85;
}	
.ht_grid {
  float: left;
  width: 49%;
  margin-right: 2%;
}

.ht_grid:nth-of-type(2n) {
  margin-right: 0;
}

.ht_grid:nth-of-type(2n+1) {
  clear: left;
}

.ht_grid:nth-of-type(2n+0) {
  margin-right: 0;
  clear: right;
}

.ht_grid img {
  width: 100%;
}
/* The Modal (background) */
.modal {
  display: none;
  /* Hidden by default */
  position: fixed;
  /* Stay in place */
  z-index: 1;
  /* Sit on top */
  padding-top: 100px;
  /* Location of the box */
  left: 0;
  top: 0;
  width: 100%;
  /* Full width */
  height: 100%;
  /* Full height */
  overflow: auto;
  /* Enable scroll if needed */
  background-color: black;
  /* Fallback color */
  background-color: rgba(0, 0, 0, 0.4);
  /* Black w/ opacity */
  z-index: 1000;
}

/* Modal Content */
.modal-content {
  position: relative;
  background-color: #fefefe;
  margin: auto;
  padding: 0;
  border-radius: 4px;
  border: 1px solid #888;
  font-size: 14px;
  width: 400px;
  padding: 25px 20px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  -webkit-animation-name: animatetop;
  -webkit-animation-duration: 0.4s;
  animation-name: animatetop;
  animation-duration: 0.4s img;
  animation-duration-border: 1px solid #f0f0f0;
  animation-duration-border-radius: 4px;
  animation-duration-width: 100%;
  animation-duration-max-width: 100%;
}

.modal-content h3 {
  font-size: 16px;
  font-weight: bold;
  margin: 0 0 10px;
}
	/* The Close Button */
.close {
  color: #aaaaaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  position: absolute;
  top: 8px;
  right: 10px;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}
</style>

html代码:

<div class="dashang clear">
  <div id="myModal" class="modal">
    <div class="modal-content clear">
      <h3>给这篇文章的作者打赏</h3>
      <div class="ht_grid"> <img src="https://www.baishitou.cn/wp-content/uploads/2019/04//weipayimg.jpg" alt="微信扫一扫打赏"/> 微信扫一扫打赏 </div>
      <div class="ht_grid"> <img src="https://www.baishitou.cn/wp-content/uploads/2019/04//alipayimg.jpg" alt="支付宝扫一扫打赏"/> 支付宝扫一扫打赏 </div>
      <span class="close">&times;</span> </div>
  </div>
  <div class="dashang-right"> <span class="entry-sponsor"> <span id="myBtn" href="#"><i class="fa fa-jpy"></i> 给本站打赏</span> </span> </div>
</div>
<script>
// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal 
btn.onclick = function() {
    modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
</script>
THE END