Anchor links open a Javascript function

Asked

Viewed 74 times

0

I’m developing a simple HTML page with links to anchors scattered around the document, but after including an image gallery in jQuery, the links started to open the gallery instead of scrolling to the anchor. Can someone help me?

Here is the call of the method:

   <script type="text/javascript">
        $(document).ready(function(){
            $('#gallery').gallerie();
        });
    </script>

Example of a link and an anchor used:

    <li><a href="#empresa">EMPRESA</a></li> 

    <div class="row" id="empresa">
  • You can include an example in the link and anchor question?

  • Added TO THE DESCRIPTION

  • If you withdraw $('#gallery').gallerie(); the anchors work normal?

  • Yes... but it serves to call the function that opens the images in a gallery. However, the linsk of the Anchors are calling this function of the images instead.

1 answer

1

Looking at the plugin documentation, by default, it will grab all tags <a> as anchor of the gallery. What you should do is put a class in each tag <a> gallery, for example, class="gallerie-image":

<div id="gallery">
   <a class="gallerie-image" href="imagem1.jpg"><img src="miniatura1.jpg"/></a>
   <a class="gallerie-image" href="imagem2.jpg"><img src="miniatura2.jpg"/></a>
</div>

And start the plugin by changing the option elem pointing to the class:

$('#gallery').gallerie({
   elem: 'a.gallerie-image'
});

So the plugin will only fetch the tags <a> gallery, not altering the normal behavior of other tags <a> page.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.