<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#searchbox {
background-color: rgba(0, 0, 0, .35);
}
#searchbox:hover {
background-color: rgba(15, 15, 15, .6);
}
.search {
position: absolute;
top: 200px;
left: 50%;
transform: translateX(-50%);
max-width: 80%;
width: 230px;
height: 43px;
border-radius: 30px;
color: #fff;
background-color: rgba(255, 255, 255, .25);
box-shadow: rgb(0 0 0 / 20%) 0 0 10px;
-webkit-backdrop-filter: blur(10px);
backdrop-filter: blur(10px);
overflow: hidden;
transition: color .25s, background-color .25s, box-shadow .25s, left .25s, opacity .25s, top .25s, width .25s;
}
input:-moz-placeholder,
textarea:-moz-placeholder {
color: black;
}
input:-ms-input-placeholder,
textarea:-ms-input-placeholder {
color: black;
}
input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
color: black;
}
.search:hover {
box-shadow: rgb(0 0 0 / 30%) 0 0 10px;
width: 530px;
}
input {
outline: 0;
border: none;
width: 100%;
height: 100%;
color: inherit;
background-color: transparent;
font-size: 14px;
text-align: center;
}
</style>
</head>
<body>
<div class="search" id="searchbox">
<input id="search" autocomplete="off" type="text" class="search-input" placeholder="Search">
</div>
</body>
<script>
var search = document.querySelector('.search');
var input = document.querySelector("input");
var click = 0; // 0未点击 1点击
input.onclick = function () {
input.setAttribute('placeholder', ''); // 清空提示词
search.style.width = '530px'; // 搜索框被点击放大效果
click = 1;
}
input.onblur = function () {
input.setAttribute('placeholder', 'Search'); // 还原提示词
search.style.width = '230px';
input.value = ''; // 失去焦点清空搜索内容
click = 0;
}
search.onmouseover = function () {
search.style.width = '530px'; // 鼠标经过放大效果
}
search.onmouseout = function () {
if (click == 0) {
search.style.width = '230px'; // 未点击
} else {
search.style.width = '530px'; // 被点击
}
}
</script>
</html>
原文地址:https://blog.csdn.net/qq_63167347/article/details/128293620
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_34702.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。