炫酷的花式滑块滑动无缝切换特效

Posted 海拥✘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了炫酷的花式滑块滑动无缝切换特效相关的知识,希望对你有一定的参考价值。

给大家安利一个免费且实用的前端刷题(面经大全)网站,👉点击跳转到网站

在线演示地址https://haiyong.site/moban/texiao/1/
源码下载地址https://code.haiyong.site/33/

✨ 项目基本结构

目录结构如下:

├── css
│   └── style.css
├── js
│   └── script.js
└── index.html

本节教程我会带大家使用 HTML 、CSS和 JS 来制作一个 炫酷的花式滑块滑动无缝切换特效

本节示例将会实现如下所示的效果:


下面让我们一起来实现吧!

HTML

HTML中<body></body>内的代码:

<div class="demo-cont">
  <!-- slider start -->
  <div class="fnc-slider example-slider">
    <div class="fnc-slider__slides">
      <!-- slide start -->
      <div class="fnc-slide m--blend-green m--active-slide">
        <div class="fnc-slide__inner">
          <div class="fnc-slide__mask">
            <div class="fnc-slide__mask-inner"></div>
          </div>
          <div class="fnc-slide__content">
            <h2 class="fnc-slide__heading">
              <div class="fnc-slide__heading-line">
                <span>Black</span>
              </div>
              <div class="fnc-slide__heading-line">
                <span>Widow</span>
              </div>
            </h2>
            <button type="button" class="fnc-slide__action-btn">
              Credits
              <span data-text="Credits">Credits</span>
            </button>
          </div>
        </div>
      </div>
      <!-- slide end -->
      <!-- slide start -->
      <div class="fnc-slide m--blend-dark">
        <div class="fnc-slide__inner">
          <div class="fnc-slide__mask">
            <div class="fnc-slide__mask-inner"></div>
          </div>
          <div class="fnc-slide__content">
            <h2 class="fnc-slide__heading">
              <div class="fnc-slide__heading-line">
                <span>Captain</span>
              </div>
              <div class="fnc-slide__heading-line">
                <span>America</span>
              </div>
            </h2>
            <button type="button" class="fnc-slide__action-btn">
              Credits
              <span data-text="Credits">Credits</span>
            </button>
          </div>
        </div>
      </div>
      <!-- slide end -->
      <!-- slide start -->
      <div class="fnc-slide m--blend-red">
        <div class="fnc-slide__inner">
          <div class="fnc-slide__mask">
            <div class="fnc-slide__mask-inner"></div>
          </div>
          <div class="fnc-slide__content">
            <h2 class="fnc-slide__heading">
              <div class="fnc-slide__heading-line">
                <span>Iron</span>
              </div>
              <div class="fnc-slide__heading-line">
                <span>Man</span>
              </div>
            </h2>
            <button type="button" class="fnc-slide__action-btn">
              Credits
              <span data-text="Credits">Credits</span>
            </button>
          </div>
        </div>
      </div>
      <!-- slide end -->
      <!-- slide start -->
      <div class="fnc-slide m--blend-blue">
        <div class="fnc-slide__inner">
          <div class="fnc-slide__mask">
            <div class="fnc-slide__mask-inner"></div>
          </div>
          <div class="fnc-slide__content">
            <h2 class="fnc-slide__heading">
              <div class="fnc-slide__heading-line">
                <span>Thor</span>
              </div>
              <div class="fnc-slide__heading-line">
                <span>Just Thor</span>
              </div>
            </h2>
            <button type="button" class="fnc-slide__action-btn">
              Credits
              <span data-text="Credits">Credits</span>
            </button>
          </div>
        </div>
      </div>
      <!-- slide end -->
    </div>
    <nav class="fnc-nav">
      <div class="fnc-nav__bgs">
        <div class="fnc-nav__bg m--navbg-green m--active-nav-bg"></div>
        <div class="fnc-nav__bg m--navbg-dark"></div>
        <div class="fnc-nav__bg m--navbg-red"></div>
        <div class="fnc-nav__bg m--navbg-blue"></div>
      </div>
      <div class="fnc-nav__controls">
        <button class="fnc-nav__control">
          Black Widow
          <span class="fnc-nav__control-progress"></span>
        </button>
        <button class="fnc-nav__control">
          Captain America
          <span class="fnc-nav__control-progress"></span>
        </button>
        <button class="fnc-nav__control">
          Iron Man
          <span class="fnc-nav__control-progress"></span>
        </button>
        <button class="fnc-nav__control">
          Thor
          <span class="fnc-nav__control-progress"></span>
        </button>
      </div>
    </nav>
  </div>
  <!-- slider end -->
  <div class="demo-cont__credits">
    <div class="demo-cont__credits-close"></div>
    <h2 class="demo-cont__credits-heading">Made by</h2>
    <img src="//s3-us-west-2.amazonaws.com/s.cdpn.io/142996/profile/profile-512_5.jpg" alt="" class="demo-cont__credits-img" />
    <h3 class="demo-cont__credits-name">Nikolay Talanov</h3>
    <a href="https://codepen.io/suez/" target="_blank" class="demo-cont__credits-link">My codepen</a>
    <a href="https://twitter.com/NikolayTalanov" target="_blank" class="demo-cont__credits-link">My twitter</a>
    <h2 class="demo-cont__credits-heading">Based on</h2>
    <a href="https://dribbble.com/shots/2375246-Fashion-Butique-slider-animation" target="_blank" class="demo-cont__credits-link">Concept by Kreativa Studio</a>
    <h4 class="demo-cont__credits-blend">Global Blend Mode</h4>
    <div class="colorful-switch">
      <input type="checkbox" class="colorful-switch__checkbox js-activate-global-blending" id="colorful-switch-cb" />
      <label class="colorful-switch__label" for="colorful-switch-cb">
        <span class="colorful-switch__bg"></span>
        <span class="colorful-switch__dot"></span>
        <span class="colorful-switch__on">
          <span class="colorful-switch__on__inner"></span>
        </span>
        <span class="colorful-switch__off"></span>
      </label>
    </div>
  </div>
</div>

CSS

部分 CSS 代码:

.fnc 
  /* you can add color names and their values here
  and then simply add classes like .m--blend-$colorName to .fnc-slide 
  to apply specific color for mask blend mode */

.fnc-slider 
  overflow: hidden;
  box-sizing: border-box;
  position: relative;
  height: 100vh;

.fnc-slider *, .fnc-slider *:before, .fnc-slider *:after 
  box-sizing: border-box;

.fnc-slider__slides 
  position: relative;
  height: 100%;
  transition: transform 1s 0.6666666667s;

.fnc-slider .m--blend-dark .fnc-slide__inner 
  background-color: #8a8a8a;

.fnc-slider .m--blend-dark .fnc-slide__mask-inner 
  background-color: #575757;

.fnc-slider .m--navbg-dark 
  background-color: #575757;

.fnc-slider .m--blend-green .fnc-slide__inner 
  background-color: #6d9b98;

.fnc-slider .m--blend-green .fnc-slide__mask-inner 
  background-color: #42605E;

.fnc-slider .m--navbg-green 
  background-color: #42605E;

.fnc-slider .m--blend-red .fnc-slide__inner 
  background-color: #ea2329;

.fnc-slider .m--blend-red .fnc-slide__mask-inner 
  background-color: #990e13;

.fnc-slider .m--navbg-red 
  background-color: #990e13;

.fnc-slider .m--blend-blue .fnc-slide__inner 
  background-color: #59aecb;

.fnc-slider .m--blend-blue .fnc-slide__mask-inner 
  background-color: #2D7791;

.fnc-slider .m--navbg-blue 
  background-color: #2D7791;

.fnc-slide 
  overflow: hidden;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  transform: translate3d(0, 0, 0);

JS

部分JS代码:

fncSlider(".example-slider", autoSlidingDelay: 4000);

var $demoCont = document.querySelector(".demo-cont");

[].slice.call(document.querySelectorAll(".fnc-slide__action-btn")).forEach(function($btn) 
  $btn.addEventListener("click", function() 
    $demoCont.classList.toggle("credits-active");
  );
);

document.querySelector(".demo-cont__credits-close").addEventListener("click", function() 
  $demoCont.classList.remove("credits-active");
);

document.querySelector(".js-activate-global-blending").addEventListener("click", function() 
  document.querySelector(".example-slider").classList.toggle("m--global-blending-active");
);

到此,仿 GitHub 登录页面的效果就实现啦!

📑 完整源码下载⬇

到此我们的产品展示界面就完成了,本实验的完整代码已上传,下载地址:

https://code.haiyong.site/33/

⭐️ 好书推荐

《人工智能导论》

【内容简介】

科大讯飞校企合编教材,涵盖人工智能各个重要体系,详解人工智能基础理论,详细解读算法逻辑:详解机器学习、人工神经网络、智能语音识别、自然语言处理、知识图谱与机器人等核心算法知识,清晰介绍实战步骤:有理论有实战,介绍了人工智能算法与技术的实际应用,步骤清楚,条理清晰,即学即用。

📚 京东自营购买链接:《人工智能导论》

以上是关于炫酷的花式滑块滑动无缝切换特效的主要内容,如果未能解决你的问题,请参考以下文章

炫酷的花式滑块滑动无缝切换特效

非常炫酷的网页样式特效

JParticles 2.0 发布,打造炫酷的粒子特效

七款炫酷的页面特效

159-使用 clip-path 实现一个炫酷的按钮悬停特效

动态炫酷的js背景特效库集锦