[英]Search opens when icon is clicked but won't close when close icon is clicked
I have an error on my JavaScript using WordPress where I can open the search but can't close it.我的 JavaScript 使用 WordPress 时出现错误,我可以在其中打开搜索但无法关闭它。 I have a functions.php where there is a
wp_enqueue_script
for a live-search script, Search.js, Index.js, header.php and footer.php with code necessary with the problem:我有一个 functions.php,其中有一个用于实时搜索脚本的
wp_enqueue_script
、Search.js、Index.js、header.php 和 footer.php,其中包含问题所需的代码:
functions.php code:函数.php代码:
wp_enqueue_script('live-search-javascript',
get_theme_file_uri('/js/modules/Search.js'), array('jquery'), '1.0', true);
header.php icon code: header.php图标代码:
<span class="search-trigger js-search-trigger"><i class="fa fa-search" aria-hidden="true"></i></span>
footer.php code:页脚.php代码:
<div class="search-overlay">
<div class="search-overlay__top"></div>
<div class="container"></div>
<i class="fa fa-search search-overlay__icon" aria-hidden="true"></i>
<input type="text" class="search-term" placeholder="Search DC" id="search-term">
<i class="fa fa-window-close search-overlay__close" aria-hidden="true"></i>
</div>
Index.js code: Index.js 代码:
import "../css/style.scss";
import $ from 'jquery';
// Our modules / classes
import MobileMenu from "./modules/MobileMenu";
import HeroSlider from "./modules/HeroSlider";
import GoogleMap from "./modules/GoogleMap";
import Search from "./modules/Search";
// Instantiate a new object using our modules/classes
const mobileMenu = new MobileMenu();
const heroSlider = new HeroSlider();
const googleMap = new GoogleMap();
const mySearch = new Search();
Search.js code:搜索.js代码:
import $ from 'jquery';
class Search {
constructor() {
this.openButton = $(".js-search-trigger");
this.closeButton = $(".search-overlay__close");
this.searchOverlay = $(".search-overlay");
this.events();
}
events() {
this.openButton.on("click", this.openOverlay.bind(this));
this.closeButton.on("click", this.closeOverlay.bind(this));
}
openOverlay() {
this.searchOverlay.addClass("search-overlay--active");
}
closeOverlay() {
this.searchOverlay.removeClass("search-overlay--active");
}
}
export default Search;
The search opens, it just won't close.搜索打开,只是不会关闭。 How do I solve this issue?
我该如何解决这个问题?
I figured out that it does close only I have to scroll down and not at the top of the page.我发现它确实关闭了,只是我必须向下滚动而不是在页面顶部。 The file where it can be fixed is called
search-overlay.scss
in the css file.可以修复的文件在css文件中叫做
search-overlay.scss
overlay.scss。 The search bar needs to have a place where it can be executed to do searches, not at the very top of the page where the header is.搜索栏需要有一个可以执行搜索的地方,而不是在 header 所在的页面顶部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.