HTML 5 CSS 3 & JavaScript 实现用按钮播放视频功能cid1065-网页前端设计

html and css

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Playmorph</title>
  6. <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.4/TweenMax.min.js"></script>
  7. <style>
  8. body {
  9. display: flex;
  10. justify-content: center;
  11. align-items: center;
  12. height: 100vh;
  13. margin: 0;
  14. background-image: url(active-adult-asian-1033374.jpg);
  15. background-size:cover;
  16. overflow: hidden;
  17. }
  18. .play-button {
  19. width: 152px;
  20. height: 152px;
  21. position: relative;
  22. cursor: pointer;
  23. }
  24. .play-backdrop {
  25. width: 100%;
  26. height: 100%;
  27. position: fixed;
  28. left: 0;
  29. top: 0;
  30. background-image: url(beautiful-girl-model-157131.jpg);
  31. opacity: 0;
  32. background-size: cover;
  33. visibility: hidden;
  34. }
  35. .play-close {
  36. width: 30px;
  37. height: 30px;
  38. position: absolute;
  39. right: 0;
  40. bottom: calc(100% + 15px);
  41. border: none;
  42. outline: none;
  43. background: deepskyblue;
  44. opacity: 0;
  45. cursor: pointer;
  46. }
  47. .play-close::before,
  48. .play-close::after {
  49. content: "";
  50. display: block;
  51. width: 100%;
  52. height: 1px;
  53. position: absolute;
  54. top: 50%;
  55. left: 0;
  56. transform: rotate(45deg);
  57. background-color: white;
  58. border-radius: 50px;
  59. }
  60. .play-close::after {
  61. transform: rotate(-45deg);
  62. color:black;
  63. }
  64. .play-circles {
  65. display: block;
  66. width: 100%;
  67. height: 100%;
  68. }
  69. .play-perspective {
  70. width: 600px;
  71. height: 400px;
  72. position: absolute;
  73. left: -230px;
  74. top: -125px;
  75. }
  76. .play-triangle {
  77. width: 600px;
  78. height: 400px;
  79. background-color:deepskyblue;
  80. cursor: pointer;
  81. }
  82. </style>
  83. </head>
  84. <body>
  85. <div class="play-backdrop"></div>
  86. <div class="play-button">
  87. <svg class="play-circles" viewBox="0 0 152 152">
  88. <circle class="play-circle-01" fill="none" stroke="#fff" stroke-width="3" stroke-dasharray="343" cx="76" cy="76" r="72.7"/>
  89. <circle class="play-circle-02" fill="none" stroke="#fff" stroke-width="3" stroke-dasharray="309" cx="76" cy="76" r="65.5"/>
  90. </svg>
  91. <div class="play-perspective">
  92. <button class="play-close"></button>
  93. <div class="play-triangle">
  94. <div class="play-video">
  95. <iframe width="600" height="415" src="https://www.youtube.com/embed/9w2JLO7A-Os" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. <script>
  101. TweenMax.set(".play-circle-01", {
  102. rotation: 90,
  103. transformOrigin: "center"
  104. })
  105. TweenMax.set(".play-circle-02", {
  106. rotation: -90,
  107. transformOrigin: "center"
  108. })
  109. TweenMax.set(".play-perspective", {
  110. xPercent: 6.5,
  111. scale: .175,
  112. transformOrigin: "center",
  113. perspective: 1
  114. })
  115. TweenMax.set(".play-video", {
  116. visibility: "hidden",
  117. opacity: 0,
  118. })
  119. TweenMax.set(".play-triangle", {
  120. transformOrigin: "left center",
  121. transformStyle: "preserve-3d",
  122. rotationY: 10,
  123. scaleX: 2
  124. })
  125. const rotateTL = new TimelineMax({ paused: true })
  126. .to(".play-circle-01", .7, {
  127. opacity: .1,
  128. rotation: '+=360',
  129. strokeDasharray: 456,
  130. ease: Power1.easeInOut
  131. }, 0)
  132. .to(".play-circle-02", .7, {
  133. opacity: .1,
  134. rotation: '-=360',
  135. strokeDasharray: 411,
  136. ease: Power1.easeInOut
  137. }, 0)
  138. const openTL = new TimelineMax({ paused: true })
  139. .to(".play-backdrop", 1, {
  140. opacity: .95,
  141. visibility: "visible",
  142. ease: Power2.easeInOut
  143. }, 0)
  144. .to(".play-close", 1, {
  145. opacity: 1,
  146. ease: Power2.easeInOut
  147. }, 0)
  148. .to(".play-perspective", 1, {
  149. xPercent: 0,
  150. scale: 1,
  151. ease: Power2.easeInOut
  152. }, 0)
  153. .to(".play-triangle", 1, {
  154. scaleX: 1,
  155. ease: ExpoScaleEase.config(2, 1, Power2.easeInOut)
  156. }, 0)
  157. .to(".play-triangle", 1, {
  158. rotationY: 0,
  159. ease: ExpoScaleEase.config(10, .01, Power2.easeInOut)
  160. }, 0)
  161. .to(".play-video", 1, {
  162. visibility: "visible",
  163. opacity: 1
  164. }, .5)
  165. const button = document.querySelector(".play-button")
  166. const backdrop = document.querySelector(".play-backdrop")
  167. const close = document.querySelector(".play-close")
  168. button.addEventListener("mouseover", () => rotateTL.play())
  169. button.addEventListener("mouseleave", () => rotateTL.reverse())
  170. button.addEventListener("click", () => openTL.play())
  171. backdrop.addEventListener("click", () => openTL.reverse())
  172. close.addEventListener("click", e => {
  173. e.stopPropagation()
  174. openTL.reverse()
  175. })
  176. </script>
  177. </body>
  178. </html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Playmorph</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.4/TweenMax.min.js"></script> 
    <style>
    body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
  background-image: url(active-adult-asian-1033374.jpg);
        background-size:cover;
  overflow: hidden;
}

.play-button {
  width: 152px;
  height: 152px;
  position: relative;
  cursor: pointer;
}

.play-backdrop {
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  background-image: url(beautiful-girl-model-157131.jpg);
  opacity: 0;
    background-size: cover;
  visibility: hidden;
}

.play-close {
  width: 30px;
  height: 30px;
  position: absolute;
  right: 0;
  bottom: calc(100% + 15px);
  border: none;
  outline: none;
  background: deepskyblue;
  opacity: 0;
  cursor: pointer;
}

.play-close::before,
.play-close::after {
  content: "";
  display: block;
  width: 100%;
  height: 1px;
  position: absolute;
  top: 50%;
  left: 0;
  transform: rotate(45deg);
  background-color: white;
    border-radius: 50px;
    
}

.play-close::after {
  transform: rotate(-45deg);
  color:black;
}

.play-circles {
  display: block;
  width: 100%;
  height: 100%;
}

.play-perspective {
  width: 600px;
  height: 400px;
  position: absolute;
  left: -230px;
  top: -125px;
}

.play-triangle {
  width: 600px;
  height: 400px;
  background-color:deepskyblue;
  cursor: pointer;
}

    
    </style>
</head>
<body>
    <div class="play-backdrop"></div>
<div class="play-button">
  <svg class="play-circles" viewBox="0 0 152 152">
    <circle class="play-circle-01" fill="none" stroke="#fff" stroke-width="3" stroke-dasharray="343" cx="76" cy="76" r="72.7"/>
    <circle class="play-circle-02" fill="none" stroke="#fff" stroke-width="3" stroke-dasharray="309" cx="76" cy="76" r="65.5"/>
  </svg>
  <div class="play-perspective">
    <button class="play-close"></button>
    <div class="play-triangle">
      <div class="play-video">
        <iframe width="600" height="415" src="https://www.youtube.com/embed/9w2JLO7A-Os" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
      </div>
    </div>
  </div>
</div>
<script>
    TweenMax.set(".play-circle-01", {
  rotation: 90,
  transformOrigin: "center"
})

TweenMax.set(".play-circle-02", {
  rotation: -90,
  transformOrigin: "center"
})

TweenMax.set(".play-perspective", {
  xPercent: 6.5,
  scale: .175,
  transformOrigin: "center",
  perspective: 1
})

TweenMax.set(".play-video", {
  visibility: "hidden",
  opacity: 0,
})

TweenMax.set(".play-triangle", {
  transformOrigin: "left center",
  transformStyle: "preserve-3d",
  rotationY: 10,
  scaleX: 2
})

const rotateTL = new TimelineMax({ paused: true })
  .to(".play-circle-01", .7, {
    opacity: .1,
    rotation: '+=360',
    strokeDasharray: 456,
    ease: Power1.easeInOut
  }, 0)
  .to(".play-circle-02", .7, {
    opacity: .1,
    rotation: '-=360',
    strokeDasharray: 411,
    ease: Power1.easeInOut
  }, 0)

const openTL = new TimelineMax({ paused: true })
  .to(".play-backdrop", 1, {
    opacity: .95,
    visibility: "visible",
    ease: Power2.easeInOut
  }, 0)
  .to(".play-close", 1, {
    opacity: 1,
    ease: Power2.easeInOut
  }, 0)
  .to(".play-perspective", 1, {
    xPercent: 0,
    scale: 1,
    ease: Power2.easeInOut
  }, 0)
  .to(".play-triangle", 1, {
    scaleX: 1,
    ease: ExpoScaleEase.config(2, 1, Power2.easeInOut)
  }, 0)
  .to(".play-triangle", 1, {
    rotationY: 0,
    ease: ExpoScaleEase.config(10, .01, Power2.easeInOut)
  }, 0)
  .to(".play-video", 1, {
    visibility: "visible",
    opacity: 1
  }, .5)


const button = document.querySelector(".play-button")
const backdrop = document.querySelector(".play-backdrop")
const close = document.querySelector(".play-close")

button.addEventListener("mouseover", () => rotateTL.play())
button.addEventListener("mouseleave", () => rotateTL.reverse())
button.addEventListener("click", () => openTL.play())
backdrop.addEventListener("click", () => openTL.reverse())
close.addEventListener("click", e => {
  e.stopPropagation()
  openTL.reverse()
})

    
    
    
</script>
</body>
</html>

在线演示


让链接同时具备两种打开方式
获取源码: Drive Download 20200402T141206Z 001
下载数:84人次, 文件大小: 85.4 KB, 上传日期: 2020年-11 月-26日

公众号回复:gcode  获取解压密码

qrcode_for_gh_6ea2c28a1709_258 (1)

2,508 人查阅

类似文章