如何使用CSS3获得此效果?

时间:2013-11-28 12:49:58

标签: css3 css-transitions effect

请问,我怎样才能获得类似右上菜单中的效果,仅使用CSS3? (鼠标悬停 - >圆圈收缩和淡入,鼠标移出 - >圆圈展开并淡出)

http://wpkuzen.com/html/architex/

我试着查看代码并且它很乱,nand找不到解释这个的教程...... 提前谢谢!

3 个答案:

答案 0 :(得分:0)

此效果通过使用CSS转换完成。您有一个属性,而不是立即更改该属性(在悬停或淡出时),您随时间更改该属性。

这里有一个很好的链接,可以帮助您实现目标。 :)

link to transition

答案 1 :(得分:0)

我真的不明白你的评论“我试着查看代码并且它很乱。”

你有一个带注释的完全缩进的CSS!

直接从您的链接中复制粘贴:

/* Positioning the icons and preparing for the animation*/
.nav i {
    position: relative;
    display: inline-block;
    margin: 0 auto;
    padding: 0.4em;
    border-radius: 50%;
    font-size: 2.2em;
    box-shadow: 0 0 0 30px transparent;
    background: rgba(255,255,255,0.1);
    -webkit-transform: translate3d(0, 0, 0);
    -moz-transform: translate3d(0, 0, 0);
    -o-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-transition: box-shadow .6s ease-in-out;
    -moz-transition: box-shadow .6s ease-in-out;
    -o-transition: box-shadow .6s ease-in-out;
    -ms-transition: box-shadow .6s ease-in-out;
    transition: box-shadow .6s ease-in-out;
    width:1.1em !important;
}   

/* Animate the box-shadow to create the effect */
.navbar .nav a:hover i,
.navbar .nav a:active i,
.navbar .nav a:focus i {        
    box-shadow: 0 0 0 0 rgba(255,255,255,0.2);
    -webkit-transition: box-shadow .4s ease-in-out;
    -moz-transition: box-shadow .4s ease-in-out;
    -o-transition: box-shadow .4s ease-in-out;
    -ms-transition: box-shadow .4s ease-in-out;
    transition: box-shadow .4s ease-in-out;
}

答案 2 :(得分:0)

查看this articledemo。它们与您需要的过渡/动画具有非常相似的过渡/动画。

以下是一个例子:

<强> FIDDLE

标记:

<a href="#set-3" class="hi-icon"></a>

CSS

.hi-icon {
    display: inline-block;
    font-size: 0px;
    cursor: pointer;
    margin: 15px 30px;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    text-align: center;
    position: relative;
    z-index: 1;
    color: green;
    box-shadow: 0 0 0 4px #FFF;
    -webkit-transition: color 0.3s;
    -moz-transition: color 0.3s;
    transition: color 0.3s;
}

.hi-icon:before {
    content: "X"; /* place image here */
    font-size: 48px;
    line-height: 90px;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    display: block;
    -webkit-font-smoothing: antialiased;
}


.hi-icon:hover:after {
    -webkit-transform: scale(1.3);
    -moz-transform: scale(1.3);
    -ms-transform: scale(1.3);
    transform: scale(1.3);
    opacity: 0;
}
.hi-icon:after {
    content: '';
    pointer-events: none;
    position: absolute;
    top: -2px;
    left: -2px;
    width: 100%;
    height: 100%;
    border-radius: 50%;    
    padding: 2px;
    z-index: -1;
    background: #FFF;
    -webkit-transition: -webkit-transform 0.2s, opacity 0.3s;
    -moz-transition: -moz-transform 0.2s, opacity 0.3s;
    transition: transform 0.2s, opacity 0.3s;
}