js+css实现三维图片层叠堆积鼠标跟随模糊聚焦效果代码

代码语言:html

所属分类:画廊相册

代码描述:js+css实现一组图片三维层叠堆积鼠标跟随模糊聚焦效果代码

代码标签: 图片 模糊 聚焦 层叠

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

<!doctype html>
<html>

<head>
    <meta charset="utf-8">


    <style>
        body {
          background: hsl(213, 8%, 40%);
          display: flex;
          flex-direction: row;
          justify-content: center;
          align-items: center;
          height: 100vh;
          margin: 0;
        }
        
        .container {
          display: flex;
          flex-direction: row;
          transition: all .5s ease;
          perspective: 200px;
          height: 100vh;
        }
        
        .card-common {
          align-self: center;
          cursor: pointer;
          box-shadow: -10px 0 30px -10px hsla(0, 0%, 0%, 0.45);
          transition: all .15s linear;
          transform: rotateY(5deg);
        }
        
        /* clicked elements in dof-container dodge left to fully reveal themselves */
        .reveal:active {
          padding-right: 6em;
          transform: rotateZ(0deg);
          box-shadow: none;
        }
        
        /* Blur Controls */
        
        .blur-container{
          display: flex;
          flex-direction: column;
          position: fixed;
          top: 1em;
          right: 1em;
          box-shadow: 0 0 20px 0 hsla(0, 0%, 0%, 0.66);
          z-index: 2;
        }
        
        .controls-header {
          color: white;
          font-size: 15px;
          background: hsl(2, 49%, 56%);
          padding: 5px;
          margin: 0;
        }
        
        .controls {
          display: flex;
          flex-direction: row;
          height: 40px;
        }
        
        .control-button {
          width: 50px;
          font-size: 30px;
          line-height: 40px;
          background: hsl(216, 14%, 24%);
          border: none;
          cursor: pointer;
          color: white;
          margin: 0;
          padding: 0;
        }
        
        .blur-button:hover {
          background: hsl(216, 14%, 44%);
        }
        
        .indicator {
          background: hsl(219, 15%, 15%);
          width: 80px;
          color: white;
          font-size: 20px;
          text-align: center;
          line-height: 40px;
        }
        
        /* Card controller */
        
        .quantity-container {
          display: flex;
          flex-direction: column;
          position: fixed;
          top: 1em;
          left: 1em;
          box-shadow: 0 0 20px 0 hsla(0, 0%, 0%, 0.66);
          z-index: 2;
        }
    </style>
</head>

<body>
    <div class="quantity-container">
        <p class="controls-header">数量</p>
        <div class="controls">
            <button class="control-button" onClick="decreaseQuantity();">-</button>
            <div id="quantity-level" class="indicator"></div>
            <button class="control-button" onClick="increaseQuantity();">+</button>
        </div>
    </div>
    <div class="blur-container">
        <p class="controls-header">模糊度</p>
        <div class="controls">
            <button class="control-button" onClick="decreaseDepth();">-</button>
            <div id="blur-level" class="indicator"></div>
            <button class="control-button" onClick="increaseDepth();">+</button>
        </div>
    </div>
    <div id="dof-container" class="container">
        <img src="//repo.bfw.wiki/bfwrepo/image/5d653bd0990d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_500,h_500,/quality,q_90" class="card-common" />
        <img src="//repo.bfw.wiki/bfwrepo/image/5d653bd0990d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_500,h_500,/quality,q_90" class="card-common" />
        <img src="//repo.bfw.wiki/bfwrepo/image/5e0c6f2cae508.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_500,h_500,/quality,q_90" class="card-common" />
        <img src="//repo.bfw.wiki/bfwrepo/image/5d653b5271e3b.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_500,h_500,/quality,q_90" class="card-common" />
        <img src="//repo.bfw.wiki/bfwrepo/image/5e0c6f962a0d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_500,h_500,/quality,q_90" class="card-common" />
        <img src="//repo.bfw.wiki/bfwrepo/image/5d653bd0990d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_500,h_500,/quality,q_90" class="card-common" />
    </div>

    <script>
        // global variables
        let currentDepth;
        let targetElement;
        let manualBlur;
        let elementQuantity;
        
        // Initialize
        setTimeout(function() {
          setPerspective();
          setInteractiveElements();
          generateRandomIndex();
        }, 0);
        
        // Applies heights and margins to all elements in dof-container in increasing increments
        function setPerspective() {
          let element = document.getElementById("dof-container"); // target container
          let nodes = element.getElementsByClassName('card-common').length; // target elements in container
          let value = document.getElementById(`quantity-level`);
          let finalWidth;
          let finalMargin;
          let initialWidth
          let marginModifier = 1.4;
          let widthModifier;
   .........完整代码请登录后点击上方下载按钮下载查看

网友评论0