简体   繁体   English

单击图标时搜索打开,但单击关闭图标时不会关闭

[英]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.

相关问题 单击关闭图标时暂停或停止视频 - Pause or stop the video when close icon is clicked 为什么单击图标时不会启动模式? - Why won't the modal launch when icon is clicked? 单击外部时,多个模态不会关闭 - Multiple modals won't close when clicked outside of it 单击外部关闭按钮 div 时,div 数组不会关闭(Javascript) - div array won't close when external close button div is clicked (Javascript) 单击“ x”关闭图标时,使箭头向后切换(0度) - Have arrow toggle back (0deg) when “x” close icon is clicked 单击链接以外的任何内容时,需要菜单关闭(包括菜单图标) - Need menu to close when anything other than a link is clicked (including the menu icon) 单击两个输入的相同标签名称的关闭图标时,取消选中选中的输入 - Uncheck the checked input when clicked on close icon for same label name for both input 我希望我的 Google 地图中的信息窗口在单击其他图标时自动关闭 - I want the infowindow in my Google map to close automatically when a different icon is clicked 当为 introjs-react 步骤单击关闭按钮(十字图标)时,是否有可调用 function 的道具? - Is there a prop available to call a function when close button (cross icon) is clicked for introjs-react step? MDL - 单击时将 + 图标更改为 -? - MDL - Change + icon to - when clicked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM