What is causing the unexpected impact of the "Product Quick View" JavaScript plugin on divs that are not being activated by user interaction?

As a newcomer to web design, I have implemented the "Product-Quick-View" plugin from CodyHouse on my website.
Upon clicking the DEMO button and inspecting the code, you will find the following:

<body>
    <header>
        <h1>Product Quick View</h1>
    </header>

    <ul class="cd-items cd-container">
        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview"/>
            <a href="#0" class="cd-trigger">Quick View</a>
        </li>

        <!-- More list items here -->

    </ul>

    <!-- Quick view details -->

</body>

In order to differentiate between products, I made the following modifications:

<div id="Num1">
    <ul class="cd-items cd-container">
        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview"/>
            <a href="#0" class="cd-trigger">Quick View</a>
        </li>
    </ul>

    <!-- Additional product information -->

</div>

However, there seems to be an issue where the content of the last division overwrites the content of the first division when clicking on the cd-trigger. This problem might stem from the animateQuickView function in main.js.

The relevant part of the JavaScript code is as follows:


// JavaScript code here

If you need access to the complete project files (including CSS, JavaScript, etc), they can be found on this GitHub link.

Your assistance in resolving this issue would be greatly appreciated.

Answer №1

Create a unique div with the class cd-quick-view for each item and assign different ids to them.

<div id="first-item" class="cd-quick-view">
        <div class="cd-slider-wrapper">
            <ul class="cd-slider">
                <li class="selected"><img src="img/item-1.jpg" alt="Product 1"></li>
                <li><img src="img/item-2.jpg" alt="Product 2"></li>
                <li><img src="img/item-3.jpg" alt="Product 3"></li>
            </ul> <!-- cd-slider -->

            <ul class="cd-slider-navigation">
                <li><a class="cd-next" href="#0">Prev</a></li>
                <li><a class="cd-prev" href="#0">Next</a></li>
            </ul> <!-- cd-slider-navigation -->
        </div> <!-- cd-slider-wrapper -->

        <div class="cd-item-info">
            <h2>First Item</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officia, omnis illo iste ratione. Numquam eveniet quo, ullam itaque expedita impedit. Eveniet, asperiores amet iste repellendus similique reiciendis, maxime laborum praesentium.</p>

            <ul class="cd-item-action">
                <li><button class="add-to-cart">Add to cart</button></li>                   
                <li><a href="#0">Learn more</a></li>    
            </ul> <!-- cd-item-action -->
        </div> <!-- cd-item-info -->
        <a href="#0" class="cd-close">Close</a>
    </div> <!-- cd-quick-view -->
    <div id="second-item" class="cd-quick-view">
        <div class="cd-slider-wrapper">
            <ul class="cd-slider">
                <li class="selected"><img src="img/item-1.jpg" alt="Product 1"></li>
                <li><img src="img/item-2.jpg" alt="Product 2"></li>
                <li><img src="img/item-3.jpg" alt="Product 3"></li>
            </ul> <!-- cd-slider -->

            <ul class="cd-slider-navigation">
                <li><a class="cd-next" href="#0">Prev</a></li>
                <li><a class="cd-prev" href="#0">Next</a></li>
            </ul> <!-- cd-slider-navigation -->
        </div> <!-- cd-slider-wrapper -->

        <div class="cd-item-info">
            <h2>Second Item</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officia, omnis illo iste ratione. Numquam eveniet quo, ullam itaque expedita impedit. Eveniet, asperiores amet iste repellendus similique reiciendis, maxime laborum praesentium.</p>

            <ul class="cd-item-action">
                <li><button class="add-to-cart">Add to cart</button></li>                   
                <li><a href="#0">Learn more</a></li>    
            </ul> <!-- cd-item-action -->
        </div> <!-- cd-item-info -->
        <a href="#0" class="cd-close">Close</a>
    </div> <!-- cd-quick-view -->

Assign those ids as hrefs to cd-trigger a tags: href="#first-item"

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#first-item" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#second-item" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

Retrieve the href of the a tags when clicked then make a quick change in animateQuickView function by adding the href property and passing it through the function.

var href = $(this).attr('href');

animateQuickView(selectedImage, sliderFinalWidth, maxQuickWidth, 'open', href);

Subsequently, replace '.cd-quick-view' with href for the open animation part:

$(href).css({
    "top": topSelected,
    "left": leftSelected,
    "width": widthSelected,
}).velocity({
    //animate the quick view: animate its width and center it in the viewport
    //during this animation, only the slider image is visible
    'top': finalTop+ 'px',
    'left': finalLeft+'px',
    'width': finalWidth+'px',
}, 1000, [ 400, 20 ], function(){
    //animate the quick view: animate its width to the final value
    $(href).addClass('animate-width').velocity({
        'left': quickViewLeft+'px',
        'width': quickViewWidth+'px',
    }, 300, 'ease' ,function(){
        //show quick view content
        $(href).addClass('add-content');
    });
}).addClass('is-visible');

To access the complete modified files, check out the link below: https://drive.google.com/file/d/1OC9uj8haP0t-EBGuJe1dwR4_5zjLq7T_/view?usp=sharing

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

Controlling the behavior of React components in response to updates

I'm currently learning ReactJs and utilizing the ExtReact framework for my project. I have successfully implemented a grid with pagination, which is functioning well. I customized the spinner that appears during data loading and it works as expected ...

jQuery prioritizes enforcing style over using a CSS file

I am facing an issue with a nested div functioning similar to a drop-down menu. The problem arises when I click on the #two div as I want it to disappear. To handle this, I utilized jQuery and tried using both .hide() and .slideUp(). However, upon implem ...

Elements inside the Bootstrap 3 navbar are actually external

I am having trouble with the collapsible navbar, specifically the alignment of the right side. Here is the code snippet related to it: <div class="collapse navbar-collapse navHeaderCollapse"> <ul class="nav navbar-nav navbar-right"> ...

How to make a static div adjust its size in the presence of a neighboring div

I am looking to create a feature where the user can click a button to reveal a new div to the right of an existing one. Check out this Fiddle for reference: http://jsfiddle.net/AV2mZ/. While the functionality works fine when both divs are visible, resizin ...

Display a thumbnail image using a v-for loop

Looking for help with implementing a photo preview in my code using BootstrapVue. The Vue devtools show that the form-file contains the image, but my 'watch' isn't functioning properly. Any assistance would be greatly appreciated! Here is ...

PHP is sending incomplete email messages

After implementing a PHP script to send an email upon unsubscribing, I encountered an issue where only part of the email was being sent. Here is a JSFiddle example that represents how the complete email should look, although it may not appear neat due to b ...

Scoped Styles rarely stand a chance against more dominant styles

I'm facing a scope issue while learning Vue. Question: I am trying to make sure that the styles in profile.vue do not override the ones in sidebar.vue. I want the sidebar to have a red background and the profile section to be blue. Shouldn't usi ...

How can Node.js and Express be used to conceal Javascript code on the backend?

I'm a beginner when it comes to Node and Express. I have a query regarding how to securely hide Javascript code on the backend. Currently, I am working with Node.js and Express. My goal is to prevent users from easily accessing the code through browse ...

Comparison of button text alignment: stacking vs inline placement

I currently have a button on my webpage labeled "Learn More." Unfortunately, the text on the button is not lining up as it should. Instead of flowing in a line, the text seems to be stacking on top of each other. The HTML code for the button is included ...

Getting Started with Parsing JSON Objects in ReactJS

In my ReactJS project, I am trying to parse through a JSON list using the following model: public class ModelEmployee { public List<Employeelist> Employees { get; set; } public int count { get; set; } public int Pagenumber { get; set; } ...

What's the best way to ensure that my image remains perfectly centered at the point where the background colors of my

html <body> <header> <div class="indexHeaderWall" id="headerLeftWall"> </div> <img id="profilePic" src="icons/myPicture.jpg" alt="Picture of Daniel Campo ...

Despite setting the date format in the Html Helper, the MVC still presents a validation error

When creating a razor view form to display the date field, I am using the following code: @Html.TextBoxFor(m => m.LectureDate, "{0:dd/MM/yyyy}") The desired date format is 21/04/2017, which is set by JQuery DatePicker. However, after setting the date ...

Creating a two-dimensional canvas within a div element using the console

I have some code that currently generates an image in the console when I hit F12. However, I would like to display this image inside a more user-friendly area such as a div on the webpage. I attempted to create a <div class = "mylog"> to place the i ...

Tips on avoiding the collapse of the right div when positioned under a left float in a full page layout

Trying out a full page layout for the first time, with a left div serving as a block style nav. #admin_nav { width: 230px; height: 100%; background-color: #f9f9f9; border-right: 1px solid #ddd; float: left; } The content is on the rig ...

When a specific option is selected in a `select` element with the `multiple` attribute, activate the change event

Is it possible to trigger a change event on individual options within a standard select element using jQuery or another method? I want the change event to be triggered on the option elements themselves rather than on the select element, as multiple options ...

Utilize jQuery to load a separate external sites div into an iframe

I have a department website that caters to a specific audience. I am interested in including a set of related links from an external site at the conclusion of each article. The links will be organized within a div, like so: <div id="linktoc"><a h ...

"Add a touch of magic to your webpage with text effects that appear

I am looking to create a glowing text effect, and I stumbled upon this resource. http://jsfiddle.net/karim79/G3J6V/1/ However, the client prefers the text effect to appear after the page loads, rather than on hover. Unfortunately, I do not have experien ...

Prevent mobile users from entering text with Material UI Autocomplete on keyboard

Currently, I am utilizing the Material UI Autocomplete component for multi-select functionality. Although it functions perfectly on desktop, I want to prevent keyboard input on mobile devices and only allow touch selection. Essentially, I do not want the v ...

Confirmation dialog with user-defined button text

When the confirm prompt box is used, it typically displays "ok" and "cancel" buttons. I am looking to customize the label text for the buttons to read as Agree and Not Agree instead. If you have any suggestions on how to achieve this modification, please ...

Load Ajax file smoothly without any flickering

I am working on a webpage that automatically loads data. The script I found on a tutorial website has a flaw - the text keeps blinking every few seconds. Is there a way to prevent this blinking effect? I am new to Ajax and finding it confusing. Below is t ...