Utilize CSS to showcase the full-size version of a clicked thumbnail

I am working on a web page that features three thumbnails displayed on the side.

When one of these thumbnails is clicked, the full-size image should appear in the center of the page with accompanying text below it. Additionally, I have already implemented code to slightly increase the size of the thumbnails when hovered over. However, my main challenge lies in correctly displaying the full-size image.

This is the current code snippet:

<!DOCTYPE html>
<html>
    <head>
        <title>Gallery Page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style>
    img:hover
       {
        transform: scale(1.250,1.250);
                padding:5px;
       }
    #right
       {
       position:absolute;
       top:50px;
       right:100px;
       left:250px;
           bottom:200px;
           } 

    </style>
    <script>
    function changeSize(id)
    {
    var mainImage=document.getElementById("mainImage");
    var someImage=document.getElementById(id);
    mainImage.src=someImage.src;
    }
    </script>

    </head>   
    <body>    
        <div align="center"><img id="mainImage" style="max-width:auto; max-height:auto" align="middle" src="blank.jpg" 
alt="blank"/></div>
        <table>
            <tr>
                <td><span style="cursor:pointer"><img style="max-width:70px; max-height:70px" id="cluster" src="cluster1.png" 
alt="cluster" onClick="changeSize(id)"/></span></td>
            </tr>
            <tr>
                <td><span style="cursor:pointer"><img style="max-width:70px; max-height:70px" id="gas" 
src="gas1.png" alt="gas" onClick="changeSize(id)"/></span></td>
            </tr>
            <tr>
                <td><span style="cursor:pointer"><img style="max-width:70px; max-height:70px" 
id="launch" src="launch1.jpg" alt="launch" onClick="changeSize(id)"/></span></td>
            </tr>

        </table>
    </body>
</html>

If you have any suggestions or better ways to achieve this functionality, please feel free to share them.

Answer №1

It seems like you're unsure about how to proceed with your script. One way to ensure that you have references to the DOM elements is by wrapping your script in an onload handler. Here's an example:

var initialize = function() {
    var mainImage=document.getElementById("mainImage");
    var someImage=document.getElementById("someImage");
    mainImage.src=someImage.src;
}
var adjustSize = function() {

}

if (window.addEventListener) {
    window.addEventListener('load', initialize, false);
} else if (window.attachEvent) {
  window.attachEvent('onload', initialize);
}

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

Failure occurred when attempting to link and display on the page container

I have created a simple app using jQuery Mobile. At some point in the app, I include the following code: <a href="test_es.html" data-role="button">Start!</a> This code snippet loads a new HTML file that contains several jQuery Mobile page ...

Navigating through pages using Jquery's show and hide functionality

How come my item is not returning? I used the .show() method on the item. <div id="back">< back</div> <div class="item">item</div> <div class="content">My content</div> $(function(){ $('.item').on(&apo ...

Generating a fresh instance from a pre-existing object using JavaScript

Currently, I am facing a challenge from devchallenges.io known as the Shoppingify challenge. After carefully reviewing the prompt, I started working on creating a model that should have a specific format when a request is submitted. { "user": 1 ...

Warning in Google Script editor

Currently, I am working on creating some quick scripts to manipulate spreadsheets in my Google Drive. However, I am cautious about the script unintentionally running and making changes to data before I am ready or executing multiple times after completing ...

What is the proper way to define an element's style property in strict mode?

Assuming: const body = document.getElementsByTagName('body')[0]; const iframe = document.createElement('iframe'); iframe.src = protocol + settings.scriptUrl + a; iframe.height = 1; iframe.width = 1; iframe.scrolling = 'no'; ...

Populate the AngularJS scope with a dynamically generated array

My Angular Application is functioning properly with <script> var app = angular.module('MyApp', []); app.controller('myCtrl', function ($scope, $sce) { $scope.urls = [ { "url": $sce.t ...

Problems with the design in the Opera browser

My website logo is displaying incorrectly in Opera, despite working fine in Firefox and Chromium. I've been trying to troubleshoot this issue for the past few hours with no success. The ID of the logo element is 'Logo'. You can view the sit ...

What is the best way to arrange a bootstrap .container?

I've been struggling to position a content DIV on a bootstrap carousel, but so far I haven't been successful in figuring it out. Below is a screenshot of the current output from my code, which is not what I am aiming for. What I'm trying t ...

Press Button to create cookie and store it in Drupal 7

I am currently working on my Drupal 7 local website, which features an article and a popup on the homepage leading to that article. Within the article, there is a button that I want to serve as a way for users to dismiss the initial popup permanently. My i ...

Instead of displaying an error page, an Axios post request is returning data

I'm currently dealing with a post request that looks like this: axios({ method: "post", url: "/sessions/add", data: { session: { name: session.session.name, date: sessionDateInput.value, ...

What is the correct method for iterating through this array of objects and eliminating those with either null or empty item.text values?

Currently, I am working with the following Array: const contactInfo = computed(() => { return [ { id: 'address', icon: 'detail/clubLocation', text: `${props.data.contactInfo.address}` ...

Guidelines for choosing a dropdown menu option using jQuery in a WordPress photo gallery

First off, take a look at the screenshot to understand what I'm trying to accomplish: Within WordPress, after clicking on "New Post" and then on the "Add Media" button, a pop-up image gallery appears with an image filtering drop-down menu. My goal is ...

Maintaining the integrity of Jquery Tab even after refreshing the page is essential

I recently started using Jquery and encountered an issue with tab implementation. Whenever I refresh the page, it automatically directs me back to the initial tab setting. $(function() { var indicator = $('#indicator'), i ...

Changing date format in Mui DatePicker

I need some assistance with customizing the mui DatePicker. Specifically, I would like to set the date format to display as Day, DD Month. For example: Monday, 10 September Below is the code snippet I am currently working with: <LocalizationProvider d ...

Instructions on how to retrieve a JSON file from an external source

I'm experiencing difficulties in downloading a json file from an external URL using nodejs. The issue arises when the downloaded file (dumpFile.json) is created empty. var file = fs.createWriteStream("download/dumpFile.json"); let URL = 'http:// ...

Two separate ajax functions executed sequentially both yield identical results

I am encountering a strange issue with 2 different ajax functions being called consecutively. Each function fetches a different value and populates different text boxes, but they both return the value of the first function called. Here is the code snippet ...

Unable to access HTTP response headers during Ext.ajax.request callback in ExtJS 4.2.1

When making an Ext.ajax.request, I am attempting to read the headers of the response that is coming. Here is the code snippet: Ext.Ajax.request({ url: 'http://localhost:3000/v0.1/login' , method: 'POST', scope:this, jsonDat ...

Can you explain the functionality of dismissing a Bootstrap alert?

In this example, we can see how Bootstrap handles dismissible alerts: <div class="alert alert-warning alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidde ...

The transition effect is not functioning properly in CSS and React.js

.cartBtn { appearance: none; outline: none; border: none; cursor: pointer; text-align: center; background-color: transparent; color: inherit; } .cartBtn:hover { color: black; } .cart { display: none; opacity: 0; transition: all 4s ea ...

Convert a fresh Date() to the format: E MMM dd yyyy HH:mm:ss 'GMT'z

The date and time on my website is currently being shown using "new date()". Currently, it appears as: Thu May 17 2018 18:52:26 GMT+0530 (India Standard Time) I would like it to be displayed as: Thu May 17 2018 18:43:42 GMTIST ...