隐藏不在div内的元素

时间:2015-11-06 08:13:02

标签: javascript jquery html css

我有一个website(点击红色拳头)。它有搜索功能。如果单击搜索,它将无法占据100%的窗口高度,您仍然可以滚动不在' morphsearch'内的内容。我哪里错了?



//morphSearch code
(function() {
  var morphSearch = document.getElementById('morphsearch'),
    input = morphSearch.querySelector('input.morphsearch-input'),
    ctrlClose = morphSearch.querySelector('span.morphsearch-close'),
    ctrlClose2 = morphSearch.querySelector('span.morphsearch-close2'),
    isOpen = isAnimating = false,
    // show/hide search area
    toggleSearch = function(evt) {
      // return if open and the input gets focused
      if (evt.type.toLowerCase() === 'focus' && isOpen) return false;

      var offsets = morphsearch.getBoundingClientRect();
      if (isOpen) {
        classie.remove(morphSearch, 'open');

        // trick to hide input text once the search overlay closes 
        // todo: hardcoded times, should be done after transition ends
        if (input.value !== '') {
          setTimeout(function() {
            classie.add(morphSearch, 'hideInput');
            setTimeout(function() {
              classie.remove(morphSearch, 'hideInput');
              input.value = '';
            }, 300);
          }, 500);
        }

        input.blur();
      } else {
        classie.add(morphSearch, 'open');
      }
      isOpen = !isOpen;
    };

  // events
  input.addEventListener('focus', toggleSearch);
  ctrlClose.addEventListener('click', toggleSearch);
  ctrlClose2.addEventListener('click', toggleSearch);
  // esc key closes search overlay
  // keyboard navigation events
  document.addEventListener('keydown', function(ev) {
    var keyCode = ev.keyCode || ev.which;
    if (keyCode === 27 && isOpen) {
      toggleSearch(ev);
    }
  });


  /***** for demo purposes only: don't allow to submit the form *****/
  morphSearch.querySelector('button[type="submit"]').addEventListener('click', function(ev) {
    ev.preventDefault();
  });
})();

.morphsearch {
  width: 200px;
  min-height: 40px;
  background: #f1f1f1;
  position: absolute;
  z-index: 10000;
  top: 50px;
  right: 50px;
  -webkit-transform-origin: 100% 0;
  transform-origin: 100% 0;
  -webkit-transition-property: min-height, width, top, right;
  transition-property: min-height, width, top, right;
  -webkit-transition-duration: 0.5s;
  transition-duration: 0.5s;
  -webkit-transition-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
  transition-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
}
.morphsearch.open {
  width: 100%;
  min-height: 100%;
  top: 0px;
  right: 0px;
}

<div id="morphsearch" class="morphsearch">
  <form id="searchForm" class="morphsearch-form" method="post">
    <input id="s" class="morphsearch-input" type="search" placeholder="Search Dundaah..." />
    <input class="morphsearch-submit" type="submit" value="Submit" id="submitButton" />
  </form>
  <div id="resultsDiv" class="morphsearch-content2"></div>
  <span class="morphsearch-close"></span>
  <span class="morphsearch-close2"></span>	
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

请按照以下方式更改CSS,然后重试:

.morphsearch.open {
    width: 100%;
    min-height: 100%;
    top: 0px;
    right: 0px;
    position: fixed;
    bottom: 0;
    overflow-y: scroll;
}

答案 1 :(得分:0)

在打开搜索时,您应该为<html><body>新成员提供一个新课程,例如: hideoverflow并删除CSS中的溢出:

.hideoverflow {
     overflow: hidden;
}

再次关闭搜索表时,不要忘记切换课程。