链接点击

时间:2017-03-24 05:46:42

标签: javascript css

首先,此问题仅适用于网站的移动版本,因此您只需查看菜单即可将浏览器缩小到小于1000像素的宽度。

在这个移动版面上,我有一个按钮,可以显示带有4个链接的叠加层。有一个" X"关闭叠加层,但我希望它在用户点击链接时关闭。到目前为止,我还没有能够使它发挥作用。以下是我使用的代码:

https://codepen.io/dftg/pen/oZyBpq

这是我试图改编以实现此功能的JavaScript:

$(document).ready(function(){
  // Add smooth scrolling to all links
  $("a").on('click', function(event) {

    // Make sure this.hash has a value before overriding default behavior
    if (this.hash !== "") {
      // Prevent default anchor click behavior
      event.preventDefault();

      // Store hash
      var hash = this.hash;

      // Using jQuery's animate() method to add smooth page scroll
      // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
      $('html, body').animate({
        scrollTop: $(hash).offset().top
      }, 800, function(){

        // Add hash (#) to URL when done scrolling (default click behavior)
        window.location.hash = hash;
      });
    } // End if
  });
});

$('#hider').click(function() {
    $('menu').addClass('hidemenu');
});

0 个答案:

没有答案