css+js实现三维可拖拽旋转木马图片转盘效果代码

代码语言:html

所属分类:其他

代码描述:css+js实现三维可拖拽旋转木马图片转盘效果代码

代码标签: css js 三维 可拖拽 旋转 木马 图片 转盘

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">

<style>
    body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #1d1e22;
}

img {
  display: block;
  max-width: 100%;
  height: 100%;
  -o-object-fit: cover;
     object-fit: cover;
}

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.container-carrousel {
  --widthItem: 150px;
  --heightItem: 100px;
  width: var(--widthItem);
  height: var(--heightItem);
  perspective: 1000px;
}

.carrousel {
  --rotatey: 0;
  font-size: 4rem;
  position: relative;
  transform: rotatey(var(--rotatey));
  transform-style: preserve-3d;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
  cursor: -webkit-grab;
  cursor: grab;
}

.carrousel-item {
  opacity: 0.5;
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 5px;
  transition: opacity 0.5s;
}

.carrousel-item:hover {
  opacity: 1;
}

.carrousel,
.carrousel-item {
  width: 100%;
  height: 100%;
}

.carrousel-item:nth-child(1) {
  --rotatey: 0;
  transform: rotatey(var(--rotatey)) translatez(var(--tz));
  background-image: url(//repo.bfw.wiki/bfwrepo/image/637ec63462777.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_600,h_400,/quality,q_90);
}

.carrousel-item:nth-child(2) {
  --rotatey: 0;
  transform: rotatey(var(--rotatey)) translatez(var(--tz));
  background-image: url(//repo.bfw.wiki/bfwrepo/image/637f4b90dd24d.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_600,h_400,/quality,q_90);
}

.carrousel-item:nth-child(3) {
  --rotatey: 0;
  transform: rotatey(var(--rotatey)) translatez(var(--tz));
  background-image: url(//repo.bfw.wiki/bfwrepo/image/637f4bacaa7f3.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_600,h_400,/quality,q_90);
}
.carrousel-item:nth-child(4) {
  --rotatey: 0;
  transform: rotatey(var(--rotatey)) translatez(var(--tz));
  background-image: url(//repo.bfw.wiki/bfwrepo/image/63803c24f1eeb.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_600,h_400,/quality,q_90);
}

.carrousel-item:nth-child(5) {
  --rotate: 0;
  transform: rotatey(var(--rotatey)) translatez(var(--tz));
  background-image: url(//repo.bfw.wiki/bfwrepo/image/63829c2f1dabd.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_600,h_400,/quality,q_90);
}

.carrousel-item:nth-child(6) {
  --rotatey: 0;
  transform: rotatey(var(--rotatey)) translatez(var(--tz));
  background-image: url(//repo.bfw.wiki/bfwrepo/image/638326893882b.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_600,h_400,/quality,q_90);
}

@media screen and (min-width: 576px) {
  .container-carrousel {
  --widthItem: 250px;
  --heightItem: 200px;
  }
}
</style>
</head>
<body>

<div class="container">
  <div class="container-carrousel">
    <div class="carrousel">
      <div class="carrousel-item"></div>
      <div class="carrousel-item"></div>
      <div class="carrousel-item"></div>
      <div class="carrousel-item"></div>
      <div class="carrousel-item"></div>
      <div class="carrousel-item"></div>
    </div>
  </div>  
</div>
<!-- partial -->
  <script >
      const container = document.querySelector(".container");
const containerCarrousel = container.querySelector(".container-carrousel");
const carrousel = container.querySelector(".carrousel");
const carrouselItem.........完整代码请登录后点击上方下载按钮下载查看

网友评论0