这个网站如何使他们的公交车图标在悬停时移动?

时间:2016-02-22 23:27:28

标签: html css svg

在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>

2 个答案:

答案 0 :(得分:2)

如果您不熟悉SVG,可以将它们换成标准的png图标。可以找到有关SVG的一些信息here

动画部分很简单,只需在悬停时向两个总线图标添加transform:translate3D即可。

假设你有一个div里面有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);
}

答案 1 :(得分:1)

通过引用id:“icon-shuttle”,我能够搜索网站的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动画并不熟悉,但看起来他们正在使用transform-origin属性来移动页面周围的图标。

查看以下链接,以便更好地了解SVG动画是什么以及它们的工作原理。

The Simple Intro to SVG Animation

CSS3 Transform-origin