When clicking, the images are displayed within a faded-in div

I'm trying to create a layout where all the images within the #ImageContainer are displayed in a fixed Div. Everything seems to be working well except for the fact that when I click on an image, it disappears from the #ImageContainer and shows up in the #BigImage. This behavior is not intended in my jQuery code, and I'm having trouble identifying the root cause.

HTML:

<body>
    <div id="ImageCotainer">
        <div id="headerLogo">
            <div id="Logo">

            </div>
        </div>
        <img src="images/hotel/1.jpg" alt="">
        <img src="images/hotel/2.jpg" alt="">
        <img src="images/hotel/3.jpg" alt="">
        <img src="images/hotel/4.jpg" alt="">
        <img src="images/hotel/5.jpg" alt="">
        <img src="images/hotel/6.jpg" alt="">
        <img src="images/hotel/7.jpg" alt="">
    </div>

    <div id="BigImage">
        <img src="images/wedding/4.jpg" alt=""> 
    </div>
</body>

CSS:

#BigImage{
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 700px;
    width: 1000px;
    margin: auto;
    background-color: rgba(0,0,0,0.95);
    z-index: 50;    
    display: none;
}
#BigImage img{
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    height: 500px;
    width: 800px;
    margin: auto;
}

Javascript:

$(window).load(function() { 
    $("#Logo").click(function () {
        window.location.href = "hotelM.html"
    });

    $("img").click(function () {
        //var img = $(this);
        $("#BigImage").html(this);
        $("#BigImage").fadeIn(1000);

    });

    $("#BigImage").click(function () {
        $("#BigImage").fadeOut(1000);
    });
});

Demo

Answer №1

$("#BigImage").html($(this).clone());

Check out the demonstration here

Typically, altering image sources is the preferred method instead of moving entire elements.

Answer №2

When the image transitions from #ImageContainer to #BigImage

This is the exact behavior we are observing, where 'this' refers to the actual dom reference. By inserting it into the HTML of another element, it effectively moves it.

To achieve the desired outcome, you need to make the following adjustment:

$("#BigImage").html($(this).clone());

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

Using v-model in a child component and setting v-model within a child component in a Vue project

How can I simplify this code? Ensure that the button also updates the localValue of the child component. Vue.component('my-input', { template: ` <div> <b>My Input:</b> <br> localValue: {{ localValue } ...

How can you create a table cell that is only partially editable while still allowing inline JavaScript functions to work?

Just a few days back, I posted a question similar to this one and received an incredibly helpful response. However, my attempt at creating a table calculator has hit a snag. Each table row in a particular column already has an assigned `id` to transform t ...

Adjusting the CSS for a specific element while hovering over another

I'm currently facing the challenge of creating a fixed position navbar with white links that should change to black when hovering over another element with a white background. Here is the CSS for the navbar links: nav ul li a {color:#ffffff;} CSS f ...

The disabled input field remains inactive even after reloading the current page

When an 'input button tag' with a value is disabled and clicked, upon reloading the current page in the browser, the button remains disabled without changing to enable (disabled = 'false'), only the value within the button is removed. ...

The fixed width setting for the alpha table column is not being recognized

Despite my efforts, the responsive bootstrap 4 table is not adhering to my fixed column width styles. <table class="table table-responsive table-sm table-striped table-hover"> <thead> <tr> <th> <input typ ...

Understanding how events propagate in three.js

I am currently working on a scene that consists of multiple objects. To manipulate the selected object, I am using an orthographic camera controller. Specifically, I want to rotate the object with the mouse by pressing shiftKey + 1 (rotation around its own ...

Lengthen the space between each item on the list to enhance readability

Is there a way to adjust the line height between li tags? I attempted using height:100%, but it seems ineffective. Are my methods correct? Can anyone provide guidance? The following is the code snippet in question: <html xmlns="http://www.w3.org/1999 ...

Refresh Vue module when router is pushed

Hello everyone! I'm new to Vue.js and have encountered an issue with my api module. The code looks like this: axios.create({ baseURL: URL, headers: { Authorization: 'Bearer ${localStorage.getItem('token')}' } }) When on ...

There appears to be some lingering content in the JQuery Mobile slide-out dialog box

My jQuery mobile slide out dialog box is experiencing an issue. The first time the slide out occurs, a comment box appears where users can enter comments and then submit them, followed by a "THANK YOU" message. However, when the user closes the dialog box ...

Replacing the tbody element in React with centered text using inline styles ---If you want

I am working with an empty array in React that I translate into state. When the array is empty, I want to insert a text that says "no match events yet..." into a react-bootstrap Table's tbody. In the current setup, I am struggling to center the text ...

Script written in PHP to retrieve text from a website, then translate and save it onto a local storage

Is there a way to save text from a website to a local file? The script should perform the following actions: Visit this website (fake site) http://website/webtv/secure?url=http://streamserver.net/channel/channel.m3u8**&TIMESTAMP** where TIMESTAMP ...

Function call fails when parameters are passed

I've been grappling with this conundrum for a few weeks now, on and off. Perhaps someone else will spot the glaringly obvious thing that I seem to be overlooking. At the present moment, my primary goal is to simply confirm that the function is operat ...

What is the best method to extract both text and href attributes from a bs4.element.Tag in Python?

I need assistance with parsing data from the following URL: After extracting text and href using bs4.element.Tag, I am facing an issue where the outputs are concatenated. Below is the code snippet: from urllib.request import urlopen from bs4 import Beaut ...

Changing the background-color of a Bootstrap 4 checkbox also alters its size

Is there a way to prevent the check icon on my checkbox from resizing when I change the background color? Here's a snippet of my code for reference: .custom-checkbox .custom-control-indicator { border-radius: 50%; height: 25px; width: 25px; ...

Card image floating to the right using Bootstrap

I have a set of three horizontal cards, not in a card deck as it's not responsive, and I want to align images in the bottom right corner of each. Bootstrap 4 comes with a class for card-img-left which works perfectly. I've attempted using float-r ...

Calculate the total count using XSLT within the loop

I'm currently iterating through my for loop <xsl:for-each select="Alerts/AlertItem"> and <xsl:value-of select="position()" /> provides me with the current position, representing 1, 2, and 3 if there are three items. While inside this ...

The utilization of jQuery's ajax feature is resulting in an unexpected full page refresh when using FireFox browser

Currently, I am facing a bit of a problem with an ajax call using jQuery. It seems to be working perfectly fine in Internet Explorer 7, however, FireFox 3 always initiates a full page refresh whenever the call is made. This ajax call is set to POST to an A ...

Get a PNG file in the form of binary/octet-stream for download

https://i.sstatic.net/VFMbl.pngsteps to recreate the issue: I have a Blob object that I am saving as form data through a service. The response I receive has a content-type of application/octet-stream, as shown in the attached image. What result is expect ...

Updating an array element in Mongoose, the MongoDB ORM

I am currently in the process of making changes to a MongoDb collection that contains an array of documents called items. To achieve this, I am utilizing the express and mongoose frameworks. This is how my schema is structured: const mongoose = require(" ...

I am having trouble retrieving the properties of "2d" objects using tiles[i-1], unlike standard objects in JavaScript

I've been working on constructing a random map generator by utilizing a grid composed of tiles within a canvas. In my process, I'm investigating the properties of each tile tiles[i] before handling tiles[i-1]. While this procedure seems to functi ...