[JavaScript库通过单击导航菜单触发

问题描述 投票:1回答:1

我在同一网页上将FixedNav (一页页面的固定导航菜单)与PhotoSwipe (JavaScript库)结合在一起。

之后,单击导航菜单中的链接,它将向下滚动到页面的相关部分。它确实可以滚动,但是由于某些原因,它还会打开PhotoSwipe画廊。

单击菜单链接应只滚动到相关区域,而不触发PhotoSwipe画廊。

我已经使用了FixedNav和PhotoSwipe的所有默认设置,并将它们放在一起以说明问题:

https://jsfiddle.net/5pw1rem9/

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Adtile Fixed Nav</title>
    <meta name="author" content="Adtile">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" href="css/styles.css">

    <title>CodePen - PhotoSwipe Demo</title>
    <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>
    <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.0/photoswipe.css'>
    <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.0/default-skin/default-skin.css'>
    <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Bitter:400,700,400italic'>
    <link rel="stylesheet" href="./style.css">


    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
      <link rel="stylesheet" href="css/ie.css">
    <![endif]-->
    <script src="js/responsive-nav.js"></script>
  </head>
  <body>

    <header>
      <a href="#home" class="logo" data-scroll>Fixed Nav</a>
      <nav class="nav-collapse">
        <ul>
          <li class="menu-item active"><a href="#home" data-scroll>Home</a></li>
          <li class="menu-item"><a href="#about" data-scroll>About</a></li>
          <li class="menu-item"><a href="#projects" data-scroll>Projects</a></li>
          <li class="menu-item"><a href="#blog" data-scroll>Blog</a></li>
          <li class="menu-item"><a href="http://www.google.com" target="_blank">Google</a></li>
        </ul>
      </nav>
    </header>

    <section id="home">
      <h1>Fixed Nav</h1>

<!-- partial:index.partial.html -->
<div class="container">
  <div class="row">
    <div class="col-sm-8 col-sm-offset-2">

      <h1 class="text-center">
          <small><em>..and a PhotoSwipe Demo</em></small>
        </h1>

      <!-- Galley wrapper that contains all items -->
      <div id="gallery" class="gallery" itemscope itemtype="http://schema.org/ImageGallery">

        <!-- Use figure for a more semantic html -->
        <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
          <!-- Link to the big image, not mandatory, but usefull when there is no JS -->
          <a href="https://unsplash.it/1200/900/?image=702" data-caption="Sea side, south shore<br><em class='text-muted'>© Dominik Schröder</em>" data-width="1200" data-height="900" itemprop="contentUrl">
            <!-- Thumbnail -->
            <img src="https://unsplash.it/400/300/?image=702" itemprop="thumbnail" alt="Image description">
          </a>
        </figure>

javascript photoswipe
1个回答
0
投票

在您的函数中,您有一个'a'的点击事件,其中a并非仅是画廊链接;单击功能也会影响您的菜单链接。这就是导致您的问题的原因。

© www.soinside.com 2019 - 2024. All rights reserved.