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

Stop the print dialog box from causing the page to refresh

I have implemented a print button for an invoice: </script> <!--Function for printing invoice--> <script> function printpage() { window.print() } </script> <button id="print" name="print" class="btn btn-info" onClick="pri ...

How to exclude the port number from the href in a Node.js EJS template?

I have the following code snippet. I am trying to list out the file names in a specific directory and add an href tag to them. The code seems to be working fine, however, it still includes the port number where my node.js app is running. How can I remove ...

What is the process for retrieving data on the server side using node.js that has been sent from the frontend via the post method

After diving into learning node.js with the express framework, I encountered a roadblock. I'm experimenting with a basic query search webapp and trying to send some data (a boolean named all) from front-end plain javascript via ajax to the server sid ...

Display an aspx page within a div container

I am using the following code to load an aspx page in a div tag. Unfortunately, it's not working as expected. Can someone please assist me in resolving this issue? <script type="text/javascript"> $(document).ready(function () { $(&a ...

problem arises when I attempt to use the code individually, as well as when I incorporate it into my existing

<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> <title>App Title</title> <!-- Framework's CSS Fil ...

How can I toggle a clicked switch in React MUI instead of all switches?

This is the current state in my parent component: const [feedbackType, setFeedbackType] = useState({ manual: true, auto: false, }); I am passing this state as a prop to the child component. In the child component, I have the following code: co ...

Error: User cannot be used as a constructor

When attempting to register a user using a Node.js app and MongoDB, I encountered the following error message: const utente = new Utente({ ||||| TypeError: Utente is not a constructor This is my model file, utente.js: const mongoose = require("mongoose") ...

jquery's each method is not functioning as intended and causing unexpected issues

I'm in the midst of developing a website, and one section requires users to input their details into a form. My goal is as follows: When a user clicks the submit button with any empty fields, I want a span element (initially set to display none in CS ...

Tips for simulating the $timeout service with sinon?

I am looking to write a unit test for a method within an Angular controller that uses the $timeout service. However, I have been advised not to use inject in this scenario. Therefore, I need to mock $timeout on my own. Can someone guide me on how I can a ...

Every time I try to upload image files to cloudinary, I encounter this frustrating error message

https://i.stack.imgur.com/kRYVZ.png The issue at hand revolves around node and the challenge of using the https module with new certificates, proving to be unsuccessful... The proposed solution is ambiguous, leaving me unsure how to proceed and resolve thi ...

Eliminate the alert message that appears when dynamically rendering a React styled component

When checking the browser console, I noticed a warning that reads as follows: react_devtools_backend.js:3973 The component styled.div with the id of "sc-dmRaPn" has been created dynamically. You may see this warning because you've called sty ...

Suggestions for updating the 'begin' and 'finish' variables transmitted through ajax on fullcalendar?

Shown below is the URL to request JSON data via Ajax: '/php/get-events.php?start=2015-05-31&end=2015-06-07&_=1433154089490'. This query will fetch JSON data from 2015-05-31 to 2015-06-07. However, I am looking to retrieve data over a ...

Issue: TypeError: Unable to access the 'getBoundingClientRect' property of an undefined value

Is there anyone who can lend me a hand? I encountered an issue: TypeError: Cannot read property 'getBoundingClientRect' of null https://i.stack.imgur.com/Jnfox.png Here is the code snippet I am trying to render: <div className="box&qu ...

Incapable of composing text using the MUI SearchBar

I'm having trouble with my Material UI search bar - it's not letting me type anything into it. How can I resolve this issue? Despite trying the suggested code snippets from other answers, I keep encountering errors when integrating them into my ...

How to append double zeros to a number in Material UI Data Grid

I'm currently working on a React.js application that utilizes the DataGrid component from the Material UI (MUI) library to display data. My challenge lies in formatting full numbers with trailing zeroes for better clarity. For example, displaying 625 ...

What is the best way to save data from a jQuery plugin to a database using ASP .NET MVC?

I have a jQuery plugin called "Slider" that displays the current price of an item. I would like to enhance it by allowing users to change prices using the jQuery slider and update them in the database. Here is the model: public class Item { public in ...

Vite deciding to generate its own node_modules directory within the workspace rather than depending on a monorepo

I have organized a monorepo for a fullstack webapp with the directory structure outlined below: . ├── client │ ├── index.html │ ├── package.json │ ├── src │ └── vite.config.ts ├── node_modules ├── p ...

Changes made to code within the node_modules directory do not appear in the browser

I encountered a bug in the vuejs-datepicker project on Github, prompting me to fork the repository. However, despite making changes to the forked project, these alterations are not reflected in my main project that relies on this dependency. Here's a ...

What is the best way to incorporate a button that can toggle the visibility of the sidebar on my post page?

Check out this post of mine I noticed a button on someone's page that could hide their sidebar and expand it again when clicked. How can I implement this feature? Is it a simple task? ...

React Timer App: The setInterval function is being reset after each render operation

I'm currently working on a straightforward timer application that will begin counting seconds when a button is clicked. To implement this, I am utilizing react hooks. import React, { useState } from 'react' function Timer() { const [sec ...