正确过渡的CSS问题

时间:2014-05-02 17:37:10

标签: jquery css css-transitions

我找到了一段用于创建扩展搜索栏的代码。它依赖于CSS和javascript来运行。演示found here,搜索栏向右打开。我已经向右漂浮,希望它在左边打开。我现在只需要另一双眼睛,因为我无法找到我的问题。问题是它打开很好,但它没有过渡。然而,它会在关闭时过渡。

这是:http://jsfiddle.net/rEsQ2/1/

HTML

<div class="fix" id="search-bar">
    <div class="search_main fix">
        <form action="http://logans.linkhousedev.net/" method="get" class="searchform" role="search" id="search">
            <div id="label" class="">
                <label id="search-label" for="search-terms">search</label>
            </div>
            <div id="input" class="">
                <input type="search" title="Search for:" name="s" value="" placeholder="Search …" class="search-field" id="search-terms" />
            </div>
        </form>
    </div>
</div>

CSS

#search-bar {
    top: 0;
    height: 60px;
    position: absolute;
    right: 0;
}
#search {
    position: absolute;
    top: 0;
    right: 0;
    width: 60px;
    height: 60px;
}
#label {
    width: 60px;
    height: 60px;
    position: relative;
    z-index: 20;
}
#label label {
    display: block;
    width: 60px;
    height: 60px;
    background: url("http://callmenick.com/lab-demos/3-expanding-search-bar/img/search.png") 0 0;
    font-size: 0;
    color: rgba(0, 0, 0, 0);
    text-indent: -9999px;
    cursor: pointer;
}
#label label:hover {
    background: url("http://callmenick.com/lab-demos/3-expanding-search-bar/img/search.png") -60px 0
}
#label.active label {
    background: url("http://callmenick.com/lab-demos/3-expanding-search-bar/img/search.png") -60px 0
}
#input {
    height: 60px;
    overflow: hidden;
    position: absolute;
    right: 60px;
    top: 0;
    width: 450px;
    z-index: 5;
}
#input input {
    display: block;
    position: absolute;
    top: 0;
    right: -450px;
    width: 430px;
    height: 100%;
    margin: 0;
    padding: 0 10px;
    border: none;
    background-color: #23688b;
    color: #fff;
    font-size: 18px;
    backface-visibility: none;
    border-radius: 0;
    transition: right 0.3s ease 0s;
}
#input input:focus {
    outline: none
}
#input.focus {
    z-index: 20
}
#input.focus input {
    right: 0;
    transition: right 0.3s ease 0.2s;
}

JS

// get vars
var searchEl = $("#input");
var labelEl = $("#label");
// register clicks and toggle classes
labelEl.on("click", function () {
    if (searchEl.hasClass("focus")) {
        searchEl.removeClass("focus");
        labelEl.removeClass("active");
    } else {
        searchEl.addClass("focus");
        labelEl.addClass("active");
    }
});
// register clicks outisde search box, and toggle correct classes
$(document).on("click", function (e) {
    var el = $(e.target);
    if (el.attr("id") != "search-terms" && el.attr("id") != "search-label") {
        if (searchEl.hasClass("focus")) {
            searchEl.removeClass("focus");
            labelEl.removeClass("active");
        }
    }
});

任何想法都会非常感激。

干杯, 杰伊

1 个答案:

答案 0 :(得分:3)

较大的搜索栏中有错误的ID。这就是你看起来的样子:

<input type="search" title="Search for:" name="s" value="" placeholder="Search …" class="search-field" id="search-terms" />

更改&#34;搜索字词&#34;只是&#34;搜索&#34;:

<input type="search" title="Search for:" name="s" value="" placeholder="Search …" class="search-field" id="search" />

当我在jsfiddle上这样做时,它完美无缺。