Add interactive buttons to an image that will appear when hovered over, while also darkening the

Is it possible to create an effect where the image darkens slightly when the mouse hovers over it, followed by buttons appearing on hover like in the image provided? Additionally, when hovering over a button, could it change color to red similar to the picture, with the image description text appearing below the buttons as shown? Furthermore, once a button is clicked, can it redirect us to a new URL (e.g., www.google.com)? I'm unsure how to implement this - does anyone have any code snippets they could share?

https://i.sstatic.net/VE7dR.png

Answer №1

I believe this solution aligns with your needs. Feel free to give it a try. My focus was on addressing your main points, so hopefully this will suit your requirements.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
</head>
<style type="text/css">
 body{
  margin: 0;
  padding: 0;
 }

div.contain{
  width: 1000px;
  height: 667px;
  border: 2px solid black;
  margin: 100px;
  margin-top: 10px;
  background-image: url(https://dancingaspen.files.wordpress.com/2015/09/coffee-shop-mug.jpg);
}

div.mask{
  width: 100%;
  height: 100%;
  background-color: black;
  position:relative;
  opacity: 0;

}

.zoom{
  width: 150px;
  height: 50px;
  color: white;
  font-size: 35px;
  background-color: red;
  position: absolute;
  top: 300px;
  left: 300px;
  border: 2px solid white;
  border-radius: 10px;
  display: none;
  text-align: center;
  font-size: monospace;
  padding-top: 15px;
  text-decoration: none;
}

.description{
 
  position: absolute;
  width: 70%;
  height: 30%;
  top:410px;
  left: 12%;
  font-size: 35px;
  color: white;
  font-family: zapfino;
  text-align: center;
  display: none;
}


</style>
<body>

<div class="contain">
 <div class="mask"></div>
    <a href="#" target="_blank" class="zoom">ZOOM</a>
    <div class="description">your description here</div>
</div>

 <script type="text/javascript">
   $(document).ready(function(){
    $(".contain").mouseenter(function(){
      $(".mask").animate({opacity:0.5},1000);
      $(".zoom").fadeIn(1500);
      $(".description").fadeIn(1500);
    });

     $(".contain").mouseleave(function(){
      $(".mask").animate({opacity:0},1000);
       $(".zoom").fadeOut();
      $(".description").fadeOut();
    });
   });
 </script>

</body>
</html>

Simply copy, paste, and execute the code above to see the results.

Answer №2

To achieve a darkened effect on images, you can utilize basic CSS properties with the 'hover' attribute. Simply select the image or its containing div and apply a lower opacity on hover state using opacity:0.5;

If you prefer to darken the image without altering the background, consider setting the image as the background of the parent div.

<main container>
   <sub container>

.main {background: 'images/image.jpg';}
  .sub {background-color: black; opacity:0;}
  .sub:hover {opacity:0.7;}

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

Tips for incorporating animation when opening a Jquery SimpleModal

The SimpleModal website features an animation-enabled example with the following sequence: 1. Display modal only 2. Fade in the overlay The code snippet for this animation is as follows: $("#the-div").modal({ onOpen: function (dialog) { dialog.overl ...

Challenges encountered when uploading a file using PHP

I am having trouble uploading a file to a server using PHP. The code I have is as follows: if( isset($_POST['Upload']) ) { //size condition if ( $_FILES['uploaded']['size'] > 350000) { $mesg = "Your file ...

Using the HTML5 Video Element on an iPad

Having trouble playing a Quicktime movie (.mov) on my iPad. Instead of the video, I just see a black area. Not sure if using the VIDEO tag will work for Quicktime videos. Does the VIDEO tag even support the .mov format? What's the best way to play a ...

The option for selection is malfunctioning

I'm brand new to jQuery and definitely not a "tumbleweed" )-; so please be patient with me. My jQuery mobile app currently sends data to an API. There are three XML documents based on daily, weekly, and monthly activities generated by the API. I nee ...

Transmit JSON from PHP to an autocomplete feature and include a data attribute in the input field

[{ "id": "39", "name": "John Doe", "code": "060400000" }] $(document).on("input", ".autocomplete", function(event) { var name = $(this).prop('id').split('_').pop(); $(".autocomplete").autocomplete({ source: function(request, respo ...

Is it possible to manipulate the content inside a div tag using JavaScript in HTML?

What is the most efficient way to dynamically adjust a data offset value within an HTML tag using JavaScript? For example: <div class="box" data-offset="2s"></div> I am looking to update the value within the data-offset attribute based on s ...

Obtain the image's name using Jquery

I have the following HTML code snippet: <li class="rpItem rpFirst d1"> <a href="#" class="rpLink 1"> <span class="rpOut"><img alt="" src="http://localhost:64034/Images/favorites_small.png" class="rpImage"> <spa ...

Recursively toggle child elements using JQuery

My knowledge of JQuery is limited, so here's the issue I'm facing. Below is an example of the HTML structure: <ul class="first-class"> <li class="second-class"> <a href="#_"> <i class="fa fa-plus"></i& ...

What is the most effective method for parsing a JSON object with a dynamic object name?

Is it possible to access specific object keys and perform actions based on the object name retrieved from a JSON object? If so, how can I achieve this? The JSON object 'x' will be fetched through an AJAX call from the server. Depending on the ob ...

Can I kindly request assistance with implementing jQuery Autocomplete on a C# IHttpHandler in a non-sequential

Currently, I have an autocomplete textbox that is requesting an IHttphandler through IIS7 using C#. However, it seems like the requests reaching the web server are arriving unordered. Below is a snippet of the log obtained from the IHttpHandler after typ ...

Can someone show me how to position this button within a React component onto the card that I've just made?

After successfully creating a Button component with separate JS and CSS files for styling variations, I am facing an issue where the button instance added to an advert card is not moving up as intended. Upon inspection, it seems that the button in the adve ...

Resize the Bootstrap select element based on its contents

My HTML code includes a <select> element that is styled using Bootstrap 5. <div class="col-md-12"> <div class="mb-3"> <label asp-for="Schedule.Minutes" class="control-label"></l ...

Green and red values hovering within the keyframe

Currently, I'm facing a dilemma involving keyframes. I have a table populated with values retrieved from a JSON fetch and need to implement a hover effect where values less than 5 show in red, while those equal to or greater than 5 appear in green. Be ...

Instructions on making a Popup appear after a specified duration of mouse inactivity on a webpage

Hello, I am new to web development and could use some guidance on creating a popup window for users to enter their username and contact number. It should be able to store this information in a database and activate after the user has been idle for about 10 ...

What is the best way to ensure an inline-block element spans the entire width?

Is there a way to make an inline block fill the entire width without using !important in AMP? I have tried making all fields fit the whole width but it's not working. How can I achieve this without resorting to !important? Below is the code I am curre ...

Chrome's Ctrl-Shift-N event binding

I have implemented jQuery.hotkeys to handle keyboard events. Currently, I am attempting to bind the combination of Ctrl+Shift+N $(document).bind('keydown', 'ctrl+shift+n', function(e) { e.preventDefault(); alert('Ctrl+Shi ...

Ways to retrieve the current tab title that I have designated in the Jquery Tabs UI

I found this helpful resource at http://jqueryui.com/demos/tabs/#manipulation and I am currently using it. My goal is to retrieve the title of the tab that is currently selected and which I had previously named (for example, in the href attribute). How can ...

Move a div element as you scroll down the page

I currently have a div that appears when a user scrolls down a page. When clicked, it sends you back to the top of the page. Right now, it simply fades in and out, but I would like it to slide in from the right side of the page. Below is my existing code: ...

What is the best way to address cookie issues while working on a full stack application that utilizes Vue and Express.js?

Developing a full stack application requires me to use Vue on port 5173 and Express on port 3000. One issue I face is the inability to store credentials in the frontend for backend communication during development. This challenge can be addressed by servin ...

I am encountering a problem with the $invalid property in AngularJS

Hey there, I've got a coding dilemma involving three number inputs, which I will refer to as the first input, second input, and third input for clarity. Here's the setup: <div> <form name="formOpenMax"> <div clas ...