增强gif背景翻转的性能

时间:2014-11-19 09:53:48

标签: jquery html css performance animated-gif

我在css中做了一个很酷的翻转,当父母徘徊时显示一个动画gif。

这是我的代码:http://codepen.io/clemeeent/pen/oggzMa

问题是我将会有大约40天的时间,所有人都可以随时在圆圈后面播放动画GIF。我不确定任何浏览器/计算机/连接可以处理那么多。我试图找出一个像以下的解决方案:

$( ".day" ).mouseenter(function() {
  $( ".play" ).append( "<img src="http://media.giphy.com/media/5Vb7xQB7Z3ScE/giphy.gif">" );
});

但我绝对不确定它会更好......

如果有人想要增强该代码,那将非常感激。

PS:gif只是一个样本,最终结果真的很棒:p

1 个答案:

答案 0 :(得分:0)

正如上面评论中已经提到的那样

使用css执行类似的操作

&#13;
&#13;
img {
    border-radius:50%;
}
.day {
    margin: 15px;
    height: 90px;
    width: 90px;
    float: left;
    position: relative;
    cursor: pointer;
}
.play {
    height: 90px;
    position: absolute;
    width: 90px;
    left: 50%;
    top: 50%;
    margin: -45px 0 0 -45px;
    z-index: -1;
    transition-duration: 100ms;
    transition-timing-function: ease-in-out;
    -moz-transition-property: all;
    -moz-transition-duration: 100ms;
    -moz-transition-timing-function: ease-in-out;
    -webkit-transition-property: all;
    -webkit-transition-duration: 100ms;
    -webkit-transition-timing-function: ease-in-out;
    -o-transition-property: all;
    -o-transition-duration: 100ms;
    -o-transition-timing-function: ease-in-out;
}
.play img {
    width: 100%;
    border-radius: 50%;
}
.badge {
    height: 35px;
    width: 35px;
    background: #ed2c27;
    border-radius: 50%;
    font-size: 18px;
    position: absolute;
    top: 0;
    right: 0;
    text-align: center;
    font-family:'Satisfy', cursive;
}
.day:hover .spinner {
    position: absolute;
    display: block;
    height: 95px;
    width: 95px;
    left: -5px;
    top: -5px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: black;
    -webkit-animation: spin 2s linear infinite;
    animation: spin 2s linear infinite;
}
.day:hover .spinner:before {
    content:"";
    position: absolute;
    top: 0px;
    left: 0px;
    right: 0px;
    bottom: 0px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: black;
    -webkit-animation: spin 3s linear infinite;
    animation: spin 3s linear infinite;
}
.day:hover .spinner:after {
    content:"";
    position: absolute;
    top: 3px;
    left: 3px;
    right: 3px;
    bottom: 3px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: black;
    -webkit-animation: spin 1.5s linear infinite;
    animation: spin 1.5s linear infinite;
}
@-webkit-keyframes spin {
    0% {
        -webkit-transform: rotate(0deg);
        -ms-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    100% {
        -webkit-transform: rotate(360deg);
        -ms-transform: rotate(360deg);
        transform: rotate(360deg);
    }
}
@keyframes spin {
    0% {
        -webkit-transform: rotate(0deg);
        -ms-transform: rotate(0deg);
        transform: rotate(0deg);
    }
    100% {
        -webkit-transform: rotate(360deg);
        -ms-transform: rotate(360deg);
        transform: rotate(360deg);
    }
}
&#13;
<div class="day">
    <!-- 1 -->
    <div class="spinner"></div>
    <img data-src="holder.js/90x90" class="img-circle" style="width: 90px; height: 90px; background-color:#D3D3D3;" /> <span class="badge">1</span>

</div>
&#13;
&#13;
&#13;