skip to Main Content

I am using the default debut theme and i am trying to open the fancybox popup on the click of image. I have uploaded the css and js using the assets folder and i have included the css and js into the theme.liquid before head tag close. Also added the script in my custom.js script.

I have given the piece of my code below. Any one can help me on the same please?

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>My page</title>

    <!-- CSS -->
    <link rel="stylesheet" type="text/css" href="jquery.fancybox.min.css">
    <!-- JS -->
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="jquery.fancybox.min.js"></script>
    <script src="custom-scripts.js"></script>
</head>
<body>

    <a href="image.jpg">
      <img src="thumbnail.jpg" alt="" />
    </a>

    

</body>
</html>

2

Answers


  1. According to Fancybox documentation to enable a gallery you need to update a tag parameters according to documentation

    <!-- 1. Add latest jQuery and fancybox files -->
    
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/[email protected]/dist/jquery.fancybox.min.css" />
    <script src="https://cdn.jsdelivr.net/gh/fancyapps/[email protected]/dist/jquery.fancybox.min.js"></script>
    
    
    
    <!-- 2. Create links -->
    
    <a data-fancybox="gallery" href="big_1.jpg"><img src="small_1.jpg"></a>
    <a data-fancybox="gallery" href="big_2.jpg"><img src="small_2.jpg"></a>
    
    
    <!-- 3. Have fun! -->
    

    This attribute play role to activate fancy box gallery data-fancybox="gallery"

    Login or Signup to reply.
  2. You just missed the single thing to add in the a tag parameters that we need to follow as per the Fancybox 3 Guide line.
    
     
    
           <!DOCTYPE html>
            <html>
            <head>
                <meta charset="utf-8">
                <title>My page</title>
            
                <!-- CSS -->
                <link rel="stylesheet" type="text/css" href="jquery.fancybox.min.css">
                <!-- JS -->
                <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
                <script src="jquery.fancybox.min.js"></script>
                <script src="custom-scripts.js"></script>
            </head>
            <body>
            
                <a href="image.jpg">
                  <img src="thumbnail.jpg" alt="" />
                </a>
            
                
            
            </body>
            </html>
        
        /* Here is the thing that you missed  */
         <a href="image.jpg" data-fancybox>
                  <img src="thumbnail.jpg" alt="" />
         </a>
         
            /* And for the gallery to open multiple images */
            <a href="image_1.jpg" data-fancybox="gallery" 
            data-caption="Caption#1">
            <img src="thumbnail_1.jpg" alt="" />
        </a>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search