Tips for seamlessly integrating an overlay into a different image

My current system is set up to overlay the image when you check the checkboxes. However, I'm facing an issue with positioning the image inside the computer screen so it's not right at the edge. Can anyone provide assistance with this?

<html><head>
    <style>
        .overlay {
            display: none;
            position: absolute;

        }
        .right {
    position: absolute;
    right: 0px;
    width: 300px;
    border:3px solid #8AC007;
    padding: 10px;
}
        #map {
            position: relative;
            right: -780px;
            width: 452px;
            height: 344px;
            background: url(BLANK-COMPUTER-SCREEN.png);

        }
        #station_A { top: 5px; left: 85px }
        #station_B { top: 150px; left: 180px }
        .hover { color: green }
    </style>
<div id="map" >
        <span id="station_A" class="overlay"><img style="background:url(/BLANK-COMPUTER-SCREEN.PNG)" src="/tn_WhiskersPrinceworkup.png" /></span>
        <span id="station_B" class="overlay">Highlight image here.</span>

    </div>

    <p>
        <h2>Choose a Shirt</h2>
        <form>
            <input type="checkbox" name="image" value="station_A">Station Alfa<br>
            <input type="checkbox" name="image" value="station_B">Station Beta
            <input type="checkbox" name="image" value="bandanna" id="checkbox1">Bandanna
        </form>
    </p>

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  <script>
  $(document).ready(function () {
    $("input[type='checkbox']").change(function () {
        var state = $(this).val();
        $("#" + state).toggleClass("overlay");
    });
    $('#checkbox1').change(function () {
        if (this.checked) $('#map').fadeIn('slow');
        else $('#map').fadeOut('slow');

    });
});
    </script>

Check out the Fiddle link for more details.

Answer №1

To ensure proper functionality, it is important to assign the position:absolute property to elements #station_A and #station_B, rather than on .overlay. This is necessary because when using jQuery toggle with .overlay, the properties may be lost.

Here's a sample code snippet:

$(document).ready(function() {
   $("input[type='checkbox']").change(function() {
     var state = $(this).val();
     $("#" + state).toggleClass("overlay");
   });
   $('#checkbox1').change(function() {
     if (this.checked) $('#map').fadeIn('slow');
     else $('#map').fadeOut('slow');

   });
 });
.overlay {
  display: none;
}
.right {
  position: absolute;
  right: 0px;
  width: 300px;
  border: 3px solid #8AC007;
  padding: 10px;
}
#map {
  position: relative;
  /*right: -780px; removed for demo purposes */
  width: 452px;
  height: 344px; 
  background: url(//preview.jesybyqcev4e7b9xn83mzparyiafw29nwvpl11qsrsmunmi.box.codeanywhere.com/BLANK-COMPUTER-SCREEN.png) no-repeat;
}
#station_A {
  top: 8%; /* adjust as needed */
  left: 5%; /* adjust as needed */
  position: absolute;
}
#station_B {
  top: 45%; /* adjust as needed */
  left: 15%; /* adjust as needed */
  position: absolute
}
.hover {
  color: green
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div id="map">
  <span id="station_A" class="overlay"><img style="background:url(//preview.jesybyqcev4e7b9xn83mzparyiafw29nwvpl11qsrsmunmi.box.codeanywhere.com/BLANK-COMPUTER-SCREEN.png)" src="//lorempixel.com/270/240" /></span>
  <span id="station_B" class="overlay">Highlight image here.</span>
</div>
<p>
  <h2>Choose a Shirt</h2>

  <form>
    <input type="checkbox" name="image" value="station_A">Station Alfa
    <br>
    <input type="checkbox" name="image" value="station_B">Station Beta
    <input type="checkbox" name="image" value="bandanna" id="checkbox1" />Bandanna
  </form>
</p>

Answer №2

After some troubleshooting, it was determined that the issue stemmed from a z-index problem. By adjusting the CSS to bring the image to the front, the button now functions properly.

 #VneckTshirtImage 
{ 
     left: 138px; 
     top: 457px; 
     position: absolute; 
     width: 118px;
     height: 174px;
     z-index:28;
} 

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

working with Selenium in the Chrome web browser

Within a file named e2e.js, the following code was written: const webdriver = require('selenium-webdriver'); const driver = new webdriver.Builder().forBrowser('chrome').build(); driver.get('https://www.google.co.il/'); I h ...

The matMul function encountered an error due to a mismatch in the inner shapes of the Tensors. The shapes provided were 684,1 and 2,1, and the transposeA and transposeB parameters were both set

I am completely new to the world of AI and tensorflow.js. Currently, I am following a Machine Learning course by Stephen Grider. I was expecting an output after running the code below, but instead, I encountered an error. Can someone please assist me? Her ...

Positioning multiple images in CSS

I am facing an issue with my background images where one of them is invisible and cannot be displayed. Additionally, the padding-top for the li a element seems to not be working properly. HTML: <ul class="menu"> <li class="item-101 current a ...

Using jQuery to check if the input time is empty

Why is this code not functioning properly? I have filled the input but it still triggers an alert saying 'empty'. <label for="">New ETA:</label> <input type="time" class="neweta"> <input ty ...

What is the best way to include Google Calendar in a div container while ensuring it is responsive?

I'm currently working on the layout of a website that features a slideshow of images at the top, followed by an embedded Google Calendar. I've encountered an issue with the responsiveness of the Google Calendar within its designated div container ...

How do I assign a background image to a rectangle using JointJs?

What is the best way to customize the background image of a rectangle in my JointJs project? ...

Verifying the Absence of Events in the Chosen Month Display of the FullCalendar jQuery Plugin

Currently utilizing full calendar, which is being shown in month view with toggle buttons for navigating between months. Now, I am looking to have a message appear that reads "No events scheduled for the month." if there are no event objects present for t ...

Having trouble displaying the accurate model value in the alert

I have the following piece of code: $(document).ready(function () { var edit= @Model.Edit.ToString().ToLower(); if( edit !=true ) { $("#editWriteup").hide(); } var date= @Model.EndDate; alert(date); ...

"Dynamic value changes in bootstrap multiselect dropdowns triggered by selection in another multiselect dropdown

I am trying to enhance the functionality of my multiselect dropdown in Bootstrap by updating the values based on another multiselect selection. Currently, the code works well with one selection, but as soon as I include the class="selectpicker", ...

Button Fails to Respond on Second Click

I have a button that triggers a JavaScript function. This function, in turn, initiates two sequential AJAX calls. Upon completion of the first call, it performs some additional tasks before proceeding to the second AJAX call. The button functions correctl ...

Struggling with resolving the error message "EEXIST: file already exists, mkdir 'C:UsersOKRDesktopMeetUp' after the apk generation failed in React Native? Learn how to troubleshoot this

Currently, I am in the process of testing my React Native apk app file. These are the steps I followed before generating the apk: react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.a ...

Tips for transferring a value from a view to a controller using AngularJS

I've created a controller that dynamically generates tables based on data retrieved from the backend using $http.get. I'm wondering how I can pass a value to this controller from the view, indicating which URL it should use to fetch the data for ...

Master the art of horizontal scrolling in React-Chartsjs-2

I recently created a bar chart using react.js and I need to find a way to enable horizontal scrolling on the x-axis as the number of values increases. The chart below displays daily search values inputted by users. With over 100 days worth of data already, ...

How can I retrieve a variable in a JavaScript AJAX POST request?

Similar Question: How to retrieve a variable set during an Ajax request I am facing a challenge, as I am making an ajax call and receiving a number as the response. My query is, how can I assign this returned number to a variable that is accessible ou ...

Steps for adding a PHP dropdown menu to an HTML/Javascript webpage

Hey there, this is only my second post and I have to admit that I am a newbie in the world of web development. I'm spending countless hours scouring different websites for guidance, and I'm finally starting to grasp some concepts (at least for no ...

What is the best way to ensure the initial item in an accordion group remains open by default when using NextJS?

I've successfully developed an accordion feature in NextJS from scratch and it's functioning flawlessly. However, I am looking to have the first item of the accordion open automatically when the page loads. Can anyone guide me on how to make this ...

Filtering out any inappropriate characters from the XML data before processing it with the XMLSerializer function

I am currently working on a solution to store user-input in an XML document using client-side JavaScript and then transmit it to the server for persistence. One specific issue that I encountered was when a user input text containing an STX character (0x2) ...

Do you have any tips on designing a mobile-friendly navigation bar?

Struggling with creating a responsive navbar using Bootstrap 5? The navbar-brand is causing issues with letters overflowing over other elements, and the toggle-icon is not aligning properly. Check out my Codepen for reference: https://codepen.io/namename12 ...

Avoid showing images when the link is not working

I am dynamically fetching images and displaying them on my webpage. return <div className="overflow-hidden "> <Image className="relative w-full h-40 object-cover rounded-t-md" src={cover_url} alt={data.name} ...

Comparison between triggering a 'click' event with or without indexing is often debated in web development circles. While trigger('click') invokes the click event

Can someone clarify the difference between using trigger('click') and trigger('click')[0]? Are there any distinctions between the two? ...