js+css实现三维3d视觉差异透视图片幻灯片轮播图效果代码

代码语言:html

所属分类:幻灯片

代码描述:js和css实现一个三维视觉差异透视效果的图片幻灯片和轮播图代码

代码标签: 幻灯片 三维 视觉差异 透视 图片

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

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 

    <style>
        body, html { font-size: 100%; 	padding: 0; margin: 0;}
        
        /* Reset */
        *,
        *:after,
        *:before {
        	-webkit-box-sizing: border-box;
        	-moz-box-sizing: border-box;
        	box-sizing: border-box;
        }
        
        /* Clearfix hack by Nicolas Gallagher: http://nicolasgallagher.com/micro-clearfix-hack/ */
        .clearfix:before,
        .clearfix:after {
        	content: " ";
        	display: table;
        }
        
        .clearfix:after {
        	clear: both;
        }
        
        body{
        	background: #494A5F;
        	color: #D5D6E2;
        	font-weight: 500;
        	font-size: 1.05em;
        	font-family: "Microsoft YaHei","Segoe UI", "Lucida Grande", Helvetica, Arial,sans-serif;
        }
            @import url("https://fonts.googleapis.com/css?family=Lora:700");
        @import url("https://fonts.googleapis.com/css?family=Open+Sans");
        :root {
          --z-distance: 8.519vw;
          --from-left: 1;
          --mobile-bkp: 650px;
        }
        
        *, *::before, *::after {
          box-sizing: border-box;
        }
        
        body {
          /*min-height: 100vh;*/
          margin: 0;
          padding: 0;
          /*overflow: hidden;*/
          overflow-x: hidden;
          font-family: Lora, serif;
          font-size: calc(14px + .3vw);
        }
        
        .slider {
          width: 100vw;
          height: 100vh;
          display: -webkit-box;
          display: -ms-flexbox;
          display: flex;
          -webkit-perspective: 1000px;
                  perspective: 1000px;
          -webkit-transform-style: preserve-3d;
                  transform-style: preserve-3d;
        }
        .slider::before, .slider::after {
          content: '';
          left: -1vw;
          top: -1vh;
          display: block;
          position: absolute;
          width: 102vw;
          height: 102vh;
          background-position: center;
          background-size: cover;
          will-change: opacity;
          z-index: -1;
          box-shadow: 0 0 0 50vmax rgba(0, 0, 0, 0.7) inset;
        }
        .slider::before {
          background-image: var(--img-prev);
        }
        .slider::after {
          -webkit-transition: opacity 0.7s;
          transition: opacity 0.7s;
          opacity: 0;
          background-image: var(--img-next);
        }
        .slider--bg-next::after {
          opacity: 1;
        }
        .slider__content {
          margin: auto;
          width: 65vw;
          height: 32.5vw;
          max-height: 60vh;
          will-change: transform;
          -webkit-transform-style: preserve-3d;
                  transform-style: preserve-3d;
          pointer-events: none;
          -webkit-transform: translateZ(var(--z-distance));
                  transform: translateZ(var(--z-distance));
        }
        .slider__images {
          overflow: hidden;
          position: absolute;
          width: 100%;
          height: 100%;
          z-index: 0;
          box-shadow: 0 0 5em #000;
        }
        .slider__images-item {
          position: absolute;
          top: 0;
          left: 0;
          height: 100%;
          width: 100%;
          will-change: transform;
          -webkit-transition-timing-function: ease-in;
                  transition-timing-function: ease-in;
          visibility: hidden;
        }
        .slider__images-item img {
          display: block;
          position: relative;
          left: -1em;
          top: -1em;
          width: calc(100% + 1em * 2);
          height: calc(100% + 1em * 2);
          -o-object-fit: cover;
             object-fit: cover;
          will-change: transform;
        }
        .slider__images-item--active {
          z-index: 20;
          visibility: visible;
        }
        .slider__images-item--subactive {
          z-index: 15;
          visibility: visible;
        }
        .slider__images-item--next {
          -webkit-transform: translateX(100%);
                  transform: translateX(100%);
        }
        .slider__images-item--prev {
          -webkit-transform: translateX(-100%);
                  transform: translateX(-100%);
        }
        .slider__images-item--transit {
          -webkit-transition: opacity 0.7s, -webkit-transform 0.7s;
          transition: opacity 0.7s, -webkit-transform 0.7s;
          transition: transform 0.7s, opacity 0.7s;
          transition: transform 0.7s, opacity 0.7s, -webkit-transform 0.7s;
        }
        .slider__text {
          position: relative;
          height: 100%;
        }
        .slider__text-item {
          position: absolute;
          width: 100%;
          height: 100%;
          padding: 0.5em;
          -webkit-perspective: 1000px;
                  perspective: 1000px;
          -webkit-transform-style: preserve-3d;
                  transform-style: preserve-3d;
        }
        .slider__text-item > * {
          overflow: hidden;
          position: absolute;
        }
        .slider__text-item h3, .slider__text-item p {
          -webkit-transition: -webkit-transform 0.35s ease-out;
          transition: -webkit-transform 0.35s ease-out;
          transition: transform 0.35s ease-out;
          transition: transform 0.35s ease-out, -webkit-transform 0.35s ease-out;
          line-height: 1.5;
          overflow: hidden;
        }
        .slider__text-item h3 {
          background-color: rgba(255, 255, 255, 0.5);
        }
        .slider__text-item p {
          font-family: 'Open Sans', sans-serif;
          padding: 1em;
          color: white;
          text-align: center;
          background-color: rgba(0, 0, 0, 0.5);
        }
        .slider__text-item h3::before, .slider__text-item p::before {
          content: '';
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          -webkit-transform: translateX(0);
                  transform: translateX(0);
          -webkit-transition: -webkit-transform 0.35s ease-out 0.28s;
          transition: -webkit-transform 0.35s ease-out 0.28s;
          transition: transform 0.35s ease-out 0.28s;
          transition: transform 0.35s ease-out 0.28s, -webkit-transform 0.35s ease-out 0.28s;
        }
        .slider__text-item h3::before {
          background-color: #000;
        }
        .slider__text-item p::before {
          background-color: #fff;
        }
        .slider__text-item h3 {
          margin: 0;
          font-size: 3.5em;
          padding: 0 .3em;
          position: relative;
          font-weight: 700;
          -webkit-transform: translateX(-100%);
                  transform: translateX(-100%);
        }
        .slider__text-item p {
          margin: 0;
          -webkit-transform: translateX(100%);
                  transform: translateX(100%);
        }
        .slider__text-item-head {
          top: -0.5em;
          -webkit-transform: translateZ(3em);
                  transform: translateZ(3em);
          -webkit-clip-path: polygon(0 0, 0.5em 100%, 100% 100%, calc(100% - .3em) 0.3em);
                  clip-path: polygon(0 0, 0.5em 100%, 100% 100%, calc(100% - .3em) 0.3em);
        }
        .slider__text-item-info {
          bottom: 0;
          right: 0;
          max-width: 75%;
          min-width: -webkit-min-content;
          min-width: -moz-min-content;
          min-width: min-content;
          -webkit-transform: translateZ(2em);
                  transform: translateZ(2em);
          -webkit-clip-path: polygon(0.5em 0, 100% 0%, calc(100% - .5em) 100%, 0 calc(100% - .5em));
                  clip-path: polygon(0.5em 0, 100% 0%, calc(100% - .5em) 100%, 0 calc(100% - .5em));
        }
        .slider__text-item--active h3, .slider__text-item--active p {
          -webkit-transform: translateX(0);
                  transform: translateX(0);
        }
        .slider__text-item--active h3::before {
          -webkit-transform: translateX(100%);
                  transform: translateX(100%);
        }
        .slider__text-item--active p::before {
          -webkit-transform: translateX(-100%);
                  transform: translateX(-100%);
        }
        .slider__text-item--backwards h3::before, .slider__text-item--backwards p::before {
          -webkit-transition: -webkit-transform 0.35s ease-in;
          transition: -webkit-transform 0.35s ease-in;
          transition: transform 0.35s ease-in;
          transition: transform 0.35s ease-in, -webkit-transform 0.35s ease-in;
        }
        .slider__text-item--backwards h3, .slider__text-item--backwards p {
          -webkit-transition: -webkit-transform 0.35s ease-in 0.35s;
          transition: -webkit-transform 0.35s ease-in 0.35s;
          transition: transform 0.35s ease-in 0.35s;
          transition: transform 0.35s ease-in 0.35s, -webkit-transform 0.35s ease-in 0.35s;
        }
        .slider__nav {
          position: absolute;
          left: 0;
          top: 0;
          width: 100%;
          height: 100%;
          text-align: center;
        }
        .slider__nav-arrows {
          display: -webkit-box;
          display: -ms-flexbox;
          display: flex;
          -webkit-box-pack: justify;
              -ms-flex-pack: justify;
                  justify-content: space-between;
          width: 100%;
          position: absolute;
          top: 0;
          left: 0;
        }
        .slider__nav-arrow {
          height: 100vh;
          width: 50vw;
          text-indent: -9999px;
          white-space: nowrap;
        }
        .slider__nav-arrow--left {
          --arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 4 4'%3E %3Cpolyline points='3 1 1 2 3 3' stroke='white' stroke-width='.3' stroke-opacity='.5' fill='none'%3E%3C/polyline%3E %3C/svg%3E");
          cursor: var(--arrow) 40 40, auto;
        }
        .slider__nav-arrow--right {
          --arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 4 4'%3E %3Cpolyline points='1 1 3 2 1 3' stroke='white' stroke-width='.3' stroke-opacity='.5' fill='none'%3E%3C/polyline%3E %3C/svg%3E");
          cursor: var(--arrow) 40 40, auto;
        }
        .slider__nav-dots {
          margin-top: 88vh;
          display: -webkit-inline-box;
          display: -ms-inline-flexbox;
          display: inline-flex;
          position: relative;
          padding: 1em;
          pointer-events: none;
        }
        .slider__nav-dots::before {
          content: '';
          position: absolute;
          left: calc(1em + 1em + 2px);
          top: calc(1em + 2px);
          width: calc(1em - 2px * 2);
          height: calc(1em / 2 - 2px * 2);
          background-color: rgba(255, 255, 255, 0.9);
          -webkit-transition: -webkit-transform 0.7s ease-out;
          transition: -webkit-transform 0.7s ease-out;
          transition: transform 0.7s ease-out;
          transition: transform 0.7s ease-out, -webkit-transform 0.7s ease-out;
          -webkit-transform: translateX(calc((1em + 1em * 2) * (var(--from-left) - 1)));
                  transform: translateX(calc((1em + 1em * 2) * (var(--from-left) - 1)));
        }
        .slider__nav-dot {
          margin: 0 1em;
          width: 1em;
          height: 0.5em;
          border: 2px solid rgba(255, 255, 255, 0.5);
          /* 
            The cursor is not the default one because of a weird bug 
            related to custom cursors above
          */
          cursor: crosshair;
          pointer-events: all;
          display: inline-block;
        }
        .slider__nav-dot:hover {
          border-color: rgba(255, 255, 255, 0.7);
        }
        .slider__nav-dot:active {
          border-color: rgba(255, 255, 255, 0.5);
        }
        
        @media only screen and (max-width: 650px) {
          .slider::before,
          .slider::after {
            display: none;
          }
        
          .slider__content {
            width: 100vw;
            height: 100vh;
            max-height: 100vh;
          }
        
          .slider__text-item-info {
            bottom: 50%;
            left: 50%;
            -webkit-transform: translate(-50%, 50%);
                    transform: translate(-50%, 50%);
          }
          .slider__text-item-info p {
            padding: 1em .8em;
          }
        
          .slider__text-item-head {
            top: 5vh;
            left: 10vw;
            -webkit-transform: translateZ(0);
                    transform: translateZ(0);
          }
          .slider__text-item-head h3 {
            font-size: 2.5em;
          }
        
          .slider__nav-dots {
            background-color: rgba(0, 0, 0, 0.3);
          }
        
          .slider__nav-arrow {
            width: 10vw;
            position: relative;
            cursor: auto;
          }
          .slider__nav-arrow:active {
            -webkit-filter: brightness(0.5);
                    filter: brightness(0.5);
          }
          .slider__nav-arrow::before {
            content: '';
            background-image: var(--arrow);
            background-size: cover;
            width: 8vw;
            height: 8vw;
            position: absolute;
            top: 50%;
            left: 50%;
            -webkit-transform: translate(-50%, -50%);
                    transform: translate(-50%, -50%);
          }
          .slider__nav-arrow--left {
            background-image: -webkit-linear-gradient(left, rgba(0, 0, 0, 0.7) 0, transparent 100%);
            background-image: linear-gradient(to right, rgba(0, 0, 0, 0.7) 0, transparent 100%);
          }
          .slider__nav-arrow--left:active {
            background-image: -webkit-linear-gradient(left, rgba(0, 0, 0, 0.9) 0, transparent 100%);
            background-image: linear-gradient(to right, rgba(0, 0, 0, 0.9) 0, transparent 100%);
          }
          .slider__nav-arrow--right {
            background-image: -webkit-linear-gradient(right, rgba(0, 0, 0, 0.7) 0, transparent 100%);
            background-image: linear-gradient(to left, rgba(0, 0, 0, 0.7) 0, transparent 100%);
          }
          .slider__nav-arrow--right:active {
            background-image: -webkit-linear-gradient(right, rgba(0, 0, 0, 0.9) 0, transparent 100%);
            background-image: linear-gradient(to left, rgba(0, 0, 0, 0.9) 0, transparent 100%);
          }
        }
    </style>
</head>

<body>

    <div class="slider" id="slider" style="--img-prev:url(//repo.bfw.wiki/bfwrepo/image/600d6e3cb8d5d.png)">
        <div class="slider__content" id="slider-content">
            <div class="slider__images">
                <div class="slider__images-item slider__images-item--active" data-id="1"><img src="//repo.bfw.wiki/bfwrepo/image/600d6e3cb8d5d.png" /></div>
                <div class="slider__images-item" data-id="2"><img src="//repo.bfw.wiki/bfwrepo/image/61471be1086c9.png" /></div>
                <div class="slider__images-item" data-id="3"><img src="//repo.bfw.wiki/bfwrepo/image/5ee9f6f685b56.png" /></div>
                <div class="slider__images-item" data-id="4"><img src="//repo.bfw.wiki/bfwrepo/image/5e323253cf4d2.png" /></div>
                <div class="slider__images-item" data-id="5"><img src="//repo.bfw.wiki/bfwrepo/image/5e957a2236f.........完整代码请登录后点击上方下载按钮下载查看

网友评论0