0


圣诞节用女神照片做了一个旋转木马

圣诞节到了 看见朋友圈都是送各种礼物的 作为一个程序员 肯定是要给女朋友准备一份不一样的礼物啦。看见在网上看见各种旋转圣诞树的,就想到了这个旋转木马 赶紧学起来发给女朋友看看!

效果图

**使用技术 html css3 jq **

使用旋转实现

基本样式

  1. <body>
  2. <div id="header">
  3. <p class="enclosed"></p>
  4. <button id="startButton">点击 查收<span style='color: red'></span></button>
  5. </div>
  6. <div id="Obscuration">
  7. <ul>
  8. <li><img src="./image/01.jpg" alt=""></li>
  9. <li><img src="./image/02.jpeg" alt=""></li>
  10. <li><img src="./image/03.jpeg" alt=""></li>
  11. <li><img src="./image/04.jpg" alt=""></li>
  12. <li><img src="./image/05.jpg" alt=""></li>
  13. <li><img src="./image/06.jpg" alt=""></li>
  14. </ul>
  15. </div>
  16. <audio src="./christmas.mp3" controls id="music">
  17. </audio>
  18. </body>

css样式

  1. <style>
  2. .enclosed {
  3. padding: 5px 30px;
  4. text-align: center;
  5. }
  6. #music{
  7. display: none;
  8. }
  9. #Obscuration {
  10. position: absolute;
  11. width: 100%;
  12. height: 100%;
  13. display: none;
  14. perspective: 1000px;
  15. z-index: 99;
  16. /* background-color: #fff; */
  17. background: url(./image/chbja1.jpg) no-repeat;
  18. background-size: 100% 100%;
  19. }
  20. #header{
  21. background: url(./image/chbja.jpg) no-repeat;
  22. background-size: 100% 100%;
  23. }
  24. ul {
  25. position: relative;
  26. margin: 300px auto;
  27. width: 150px;
  28. height: 150px;
  29. /* border: 4px solid #1a1; */
  30. animation: xuanzhuan 10s linear infinite;
  31. transform-style: preserve-3d;
  32. }
  33. li {
  34. list-style: none;
  35. position: absolute;
  36. }
  37. img{
  38. width: 250px;
  39. height: 300px;
  40. }
  41. li:nth-child(1) {
  42. transform: translateZ(300px);
  43. }
  44. li:nth-child(2) {
  45. transform: rotateY(60deg) translateZ(300px);
  46. }
  47. li:nth-child(3) {
  48. transform: rotateY(120deg) translateZ(300px);
  49. }
  50. li:nth-child(4) {
  51. transform: rotateY(180deg) translateZ(300px);
  52. }
  53. li:nth-child(5) {
  54. transform: rotateY(240deg) translateZ(300px);
  55. }
  56. li:nth-child(6) {
  57. transform: rotateY(300deg) translateZ(300px);
  58. }
  59. @keyframes xuanzhuan {
  60. to {
  61. transform: rotateY(360deg);
  62. }
  63. }
  64. ul:hover {
  65. animation-play-state: paused;
  66. }
  67. </style>

引入插件

<script src="./jquery-2.1.4.min.js"></script> <script src="./typeit.js"></script> <script src="./index.js"></script>

js逻辑

首先定义好数据

const startButton = document.getElementById('startButton')

const Obscuration = document.getElementById('Obscuration')

const music = document.getElementById('music')

startButton.addEventListener('click', start)

封装调用逻辑

  1. function play() {
  2. if(music.paused) {
  3. music.paused = false
  4. music.play()
  5. }
  6. }
  7. function initRenderer() {
  8. width = window.innerWidth
  9. height = window.innerHeight
  10. renderer = new THREE.WebGLRenderer({
  11. antialias: true
  12. })
  13. // 如果设置开启,允许在场景中使用阴影贴图
  14. // renderer.shadowMap.enabled = true
  15. // 定义阴影贴图类型 (未过滤, 关闭部分过滤, 关闭部分双线性过滤)
  16. // renderer.shadowMap.type = THREE.BasicShadowMap
  17. renderer.setSize(width, height)
  18. document.body.appendChild(renderer.domElement)
  19. renderer.setClearColor(0x000089, 1.0)
  20. }
  21. function initScene() {
  22. scene = new THREE.Scene()
  23. }
  24. function initCamera() {
  25. camera = new THREE.PerspectiveCamera(45, width/height, 1, 1000)
  26. camera.position.set(6, 2, -12)
  27. }

用户点击查收触发

  1. function start() {
  2. startButton.innerHTML = '加载中...'
  3. Obscuration.style.display = 'block'
  4. play()
  5. initRenderer()
  6. initScene()
  7. initCamera()
  8. setTimeout(()=>{
  9. // Obscuration.style.display = 'none'
  10. startButton.style.display = 'none'
  11. },3000)
  12. }

到这里就可以实现啦

实现的地址

tschristmas.haihaina.cn

完整代码我都已经放在码云上面了

海海/christmas

感兴趣的可以自己克隆

有什么不明白的可以提问哦

http://print.haihaina.cn/qr.jpg

标签: css3 前端 css

本文转载自: https://blog.csdn.net/m0_56344602/article/details/122139675
版权归原作者 海海呐 所有, 如有侵权,请联系我们删除。

“圣诞节用女神照片做了一个旋转木马”的评论:

还没有评论