简体   繁体   English

使用CSS3或JS中的div动画对div内容进行动画处理

[英]Animate div content with div's animation in CSS3 or JS

Here is the jsfiddle: http://jsfiddle.net/kimimsc/LEjBR/ 这是jsfiddle: http : //jsfiddle.net/kimimsc/LEjBR/

<section id="portfolioContent" class="blueTheme">
<div class="container mmContainer">
    <div class="pullLeft portfolioVignette">
        <div class="portfolioVignetteFilter">
            <p>Test1</p>
        </div>
    </div>
</div>

#portfolioContent {}
.portfolioVignette {background-color: gold; width: 500px; height: 300px; border-radius: 20px; margin: 20px;}
.portfolioVignette > .portfolioVignetteFilter {height: 300px; width:0px; border-radius: 20px; background-color: rgba(204,204,204,0.5); -webkit-transition: width 0.5s ease-out; -moz-transition: width 0.5s ease-out; -o-transition: width 0.5s ease-out; transition: width 0.5s ease-out;}
.portfolioVignette:hover > .portfolioVignetteFilter {height: 300px; width: 500px; border-radius: 20px; background-color: rgba(204,204,204,0.5);  -webkit-transition: width 0.5s ease-out; -moz-transition: width 0.5s ease-out; -o-transition: width 0.5s ease-out; transition: width 0.5s ease-out;}

So first of all, if you look at the jsfiddle that I provided you will see what I've done. 因此,首先,如果您看一下我提供的jsfiddle,您将看到我做了什么。

Bascily I have a div (in yellow) and I am using css3 transition to animate the width change on another div (grey with 0.5 alpha). 基本上,我有一个div(黄色),并且我正在使用css3过渡来为另一个div(带有0.5 alpha的灰色)上的宽度变化设置动画。 The grey div appears over the yellow on hover and disappears when the hover action is over. 灰色div悬停在黄色上方,当悬停动作结束时消失。 You can also see that there is a text element 'Test1' that is always displayed. 您还可以看到始终显示一个文本元素“ Test1”。

So what I want to do is when there is no hover I would like to have only the yellow element without anything else (so no text aswell) and on hover I would like the text to come with the grey element. 所以我想做的是,当没有悬停时,我只希望有黄色元素,而没有其他内容(所以也没有文本),在悬停时,我希望文本带有灰色元素。

I don't think this is the right way to do it but I couldn't find anything that could help me. 我认为这不是正确的方法,但是我找不到任何可以帮助我的东西。

If I haven't been clear enough. 如果我还不够清楚。 tell me if you have any questions. 告诉我您是否有任何疑问。

Thank you for your help guys, 谢谢您的帮助,

Something like this should do it: 这样的事情应该做到:

.portfolioVignette p {
    width: 0;
    overflow: hidden;
    transition: width 0.5s ease-out;
}

.portfolioVignette:hover p {
    width: 100%;    
}

See it here: http://jsfiddle.net/shomz/LEjBR/6/ 在这里查看: http : //jsfiddle.net/shomz/LEjBR/6/

I did something similar, but interpreted your problem a little differently: 我做了类似的事情,但对您的问题的理解有所不同:

.portfolioVignette p {
 width:0;
 margin-left:0;
 overflow: hidden;
 transition: width .5s ease-out;
 transition: margin-left .5s ease-out;
}

.portfolioVignette:hover p {
 width:100%;
 margin-left:90%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM