简体   繁体   English

CSS:悬停时从左到右对文本进行动画处理[提供的提琴]

[英]CSS: Animating text from left to right on hover [fiddle provided]

I'm having a problem of animating text from left to right. 我在从左到右设置文本动画方面遇到问题。 As far as I'm concerned there's no way out without some hack. 就我而言,没有一些破解是没有出路的。

This is my nav on initial load. 这是我在初始加载时的导航。

在此处输入图片说明

Hovering an element reveals text for the icon 悬停元素会显示图标的文本

在此处输入图片说明

It would be awesome to have text from left => right. 从左侧=>右侧输入文本真是太棒了。

Current 当前

CSS CSS

.menu-item { /* hide and position tooltip */
    opacity: 0;
    transition: opacity 0s ease-in 600ms, opacity 600ms;
}

.menu-item-hover:hover .menu-item {
    opacity: 1;
    transition: opacity 0s ease-in 600ms, opacity 600ms;
}

HTML (handlebars) HTML(车把)

<div class="menu-item-hover">
     <i class="icon-my-menu my-menu"></i>
         <span>
              <span class="menu-item">
                   {{i18n-t 'General.myMenu'}}
              </span>
         </span>
</div>

Link to fiddle : http://jsfiddle.net/kristjanrei/kLd7obvg/ 链接到小提琴: http : //jsfiddle.net/kristjanrei/kLd7obvg/

And the way text should animate 以及文字动画的方式

http://jsfiddle.net/gionaf/SNycF/ http://jsfiddle.net/gionaf/SNycF/

There we go 我们去

http://jsfiddle.net/kLd7obvg/7/ http://jsfiddle.net/kLd7obvg/7/

I just used the :after pseudo element, make it absolute, cover it's parent a use a transition for its width 我只用了:after伪元素,使其成为绝对,覆盖它的父对象,为其宽度使用过渡

.menu-item { /* hide and position tooltip */
    opacity: 0;
    transition: opacity 0s ease-in 600ms, opacity 600ms;
    position: relative;
}

.menu-item:after{
    display: block;
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background-color: #fff;
    transition: width 600ms;
}

.menu-item-hover:hover .menu-item {
    opacity: 1;
    transition: opacity 0s ease-in 600ms, opacity 600ms;
}

.menu-item-hover:hover .menu-item:after{
    width: 0;   
}

To have to text from left to right, just put it as absolute position and change left value 要从左向右发送文本,只需将其放在绝对位置并更改left

 .menu-item { /* hide and position tooltip */ opacity: 0; left:-50px; position:absolute; top:10px; transition: all 600ms; } .menu-item-hover:hover .menu-item { opacity: 1; position:absolute; top:8px; left:40px; transition: all 600ms; } 
 <div class="menu-item-hover"> icon <span> <span class="menu-item"> my-menu </span> </span> </div> 

FIDDLE 小提琴

Try this 尝试这个

   <div class="menu-item-hover">
        icon    
    </div>                     

.menu-item-hover:hover:before {              
    opacity: 1;               
    Content:"my-menu";              
    transition: opacity 0s ease-in 600ms, opacity 600ms;          
}

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

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