Slide input on hover and stay for few seconds

回眸只為那壹抹淺笑 提交于 2019-12-25 03:32:56

问题


How to open the input box on hover an icon and it should stay open for few seconds then it should automatically slide back to the initial position.

I have tried in css but I need to do this using jquery.

Initially there will be an icon when hover happens then icon should disappear and input box should slide.

Here is the link for the demo what I have tried.

.media{
    width:6%;
    background:yellow;
    height:26px;
    cursor:pointer;
    display:inline-block;
    transition: width 1s;
    -moz-transition: width 1s; /* Firefox 4 */
    -webkit-transition: width 1s; /* Safari and Chrome */
    -o-transition: width 1s; /* Opera */
    -ms-transition: width 1s; /* IE9 (maybe) */
    vertical-align:top;
    overflow:hidden
}
.media:hover{
    width:25%;
}

FIDDLE

Thanks in advance!!

P.S - I dont need this to be done with CSS (even that transition effect)


回答1:


Try this:

<script>
    $('.media').mouseenter(function(){
        $('img').hide();
        $('.media').width('25%');
    });
    $('.media').mouseleave(function(){
        setTimeout(function(){
            $('.media').width('6%');
            setTimeout(function(){$('img').show()},1000);
        },3000);
    });
</script>

Fiddle http://jsfiddle.net/aVDgk/2/




回答2:


You may take a look on CSS Animations.



来源:https://stackoverflow.com/questions/16396445/slide-input-on-hover-and-stay-for-few-seconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!