2016-02-22 14 views
0

在www。 www.coachella.com他们有这些穿梭巴士图标,其中3个,并悬停图标四处移动。我如何为我的网站做这样的事情?有没有指南?这个网站如何使他们的巴士图标在悬停上移动?

我查看了源代码,它很混乱,但看起来他们有3个SVG标签,它们在悬停时动画。这对一般的乔来说有多难?

<div id="icon-shuttles" class="icon"> 
      <!-- Generator: Adobe Illustrator 19.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> 
      <svg version="1.1" id="icon-shuttles-base-1" class="absolutePosition" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 305.8 350.7" style="transform-origin: 100% 50% 0px; transform: matrix(1, 0, 0, 1, 0, 0);" xml:space="preserve"> 
      <style type="text/css"> 
       .st0-shuttles{fill:#FCFCFC;} 
       .st1-shuttles{fill:#FCA126;} 
       .st2-shuttles{fill:#CB821F;} 
      </style> 
      <rect x="25.6" y="50" class="st0-shuttles" width="255" height="154.5"></rect> 
      <path class="st1-shuttles" d="M28.3,154.5c0.4-15.2,0.8-30.3,1.2-45.4c0.1-2.5,0.1-5.1,0.2-7.6C30,91.3,30.4,81.2,30.5,71 
       c0-7.4,6.4-10.6,13.9-12.1c6.8-1.3,14.5-1.2,19.1-1.4c12.7-0.6,25.4-0.8,38.1-1.1c17-0.3,34.1-0.4,51.4-0.4V35.3h-24.1 
       c-5.5,0-10-4.5-10-10V25c0-5.5,4.5-10,10-10H153V0H37C20.5,0,7,13.5,7,30L6.2,56.7L4.9,99.9L1.7,209.3l-1,32.8l-0.3,8.8l-0.3,10.9 
       L0,265.4c0,7.2,2.6,15.7,6.8,23c0.8,1.4,1.7,2.7,2.6,4c1.5,2,3,3.9,4.7,5.5c0.2,0.2,0.3,0.3,0.5,0.5v44.1c0,4.4,3.6,8,8,8h40 
       c4.4,0,8-3.6,8-8v-23.2h82.2v-14v-35.2l0,0v-67.6c-8.1,0-16.1-0.1-24.2-0.2c-15.6-0.2-31.2-0.3-46.7-1.2c-7.1-0.4-14.1-0.9-21.1-1.7 
       c-5.4-0.7-10.9-1.5-16.3-2.7c-1.1-0.2-2.2-0.5-3.3-0.8c-2.8-0.8-5.5-1.9-7.8-3.6c-6.8-4.9-5.9-12.5-5.7-20 
       C28,166.5,28.1,160.5,28.3,154.5z"></path> 
      <path class="st2-shuttles" d="M277.6,154.5c-0.4-15.2-0.8-30.3-1.2-45.4c-0.1-2.5-0.1-5.1-0.2-7.6c-0.3-10.2-0.7-20.3-0.8-30.5 
       c0-7.4-6.4-10.6-13.9-12.1c-6.8-1.3-14.5-1.2-19.1-1.4c-12.7-0.6-25.4-0.8-38.1-1.1c-17-0.3-34.1-0.4-51.4-0.4V35.3H177 
       c5.5,0,10-4.5,10-10V25c0-5.5-4.5-10-10-10h-24.1V0h115.9c16.5,0,30,13.5,30,30l0.8,26.7l1.3,43.2l3.2,109.4l1,32.8l0.3,8.8 
       l0.3,10.9l0.1,3.6c0,7.2-2.6,15.7-6.8,23c-0.8,1.4-1.7,2.7-2.6,4c-1.5,2-3,3.9-4.7,5.5c-0.2,0.2-0.3,0.3-0.5,0.5v44.1 
       c0,4.4-3.6,8-8,8h-40c-4.4,0-8-3.6-8-8v-23.2H153v-14v-35.2l0,0v-67.6c8.1,0,16.1-0.1,24.2-0.2c15.6-0.2,31.2-0.3,46.7-1.2 
       c7.1-0.4,14.1-0.9,21.1-1.7c5.4-0.7,10.9-1.5,16.3-2.7c1.1-0.2,2.2-0.5,3.3-0.8c2.8-0.8,5.5-1.9,7.8-3.6c6.8-4.9,5.9-12.5,5.7-20 
       C277.9,166.5,277.7,160.5,277.6,154.5z"></path> 
      <circle class="st0-shuttles" cx="55.6" cy="251" r="26.5"></circle> 
      <circle class="st0-shuttles" cx="250.6" cy="251" r="26.5"></circle> 
      </svg> 

      <!-- Generator: Adobe Illustrator 19.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> 
      <svg version="1.1" id="icon-shuttles-base-3" class="absolutePosition" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 305.8 350.7" style="transform: matrix(1, 0, 0, 1, 0, 0); transform-origin: 0% 50% 0px;" xml:space="preserve"> 
      <style type="text/css"> 
       .st0-shuttles{fill:#FCFCFC;} 
       .st1-shuttles{fill:#FCA126;} 
       .st2-shuttles{fill:#CB821F;} 
      </style> 
      <rect x="25.6" y="50" class="st0-shuttles" width="255" height="154.5"></rect> 
      <path class="st1-shuttles" d="M28.3,154.5c0.4-15.2,0.8-30.3,1.2-45.4c0.1-2.5,0.1-5.1,0.2-7.6C30,91.3,30.4,81.2,30.5,71 
       c0-7.4,6.4-10.6,13.9-12.1c6.8-1.3,14.5-1.2,19.1-1.4c12.7-0.6,25.4-0.8,38.1-1.1c17-0.3,34.1-0.4,51.4-0.4V35.3h-24.1 
       c-5.5,0-10-4.5-10-10V25c0-5.5,4.5-10,10-10H153V0H37C20.5,0,7,13.5,7,30L6.2,56.7L4.9,99.9L1.7,209.3l-1,32.8l-0.3,8.8l-0.3,10.9 
       L0,265.4c0,7.2,2.6,15.7,6.8,23c0.8,1.4,1.7,2.7,2.6,4c1.5,2,3,3.9,4.7,5.5c0.2,0.2,0.3,0.3,0.5,0.5v44.1c0,4.4,3.6,8,8,8h40 
       c4.4,0,8-3.6,8-8v-23.2h82.2v-14v-35.2l0,0v-67.6c-8.1,0-16.1-0.1-24.2-0.2c-15.6-0.2-31.2-0.3-46.7-1.2c-7.1-0.4-14.1-0.9-21.1-1.7 
       c-5.4-0.7-10.9-1.5-16.3-2.7c-1.1-0.2-2.2-0.5-3.3-0.8c-2.8-0.8-5.5-1.9-7.8-3.6c-6.8-4.9-5.9-12.5-5.7-20 
       C28,166.5,28.1,160.5,28.3,154.5z"></path> 
      <path class="st2-shuttles" d="M277.6,154.5c-0.4-15.2-0.8-30.3-1.2-45.4c-0.1-2.5-0.1-5.1-0.2-7.6c-0.3-10.2-0.7-20.3-0.8-30.5 
       c0-7.4-6.4-10.6-13.9-12.1c-6.8-1.3-14.5-1.2-19.1-1.4c-12.7-0.6-25.4-0.8-38.1-1.1c-17-0.3-34.1-0.4-51.4-0.4V35.3H177 
       c5.5,0,10-4.5,10-10V25c0-5.5-4.5-10-10-10h-24.1V0h115.9c16.5,0,30,13.5,30,30l0.8,26.7l1.3,43.2l3.2,109.4l1,32.8l0.3,8.8 
       l0.3,10.9l0.1,3.6c0,7.2-2.6,15.7-6.8,23c-0.8,1.4-1.7,2.7-2.6,4c-1.5,2-3,3.9-4.7,5.5c-0.2,0.2-0.3,0.3-0.5,0.5v44.1 
       c0,4.4-3.6,8-8,8h-40c-4.4,0-8-3.6-8-8v-23.2H153v-14v-35.2l0,0v-67.6c8.1,0,16.1-0.1,24.2-0.2c15.6-0.2,31.2-0.3,46.7-1.2 
       c7.1-0.4,14.1-0.9,21.1-1.7c5.4-0.7,10.9-1.5,16.3-2.7c1.1-0.2,2.2-0.5,3.3-0.8c2.8-0.8,5.5-1.9,7.8-3.6c6.8-4.9,5.9-12.5,5.7-20 
       C277.9,166.5,277.7,160.5,277.6,154.5z"></path> 
      <circle class="st0-shuttles" cx="55.6" cy="251" r="26.5"></circle> 
      <circle class="st0-shuttles" cx="250.6" cy="251" r="26.5"></circle> 
      </svg> 

      <!-- Generator: Adobe Illustrator 19.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> 
      <svg version="1.1" id="icon-shuttles-base-2" class="absolutePosition" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 305.8 350.7" style="enable-background:new 0 0 305.8 350.7;" xml:space="preserve"> 
      <style type="text/css"> 
       .st0-shuttles{fill:#FCFCFC;} 
       .st1-shuttles{fill:#FCA126;} 
       .st2-shuttles{fill:#CB821F;} 
      </style> 
      <rect x="25.6" y="50" class="st0-shuttles" width="255" height="154.5"></rect> 
      <path class="st1-shuttles" d="M28.3,154.5c0.4-15.2,0.8-30.3,1.2-45.4c0.1-2.5,0.1-5.1,0.2-7.6C30,91.3,30.4,81.2,30.5,71 
       c0-7.4,6.4-10.6,13.9-12.1c6.8-1.3,14.5-1.2,19.1-1.4c12.7-0.6,25.4-0.8,38.1-1.1c17-0.3,34.1-0.4,51.4-0.4V35.3h-24.1 
       c-5.5,0-10-4.5-10-10V25c0-5.5,4.5-10,10-10H153V0H37C20.5,0,7,13.5,7,30L6.2,56.7L4.9,99.9L1.7,209.3l-1,32.8l-0.3,8.8l-0.3,10.9 
       L0,265.4c0,7.2,2.6,15.7,6.8,23c0.8,1.4,1.7,2.7,2.6,4c1.5,2,3,3.9,4.7,5.5c0.2,0.2,0.3,0.3,0.5,0.5v44.1c0,4.4,3.6,8,8,8h40 
       c4.4,0,8-3.6,8-8v-23.2h82.2v-14v-35.2l0,0v-67.6c-8.1,0-16.1-0.1-24.2-0.2c-15.6-0.2-31.2-0.3-46.7-1.2c-7.1-0.4-14.1-0.9-21.1-1.7 
       c-5.4-0.7-10.9-1.5-16.3-2.7c-1.1-0.2-2.2-0.5-3.3-0.8c-2.8-0.8-5.5-1.9-7.8-3.6c-6.8-4.9-5.9-12.5-5.7-20 
       C28,166.5,28.1,160.5,28.3,154.5z"></path> 
      <path class="st2-shuttles" d="M277.6,154.5c-0.4-15.2-0.8-30.3-1.2-45.4c-0.1-2.5-0.1-5.1-0.2-7.6c-0.3-10.2-0.7-20.3-0.8-30.5 
       c0-7.4-6.4-10.6-13.9-12.1c-6.8-1.3-14.5-1.2-19.1-1.4c-12.7-0.6-25.4-0.8-38.1-1.1c-17-0.3-34.1-0.4-51.4-0.4V35.3H177 
       c5.5,0,10-4.5,10-10V25c0-5.5-4.5-10-10-10h-24.1V0h115.9c16.5,0,30,13.5,30,30l0.8,26.7l1.3,43.2l3.2,109.4l1,32.8l0.3,8.8 
       l0.3,10.9l0.1,3.6c0,7.2-2.6,15.7-6.8,23c-0.8,1.4-1.7,2.7-2.6,4c-1.5,2-3,3.9-4.7,5.5c-0.2,0.2-0.3,0.3-0.5,0.5v44.1 
       c0,4.4-3.6,8-8,8h-40c-4.4,0-8-3.6-8-8v-23.2H153v-14v-35.2l0,0v-67.6c8.1,0,16.1-0.1,24.2-0.2c15.6-0.2,31.2-0.3,46.7-1.2 
       c7.1-0.4,14.1-0.9,21.1-1.7c5.4-0.7,10.9-1.5,16.3-2.7c1.1-0.2,2.2-0.5,3.3-0.8c2.8-0.8,5.5-1.9,7.8-3.6c6.8-4.9,5.9-12.5,5.7-20 
       C277.9,166.5,277.7,160.5,277.6,154.5z"></path> 
      <circle class="st0-shuttles" cx="55.6" cy="251" r="26.5"></circle> 
      <circle class="st0-shuttles" cx="250.6" cy="251" r="26.5"></circle> 
      </svg> 



      <div id="icon-shuttles-hit" class="icon-hit-square"></div> 
     </div> 
+1

这很简单直接。如果您不知道如何制作CSS动画,可以使用动画库,如Animate CSS https://daneden.github.io/animate.css/ –

+0

观看脚本https://www.coachella.com/wp- content/themes/coachella2016/js/scripts.js – sglazkov

回答

2

如果不熟悉SVGs你可以只交换他们出去标准PNG图标。可以找到关于SVG的一些信息here

动画部分很简单,只需将鼠标悬停上的两个总线图标添加到transform:translate3D即可完成。

假设你有一个3格的div。每个div包含总线(可能是一个SVG,PNG图标字体或类似)

HTML

<div class="buses"> 
    <div class="bus-1"></div> 
    <div class="bus-2"></div> 
    <div class="bus-3"></div> 
</div> 

你的CSS看起来财产以后这样的:

CSS

.buses .bus-1, 
.buses .bus-3 { 
    /* This determines the duration of the animation */ 

    -webkit-transition: -webkit-transform 600ms ease; 
    transition: transform 600ms ease; 
} 

.buses:hover .bus-1 { 
    /* The translate property will move the bus in an x,y,z direction */ 

    -webkit-transform: translate3D(-10px, 0, 0);  
    transform: translate3D(-10px, 0, 0); 
} 

.buses:hover .bus-3 { 
    /* The translate property will move the bus in an x,y,z direction */ 

    -webkit-transform: translate3D(10px, 0, 0);  
    transform: translate3D(10px, 0, 0); 
} 
+0

非常好的解释。 – Badrush

1

通过引用id:“图标班车”我能够通过该网站的JavaScript文件搜索和定位的一段代码转换的图标,并创建你问的动画。

// shuttles -- 

var _onOver_shuttles = function() { 
    TweenMax.to('#icon-shuttles-base-1', 0.3, {x:-9, scale:1.2, transformOrigin:"100% 50%", ease:Power1.easeOut}); 
    TweenMax.to('#icon-shuttles-base-3', 0.3, {delay:0.15, x:8, scale:1.2, transformOrigin:"0% 50%", ease:Power1.easeOut}); 
} 

var _onOut_shuttles = function() { 
    // in case delayed tween hasn't fired 
    TweenMax.killTweensOf('#icon-shuttles-base-3'); 

    TweenMax.to('#icon-shuttles-base-1', 0.2, {x:0, scale:1.0, transformOrigin:"100% 50%", ease:Power1.easeInOut}); 
    TweenMax.to('#icon-shuttles-base-3', 0.2, {x:0, scale:1.0, transformOrigin:"0% 50%", ease:Power1.easeInOut}); 
} 

我没那么熟悉SVG和CSS动画,但它看起来像他们所使用的变换原点物业移动页面图标周围。

查看以下链接以更好地了解SVG动画是什么以及它们如何工作。

The Simple Intro to SVG Animation

CSS3 Transform-origin

+0

'TweenMax'是[GSAP]的一部分(http://greensock.com/gsap) – zzzzBov

相关问题