gpt4 book ai didi

javascript - 将输入 Action 添加到动画搜索表单

转载 作者:太空宇宙 更新时间:2023-11-04 07:53:32 24 4
gpt4 key购买 nike

我正在使用基于 CSS 的动画搜索表单:

演示:https://codepen.io/CBeghin/pen/HeuiF

要打开搜索栏,我必须单击放大镜图标。如果我再次点击放大镜图标,该条再次消失。目前我必须按“Enter”键来搜索我的关键字。

我不想删除搜索栏,而是在第二次单击放大镜图标时使用输入操作来搜索我的关键字。

我尝试使用 javascript,但我没有在正确的位置执行操作:

$('input').click(function() {
var clicks = $(this).data('clicks');
if (clicks) {
alert('open search bar');
} else {
alert('enter search bar');
}
$(this).data("clicks", !clicks);
});

有人有想法,如何实现?

最佳答案

您可以通过 javascript 处理焦点样式,并在用户第一次单击文本输入时将放大镜移动到文本输入前面来实现此目的

$("input[type='text']").focus(function() {
if (!$(this).hasClass("focus")) {
$(this).addClass("focus");
}
$("input[type='submit']").attr('style', 'z-index: 4');
});
@import url(https://fonts.googleapis.com/css?family=Lato:100,300,400,700);
@import url(https://raw.github.com/FortAwesome/Font-Awesome/master/docs/assets/css/font-awesome.min.css);

body {
background: #DDD;
font-size: 15px;
}
#wrap {
margin: 50px 100px;
display: inline-block;
position: relative;
height: 60px;
float: right;
padding: 0;
position: relative;
}

input[type="text"] {
height: 60px;
font-size: 55px;
display: inline-block;
font-family: "Lato";
font-weight: 100;
border: none;
outline: none;
color: #555;
padding: 3px;
padding-right: 60px;
width: 0px;
position: absolute;
top: 0;
right: 0;
background: none;
z-index: 3;
transition: width .4s cubic-bezier(0.000, 0.795, 0.000, 1.000);
cursor: pointer;
}

input[type="text"].focus:hover {
border-bottom: 1px solid #BBB;
}

input[type="text"].focus {
width: 700px;
z-index: 1;
border-bottom: 1px solid #BBB;
cursor: text;
}
input[type="submit"] {
height: 67px;
width: 63px;
display: inline-block;
color:red;
float: right;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRFU1NT9fX1lJSUXl5e1dXVfn5+c3Nz6urqv7+/tLS0iYmJqampn5+fysrK39/faWlp////Vi4ZywAAABF0Uk5T/////////////////////wAlrZliAAABLklEQVR42rSWWRbDIAhFHeOUtN3/ags1zaA4cHrKZ8JFRHwoXkwTvwGP1Qo0bYObAPwiLmbNAHBWFBZlD9j0JxflDViIObNHG/Do8PRHTJk0TezAhv7qloK0JJEBh+F8+U/hopIELOWfiZUCDOZD1RADOQKA75oq4cvVkcT+OdHnqqpQCITWAjnWVgGQUWz12lJuGwGoaWgBKzRVBcCypgUkOAoWgBX/L0CmxN40u6xwcIJ1cOzWYDffp3axsQOyvdkXiH9FKRFwPRHYZUaXMgPLeiW7QhbDRciyLXJaKheCuLbiVoqx1DVRyH26yb0hsuoOFEPsoz+BVE0MRlZNjGZcRQyHYkmMp2hBTIzdkzCTc/pLqOnBrk7/yZdAOq/q5NPBH1f7x7fGP4C3AAMAQrhzX9zhcGsAAAAASUVORK5CYII=) center center no-repeat;
text-indent: -10000px;
border: none;
position: absolute;
top: 0;
right: 0;
z-index: 2;
cursor: pointer;
opacity: 0.4;
cursor: pointer;
transition: opacity .4s ease;
}

input[type="submit"]:hover {
opacity: 0.8;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrap">
<form action="" autocomplete="on">
<input id="search" name="search" type="text" placeholder="What're we looking for ?"><input id="search_submit" value="Rechercher" type="submit">
</form>
</div>

关于javascript - 将输入 Action 添加到动画搜索表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47536898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com