首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用chrome的html5 + css3滑块动画问题

问使用chrome的html5 + css3滑块动画问题
EN

Stack Overflow用户
提问于 2013-12-20 07:22:53
回答 1查看 532关注 0票数 0

下面是carrousel的CSS3和HTML

http://jsfiddle.net/5P7Gu/

代码语言:javascript
复制
#slider {
    height:150px;
    position:absolute;
    clip:rect(0px,900px,140px,0px);
    overflow:hidden;
}
#insideSlider{
    animation: move1 20s ease 2s infinite   ; 
   -moz-animation: move1 20s ease 2s infinite  ; 
   -webkit-animation: move1 20s ease 2s infinite  ; 
}
#insideSlider:hover {
    -webkit-animation-play-state:paused;
    -moz-animation-play-state:paused;
    -animation-play-state:paused;
}


@keyframes move1 {
0% {transform:translateX(0px);}
10% {transform:translateX(-155px);}
20% {transform:translateX(-310px);}
30% {transform:translateX(-465px);}
40% {transform:translateX(-620px);}
50% {transform:translateX(-775px);}
60% {transform:translateX(-930px);}
70% {transform:translateX(-1085px);}
80% {transform:translateX(-1240px);}
90% {transform:translateX(-1395px);}
100% {-webkit-transform:translateX(0px);}
} 

@-webkit-keyframes move1 {
0% {-webkit-transform:translateX(0px);}
10% {-webkit-transform:translateX(-155px);}
20% {-webkit-transform:translateX(-310px);}
30% {-webkit-transform:translateX(-465px);}
40% {-webkit-transform:translateX(-620px);}
50% {-webkit-transform:translateX(-775px);}
60% {-webkit-transform:translateX(-930px);}
70% {-webkit-transform:translateX(-1085px);}
80% {-webkit-transform:translateX(-1240px);}
90% {-webkit-transform:translateX(-1395px);}
100% {-webkit-transform:translateX(0px);}
}  
@-moz-keyframes move1 {
0% {-moz-transform:translateX(0px);}
10% {-moz-transform:translateX(-155px);}
20% {-moz-transform:translateX(-310px);}
30% {-moz-transform:translateX(-465px);}
40% {-moz-transform:translateX(-620px);}
50% {-moz-transform:translateX(-775px);}
60% {-moz-transform:translateX(-930px);}
70% {-moz-transform:translateX(-1085px);}
80% {-moz-transform:translateX(-1240px);}
90% {-moz-transform:translateX(-1395px);}
100% {-webkit-transform:translateX(0px);}
}  


.vignette {
    display:inline-block;
    width:130px;
    margin:10px;
}

.imageVignette {
    border:1px solid #CCC;
    position:relative;
}

.imageVignette:hover {
    -webkit-transform:scale(1.2,1.2);
    transition:0.3s;
}

.vignette:hover .description{
    bottom:10px;
    transition:0.3s;
}


.description {
    position:absolute;
    bottom:-20px;
    display:block;  
    width:130px;
    height:30px;
    transition:0.3s;
}



.description .detail {
    font-size:12px;
    position:absolute;bottom:0px;
    height:25px;
    text-align:center;
    background-color:#CCC;
    width:100%;
    text-shadow: 1px 1px 2px #AAA;
}

和HTML

代码语言:javascript
复制
<div id="slider">
    <div id="insideSlider">

            <div class="vignette">
                <img  class="imageVignette" src="http://placehold.it/128x128"  />
                <div class="description">
                    <div class="detail">
                        <a href="#">hello1</a>
                    </div>
                </div>
            </div>

            <div class="vignette">
                <img  class="imageVignette" src="http://placehold.it/128x128"  />
                <div class="description">
                    <div class="detail">
                        <a href="#">hello1</a>
                    </div>
                </div>
            </div>

            <div class="vignette">
                <img  class="imageVignette" src="http://placehold.it/128x128"  />
                <div class="description">
                    <div class="detail">
                        <a href="#">hello1</a>
                    </div>
                </div>
            </div>

            <div class="vignette">
                <img  class="imageVignette" src="http://placehold.it/128x128"  />
                <div class="description">
                    <div class="detail">
                        <a href="#">hello1</a>
                    </div>
                </div>
            </div>

            <div class="vignette">
                <img  class="imageVignette" src="http://placehold.it/128x128"  />
                <div class="description">
                    <div class="detail">
                        <a href="#">hello1</a>
                    </div>
                </div>
            </div>

            <div class="vignette">
                <img  class="imageVignette" src="http://placehold.it/128x128"  />
                <div class="description">
                    <div class="detail">
                        <a href="#">hello1</a>
                    </div>
                </div>
            </div>

            <div class="vignette">
                <img  class="imageVignette" src="http://placehold.it/128x128"  />
                <div class="description">
                    <div class="detail">
                        <a href="#">hello1</a>
                    </div>
                </div>
            </div>    

            <div class="vignette">
                <img  class="imageVignette" src="http://placehold.it/128x128"  />
                <div class="description">
                    <div class="detail">
                        <a href="#">hello1</a>
                    </div>
                </div>
            </div>  




    </div>                             
</div>

我有两个问题无法解决

1)在chrome上,当你翻转的时候,有时它会乱成一团,疯狂地向左移动所有的滑块!

2) .detail翻转仅在动画开始之前生效。

欢迎在这个纯css3滑块上的任何线索。

EN

回答 1

Stack Overflow用户

发布于 2013-12-20 09:27:37

我只是稍微更新了你的代码。你可以在here上看看。

1.)在chrome上,我遇到了你上面描述的同样的问题:框的奇怪移动只发生在动画开始之前。所以我删除了你的CSS动画的延迟,它工作得很好。我仍然不确定为什么会发生这种情况,需要再看一眼。

代码语言:javascript
复制
animation: move1 20s ease infinite; /* Removed delay due to weird behaviour */
-moz-animation: move1 20s ease infinite; 
-webkit-animation: move1 20s ease infinite; 

2.)你的CSS中有一些奇怪的位置。我清理了其中的一些,并将悬停时的缩放应用于父对象。

您使用了inline-block,但是忘记了删除尾随的空格(http://css-tricks.com/fighting-the-space-between-inline-block-elements/)。所以我添加了HTML注释来去掉空格。可以随意删除它们,并使用"float: left;“代替"inline-block”。

我做的最后一件事是使用宽度的百分比值,这样您的轮播响应就会更快一些。

EDIT:我忘了将关键帧动画中的转换值更改为百分比值。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20693642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档