Enhance the visual appeal of your website by incorporating a dazzling sparkle effect using

I have implemented the magnificPopup script on my gallery page.

Check out magnificPopup on Github

In addition, I have added a sparkle effect using this script:

Try out the Sparkle Effect

Currently, the sparkle effect only appears when hovering over each gallery image. However, I also want to add the same sparkly effect to the thumbnail images.

View Thumbnail Image

This is the code I am using for the normal image hover mode:

<div class="cards-row">
    <div class="col-md-2 col-md-offset-1">
      <a href="/images/Cards/alien-back.jpg" data-effect="mfp-3d-unfold">
        <div class="sparkley">
          <img src="/images/Cards/alien-front.jpg" alt="" />
        </div>
      </a>
    </div>

To apply the sparkley effect to the back image, I used a jQuery function to wrap it in a "sparkley" class.

$( "figure" ).addClass( "sparkley" );

Unfortunately, this approach did not work as expected. While adding another class with a hover effect worked, it seems that the sparkley effect relies on a mouseover jQuery function rather than just the hover event. I am currently facing some challenges in getting this to work.

Answer №1

If you wanted to achieve something similar, you could try the following approach:

$('#gallery').magnificPopup({
  […],
  callbacks: {
    open: function() {
      this.contentContainer.find('figure').shine();
    },
    resize: function() {
      this.contentContainer.find('figure').trigger('resize.shine');
    }
});

This code will trigger the shine effect only after the gallery popup is opened (when the open callback is invoked) and will adjust it according to any size changes.

This solution assumes that you are using the default markup provided by Magnific Popup for the popup. If you have a custom layout for the content with the shine effect, make sure to use an element other than <figure>.

You may also consider wrapping the <img> in a specific container and target that instead of the entire <figure> to limit the shine effect to just the image and not the entire popup container.

/**
 * Overlay for images (gallery)
 *
 * @param {string} theme
 */
var openGallery = function(theme) {
};

// Galleries
$('ul.magnific-gallery').magnificPopup({
  delegate: '> li > a',
  type: 'image',
  gallery: {
    enabled: true
  },
  callbacks: {
    open: function() {
      var $shineEffect = this.contentContainer.find('figure');
      $shineEffect.shine();
      
      // Uncomment the code below to immediately start the effect
      $shineEffect.off("mouseover.shine")
        .off("mouseout.shine")
        .off("focus.shine")
        .off("blur.shine")
        .trigger("start.shine");
    },
    resize: function() {
      this.contentContainer.find('figure').trigger('resize.shine');
    }
  },
});
.magnific-gallery img {
  max-width: 200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>
<script src="https://rawgit.com/simeydotme/jQuery-canvas-sparkles/master/dist/jquery-canvas-sparkles.min.js"></script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css" rel="stylesheet" type="text/css">

<ul class="magnific-gallery">
  <li>
    <a href="http://i1232.photobucket.com/albums/ff372/Marcin_Gil/magnific%20example/flower1.jpg" title="Etiam ullamcorper.">
      <img src="http://i1232.photobucket.com/albums/ff372/Marcin_Gil/magnific%20example/flower1.jpg" alt="" />
    </a>
  </li>
  <li>
    <a href="http://i1232.photobucket.com/albums/ff372/Marcin_Gil/magnific%20example/flower2.jpg" title="Cum sociis natoque penatibus." data-description="Estibulum id, eleifend justo vel bibendum sapien massa ac turpis faucibus orci luctus non, consectetuer lobortis quis, varius in, purus. Integer ultrices posuere cubilia.">
      <img src="http://i1232.photobucket.com/albums/ff372/Marcin_Gil/magnific%20example/flower2.jpg" alt="" />
    </a>
  </li>
   <li>
    <a href="http://i1232.photobucket.com/albums/ff372/Marcin_Gil/magnific%20example/flower3.jpg" title="Maecenas malesuada.">
      <img src="http://i1232.photobucket.com/albums/ff372/Marcin_Gil/magnific%20example/flower3.jpg" alt="" />
    </a>
  </li>
    <li>
    <a href="http://i1232.photobucket.com/albums/ff372/Marcin_Gil/magnific%20example/flower4.jpg" title="Vestibulum dapibus, mauris nec malesuada fames ac turpis velit, rhoncus eu, luctus et interdum adipiscing wisi." data-description="Vestibulum dapibus, mauris nec malesuada fames ac turpis velit, rhoncus eu, luctus et interdum adipiscing wisi.">
      <img src="http://i1232.photobucket.com/albums/ff372/Marcin_Gil/magnific%20example/flower4.jpg" alt="" />
    </a>
  </li>
</ul>

In the updated snippet, I have modified the code to start the shine effect immediately by removing hover events and manually triggering "start.shine" within the open callback:

this.contentContainer.find('figure')
  .off("mouseover.shine")
  .off("mouseout.shine")
  .off("focus.shine")
  .off("blur.shine")
  .trigger("start.shine");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Eradicate white space in a JavaScript code

Calling all JS programmers! Here's a challenge for you, check out this demo: https://codepen.io/gschier/pen/jkivt I'm looking to tweak 'The pen is simple.' to be 'The pen issimple.' by removing the extra space after 'is& ...

Unable to execute PHP code within a PHP file loaded through AJAX

I'm currently in the process of developing a webshop using WooCommerce. I have successfully implemented two switch buttons that allow users to toggle between 'List view' and 'Grid view'. Specifically, for the list view button, I am ...

Rejuvenating your HTML content with AJAX over time

My HTML page contains links to charts that refresh every time the page is reloaded. A friend mentioned that AJAX can automatically refresh the chart at specified intervals without reloading the entire HTML page. I would appreciate any help with the HTML ...

Incorporating library files (css/js) into your app built on the angular-fullstack framework

After using a Yo Angular-Fullstack generator (https://github.com/DaftMonk/generator-angular-fullstack) to start an app, I attempted to install Toastr from bower with the command: bower install angular-toastr Now, I need to add the toastr css and js files ...

Utilizing HTML5 audio elements with jQuery enhances the auditory experience

As I delve into creating a simple media section for a website, I have encountered some challenges that I would like to address. Let me explain the issue I am facing. I currently have a 'play list' consisting of 'links' - represented by ...

What is the best way to modify the appearance of the button?

I'm attempting to change the appearance of buttons at the top of a webpage to be square and blue. I have jQuery code for this purpose, but it doesn't seem to be functioning correctly. Here is the snippet of code I am using: $(document).ready(fu ...

Spacing between a pair of jQuery datepicker panels

https://i.sstatic.net/Xnbh1.png Is there any way to add spacing between two tables inside the jquery date picker with a common header? I've tried various solutions like adding padding to the parent div, but haven't been able to fix it. Can anyon ...

Sending form input values to JavaScript

Struggling to design a webpage featuring one text box and a button that, when clicked, sends the value to Javascript for further processing? After spending significant time troubleshooting, I'm unsure of what's causing the issue. Below are both t ...

How wide should the website layout be?

What is the perfect size for a standard portal website? I've seen many sites with widths ranging from 960px to 1000px. ...

Adjust the size of flex items to match the size of their container

I'm attempting to design a two-column layout using a flex parent with a height of 100vh. The first column consists of a div containing a heading and a paragraph, while the second column contains a div with an image. I want the flex parent's heigh ...

Unexpected Django Get request error causing confusion

I am currently working on a basic Django app that enables users to add items to a database. The goal is to have the list of items automatically update whenever a new item is added via the form, displaying both the newly added product and all existing produ ...

Attempting to reveal or conceal the change_list filter within Django admin

Is there a way to hide the filter box (the grey box on the right) on the django admin change_list.html page? I attempted to create a basic JavaScript function and insert it into the extra head section like this: {% extends "admin/change_list.html" %} {% ...

What is the best URL structure to use?

I am seeking feedback on the best approach for structuring a website. My website allows companies to register and have their own page at company.site.com. I am trying to decide where the administration should take place for each company. Here are the two o ...

Skrollr immediate pop-up notification

Can anyone help me figure out how to make text appear suddenly and then disappear using skrollr? I've been able to get it to fade in and out, but I want it to just show up without any transition. Here's the code I have so far: <div id="style" ...

Design a big-sized button using Bootstrap framework

Is there a way to design a big, responsive button using Bootstrap? Similar to the example image linked below https://i.sstatic.net/xEBwc.png ...

What is the sequence of Javascript Execution for the event of window.location.href?

After browsing through this discussion on asynchronous JavaScript location.href call and watching a video explaining the event loop, I found no clear explanation regarding the behavior of href within window.location: The script order in the source code is ...

What might be causing res.download to retrieve a zip file that is empty?

Using expressjs for my app development, I have created a service to download files on the client side using res.download(filepath, filename). The following is the code snippet of my service: router.route('/downloadFile').get(function(req,res){ ...

What is the best method to make a hyperlink within an IFrame open in a new window?

Let me share the code I've been working on: <!DOCTYPE html> <html> <head> <base target="_blank"> </head> <body> <div style="border: 2px solid #D5CC5A; overflow: hidden; margin: 15px auto; max-width: 800px; ...

Create a one-of-a-kind SVG design with a customized blur effect in

Recently, I've been experimenting with SVG effects and animations and stumbled upon a fantastic example of how to apply a blur effect to an SVG path. However, I'm struggling to figure out how to set a different color instead of the default black ...

Attempting to store an array in a database while avoiding duplicate entries

English is not my first language, so I apologize in advance if my explanation is unclear. I am currently working on developing a game where each player is assigned a specific role. However, I've encountered an issue with repetitive numbers being inser ...