如何制作旋转搜索栏

时间:2016-02-07 14:44:44

标签: html searchbar

我一直在搜索如何制作这个旋转搜索栏https://dribbble.com/shots/344730--Loooong-the-search-bar。我也搜索了一个旋转对象的代码,但我也没有找到。我还尝试使用另一个单词而不是旋转搜索栏,例如"如何旋转照片"但我没有发现任何与我的问题相符的内容。我总是在我问之前搜索,但我找不到任何与我的问题相符的内容。我知道如何扩展搜索栏但我不知道如何在点击它时旋转搜索图标。

1 个答案:

答案 0 :(得分:0)

您需要的所有代码都可以在JSFiddle中找到。

HTML:

<h3>A <a href="http://goo.gl/qCtsD" target="_blank">dribbble shot</a> recreated for the web by <a href="http://dribbble.com/ryanmclaughlin">ryan mack</a>.<p>Try typing <i>etwas</i> and press enter.</p></h3>

<form>
    <input id="search" type="search" name="search" />
    <p></p>
</form>

CSS:

    form {
    display: inline-block;
    margin: 0 100px;
    position: relative;
}

#search {
    border: 4px solid #999;
    cursor: pointer;
    height: 10px;
    padding: 8px;
    position: relative;
    width: 10px;

    -moz-border-radius: 15px;
    -webkit-border-radius: 15px;
    border-radius: 15px;

    -moz-appearance: none;
    -webkit-appearance: none;
}

#search:hover {   
    border-color: #199ed9;
}

#search:focus {   
    border-color: #199ed9;
    outline: none;
    width: 180px;

    -moz-transition: all .2s ease-in-out;  
    -webkit-transition: all .2s ease-in-out;
}

#search.searching {
    margin-left: 80px;
    width: 10px;

    -moz-transition: all .2s ease-in-out;  
    -webkit-transition: all .2s ease-in-out;
}

#search + p {
    background: #999;
    content: '';
    cursor: pointer;
    display: block;
    height: 10px;
    position: absolute;
    right: 10px;
    top: -8px;
    width: 4px;

    -moz-border-radius: 1px;
    -webkit-border-radius: 1px;
    border-radius: 1px;

    -moz-transform: rotate(135deg);
    -webkit-transform: rotate(135deg);
    -moz-transform-origin: center 20px;
    -webkit-transform-origin: center 20px;
}

#search + p:hover,
#search:hover + p,
#search:focus + p {   
    background: #199ed9;
}

#search.searching + p {
    -moz-animation: rotateHandle .6s linear 6;
    -webkit-animation: rotateHandle .6s linear 6;
}

@-webkit-keyframes rotateHandle {
    from { -webkit-transform: rotate(135deg); }
    to { -webkit-transform: rotate(-225deg); }
}

@-moz-keyframes rotateHandle {
    from { -moz-transform: rotate(135deg); }
    to { -moz-transform: rotate(-225deg); }
}

h3 {
    color: #888;
    font-size: 20px;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    margin: 100px 100px 50px;

    -webkit-font-smoothing: antialiased;
}

h3 p {
    font-size: 13px;
}

a {
    color: #199ed9;
    font-weight: bold;
    text-decoration: none
}

a:hover {
    text-decoration: underline;   
}

Javascript:

var form = $('form'),
    search = $('#search');

form.submit(function(e) {
    e.preventDefault();

    search.addClass('searching').val('');

    setTimeout(function() {
        search.removeClass('searching');
    }, 3600);
});

/* what's with input padding? :/ */
if ($.browser.mozilla) {
    search.css('padding', '3px');
}

那个做过它的人:http://dribbble.com/ryanmclaughlin