Struggling to implement hover state functionality with Magnific Popup

I'm currently facing an issue with my thumbnails where I can either have a hover state or the Magnific popup working, but not both at the same time.

The overlay is triggered by the class "overlay" within the div.

Below is the HTML for the image that pops up (without the functioning overlay):

<ul id="Grid">
    <li class="mix category_1 mix_all">
        <div class="overlay"> <a href="http://i.imgur.com/i5SwjyO.jpg"><img src="http://i.imgur.com/J4PaouI.jpg" alt="#"></a>

        </div>
    </li>
</ul>

And here is the HTML for the image that has a working overlay (but the image popup does not work):

<ul id="Grid">
    <li class="mix category_2 mix_all"> <a href="http://i.imgur.com/i5SwjyO.jpg"><img src="http://i.imgur.com/J4PaouI.jpg" alt="#"></a>

        <div class="overlay"></div>
    </li>
    <ul>

Furthermore, here is the relevant CSS code for the hover state:

.mix_all:hover .overlay {
    background: url(http://i.imgur.com/DZcK9ge.png) no-repeat center !important;
    background-color: #de6573 !important;
    opacity: 0.9;
}

For a visual representation and to see both examples in action, you can check out this jsfiddle link: http://jsfiddle.net/yashar/wz4BT/10/

Answer №1

After making adjustments to the HTML structure, I incorporated two distinct JS events: one for magnificPopup targeting the .mix selector, and another click event applied to the overlays enabling them to directly access the anchor tag and activate the popup event.

You can find the code at this link: http://jsfiddle.net/GQZVR/

Here is the modified HTML:

<ul id="Grid">
    <li class="mix category_1 mix_all">
        <div class="overlay"></div>
        <a href="http://i.imgur.com/i5SwjyO.jpg"><img src="http://i.imgur.com/J4PaouI.jpg" alt="#"></a>
    </li>
    <li class="mix category_2 mix_all"> 
        <div class="overlay"></div>
        <a href="http://i.imgur.com/i5SwjyO.jpg"><img src="http://i.imgur.com/J4PaouI.jpg" alt="#"></a>    
    </li>
</ul>

The updated CSS (including cursor: pointer) is as follows:

.mix_all .overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

For the JS part, see below:

$('.overlay')
    .click(function(){
        $(this).next('a').trigger('click');
    });
$('.mix')
    .magnificPopup({
        delegate: 'a', // child items selector, by clicking on it popup will open
        gallery: {
            enabled: false //disabling the gallery for now
        },
        type: 'image' //type of lightbox
    });

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

Unusual display of fonts on Chrome

Recently, I encountered a strange issue with font rendering on Chrome/Opera compared to Firefox. The problem can be seen in the preview below - pay attention to the pink text. It appears blurry initially but sharpens once text input is focused. This same i ...

What could be causing my background image to resize while scrolling on mobile devices?

While browsing on mobile, I noticed that my div with a background-image gets zoomed in when scrolling down the page. I did some research and realized that others have experienced this issue as well, but there doesn't seem to be a definitive solution. ...

Why is my text becoming centered on desktop view?

One curious issue I encountered while working with Bootstrap 4's accordion on this page is that the text of the last item in the accordion is mysteriously centered. Despite not using text-center or having any CSS properties like text-align: center spe ...

Applying Bootstrap Style to an Inline Select Element: A Step-by-Step Guide

Currently working on a page layout using Thymeleaf and Bootstrap 5. I have divided the page into two parts, with this section behaving as desired: <main role="main" class="pb-3"> <br> <p>Post office ex ...

How To Align a Main Header and Secondary Header

Is there a way to align a header and sub-header using text-align: justify;? It doesn't seem to work for me, possibly because the parent is set to inline-block? Check out my jsFiddle example: http://jsfiddle.net/9bnqab6n/1/ Here's the HTML code: ...

The validation error is displayed within the textbox instead of beside the label

Hey there! I encountered a rather peculiar issue while working on my jQuery mobile webapp. I decided to implement jqueryvalidation for form validation, which is pretty neat, except for one hiccup - the error messages are showing up inside the input field ...

"the content does not occupy the entire space of the parent

My TableRow expands across the width of the screen, and within it is a ListView with a layout_width set to match_parent. However, the ListView does not expand properly. This issue arose when I added two buttons in the next TableRow. Even after setting the ...

Learn how to separate two SCSS files and compile them into individual CSS files

Currently, I have two SCSS files that need to be compiled into separate CSS files. For one of the SCSS files, my script looks like this: "watch:sass": "node-sass assets/stylesheets/custom.scss assets/stylesheets/custom.css -w", "compile:sass": "node-sass ...

Is it possible to modify the class within TypeScript code while utilizing the CSS library for styling?

In my custom style sheet coustume-webkit.css, I have the following code snippet: .tabella .pagination > li:last-child > a:before, .tabella .pagination > li:last-child > span:before { padding-right: 5px; content: "avanti"; ...

React cursor none does not have the ability to adjust

I am currently working with React and Next.js. I am trying to hide the pointer using cursor: none. Even though I used cursor: none, the pointer is still visible. const Home: FunctionComponent = () => { const [mouseX, setMouseX] = useState(0); ...

Is there a way to adjust the height of a turnjs page?

I am currently utilizing the Turn.js flip library and I need to adjust the height of the turnjs page. The current setup calculates the height of the page based on the client's height, but now I want to change it to a specific value like 700px. How can ...

What is the most effective method for locating and capturing a specific element (such as an input box) in Python Selenium using either Xpath or CSS selector

I am currently using selenium to scrape a website, primarily relying on xpath or CSS selectors to extract elements. However, I have noticed that these selectors are dynamic, which contradicts what I have read online about CSS selectors being stable. As a b ...

Open space on responsive website causing layout issue

I need help troubleshooting some code for a responsive website. When I shrink the screen and an item goes "under" another one instead of next to it, it creates a large gap that I want to avoid. Ideally, I would like the items to shrink up to a certain mini ...

Guidelines for creating a rectangular selection tool in Angular 2+ to choose multiple items

Hello, I am interested in learning how to draw a rectangle to select multiple items using Angular 2+. I currently have a working Plunker example where I would like to implement the ability to select items by drawing a rectangle similar to this jsfiddle I ...

Tips for designing a form action

I am a beginner and struggling with understanding the CSS for the code below. Can someone help me out? <div id="page-container"> <?php include_once("home_start.php"); ?> <h1>Login</h1> <for ...

Is it a good idea to relocate the pagination to the top of the DataGrid in MUI

Can someone suggest a solution for moving the default pagination of XGrid above the table? Or do I need to develop my own custom pagination instead of using the built-in feature with XGrid? ...

Ways to interact with a button that toggles between states

I am working with a button that has both an enabled and disabled state. Enabled State: <button type="button" class="btt-download-csv site-toolbar-menu-button icon-download no-icon-margins ng-isolate-scope" title="Download CSV" rc-download-csv="" curren ...

SQL Query: Change text color based on the result number retrieved

After executing my SQL SELECT statement, I want to display every record in a div using a While statement. I would like the divs to alternate in color, for example: Result 1 = white div Result 2 = grey div Result 3 = white div Result 4 = grey div. I am un ...

Display or conceal a division underneath a dropdown menu based on selections retrieved from a SQL Server database

Presented here is my JavaScript code. function appendItemforPurchaseOrder() { debugger var rowNumber = parseInt($(".itemmapContainer").attr("data-rownumber")); rowNumber = isNaN(rowNumber) ? 1 : rowNumber + 1; var addNewItemDetailHtml = ...

What could be the reason for the percentage not functioning properly in margin-top?

Attempting to apply a top margin in percentage (%) to the form element but encountering issues with the property not being accepted. The goal is to create a margin from the top for the form. Below is the code snippet: http://plnkr.co/edit/byQLFlLh4a2qaIEZ ...