布局框架

水平滚动展示图片jQuery特效

阿里云


这是一款效果非常炫酷的 jQuery 水平滚动展示图片特效。该特效在滚动鼠标滚轮的时候,屏幕会水平滚动,展示图片内容。

使用方法

在页面中引入下面的文件。

也想出现在这里?联系我们
创客主机
  1. <link rel="stylesheet" type="text/css" href="assets/css/demo.css" />
  2. <script src="assets/js/jquery.min.js"></script>
  3. <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.2/TweenMax.min.js"></script>
  4. <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.2/plugins/ScrollToPlugin.min.js"></script>
  5. <script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.6/ScrollMagic.min.js"></script>
  6. <script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.6/plugins/animation.gsap.min.js"></script>
  7. <script src="https://unpkg.com/imagesloaded@4.1.4/imagesloaded.pkgd.min.js"></script>
  8. <script src="assets/js/demo.js"></script>

HTML 结构

基本 HTML 结构如下。

  1. <main class="coidea-horizontal" id="intro" role="main">
  2.     <section class="horizontal-container">
  3.       <h1>Community</h1>
  4.       <h2>Capsule</h2>
  5.       <p>I love my beauty. It's not my fault......
  6.     </section>
  7.     <section class="horizontal-container">
  8.       <div class="horizontal-container-content">
  9.         <div class="image image-desktop bottom left">
  10.           <img class="big" src="assets/img/img-1.jpeg" alt="coidea - horizontal scroll" />
  11.         </div>
  12.         <div class="image image-desktop top right">
  13.           <img class="big" src="assets/img/img-2.jpeg" alt="coidea - horizontal scroll" />
  14.         </div>
  15.       </div>
  16.     </section>
  17.     <section class="horizontal-container">
  18.       <div class="horizontal-container-content">
  19.         <div class="image image-desktop middle center">
  20.           <img class="middle" src="assets/img/img-3.jpeg" alt="coidea - horizontal scroll" />
  21.         </div>
  22.         <div class="image image-desktop bottom right">
  23.           <img class="big" src="assets/img/img-4.jpeg" alt="coidea - horizontal scroll" />
  24.         </div>
  25.       </div>
  26.     </section>
  27.     <section class="horizontal-container">
  28.       <div class="horizontal-container-content">
  29.         <div class="image image-desktop top center">
  30.           <img class="big" src="assets/img/img-5.jpeg" alt="coidea - horizontal scroll" />
  31.         </div>
  32.         <div class="image image-desktop middle right">
  33.           <img class="middle" src="assets/img/img-6.jpeg" alt="coidea - horizontal scroll" />
  34.         </div>
  35.       </div>
  36.     </section>
  37. </main>

初始化插件

在页面 DOM 元素加载完毕之后,通过下面的方法来初始化该特效。

  1. $('.coidea-horizontal').imagesLoaded(function() {
  2.     $('.loader').addClass('is-loaded');
  3.  
  4.     var totalWidth = 0,
  5.         timeline = new TimelineMax({ paused: true });
  6.  
  7.     // set width of our scrolling div
  8.     $('.horizontal-container').each(function(index) {
  9.       totalWidth += parseInt($(this).width(), 10);
  10.     });
  11.     $('.coidea-horizontal').css({
  12.       'width': totalWidth
  13.     })
  14.  
  15.     // timeline
  16.     timeline.staggerTo('.image', 0.75, {
  17.         scaleX: 1.20,
  18.         transformOrigin: "right",
  19.         ease: Back.easeOut.config(0.5)
  20.       })
  21.       .staggerTo('.image', 0.75, {
  22.         scaleX: 1,
  23.         transformOrigin: "right",
  24.         ease: Back.easeOut.config(0.5)
  25.       }, 0, '-=0.5');
  26.  
  27.     // mouse wheel
  28.     window.addEventListener("wheel", onWheel);
  29.     // mouse wheel - firefox
  30.     window.addEventListener('DOMMouseScroll', onWheel);
  31.     // touch mobile
  32.     window.addEventListener("touchmove", onWheel);
  33.  
  34.     // main function
  35.     function onWheel(event) {
  36.  
  37.       event.preventDefault();
  38.       var normalized,
  39.           delta = event.wheelDelta,
  40.           scroll = (window.pageXOffset || document.scrollLeft) - (document.clientLeft || 0) || 0;
  41.       if (delta) {
  42.  
  43.         normalized = (delta % 120) == 0 ? -delta / 120 : -delta / 3;
  44.       } else {
  45.  
  46.         delta = event.deltaY || event.detail || 0;
  47.         normalized = -(delta % 3 ? delta * 10 : delta / 3);
  48.       }
  49.  
  50.       timeline.play().restart();
  51.  
  52.       TweenLite.to(window, 0.4, {
  53.         scrollTo: {
  54.           x: scroll + 200 * normalized
  55.         }
  56.       });
  57.     }
  58.   });
  59.  
  60.   // fast fix for resize window and refresh view, attention: not use in production!
  61.   window.onresize = function(){ location.reload(); }

Github 网址:https://github.com/COIDEAwebsite/horizontal-scrolling-with-animated-images

水平滚动展示图片 jQuery 特效

已有 415 人购买
  • qmxu
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!