제 검색 양식이 처음에는 작동하지 않는다는 것이 확실합니다. 실제 검색을 수행하려면 다시 검색해야합니다. 코드에 문제가 있습니까?내 검색 양식이 처음 검색을하지 않는 이유는 무엇입니까?
HTML
<form id='sform' action="/admin/search.php" method="get">
<input id="search" placeholder="Enter your group name..." type="search" name="s" value="" />
<p></p>
<input type="submit" style="display:none;" />
</form>
CSS
/*search bar*/
#sform {
display:inline-block;
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: -22px;
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);
}
}
/*end of search bar*/
JS
$(function(){
//expand search bar
var okToSubmit = false;
$("#sform").submit(function (e) {
if (!okToSubmit) {
e.preventDefault();
$("#search").addClass('searching').val('');
var url = $(this).attr('action');
setTimeout(function() {
$.ajax({
type: 'POST',
url: url,
data: $(this).serialize(),
timeout: 8000,
success: function (r) {
$("#search").removeClass('searching');
}
});
okToSubmit = true;
}, 8000);
}
});
});
당신이 준 코드는 기본적으로 okToSubmit == FALSE ''이 있으므로 물론, 제출하지 않습니다. –
당신의 수수께끼 : http://jsfiddle.net/bdf8V/ – diEcho
왜 setTimeout을 사용하고 있습니까 ?? –