Is it possible to add a click event to an image with a hole inside, allowing the image behind it to show through?
Check out this JSFIDDLE for reference
//javascript code
$('#ant').click(function()
{
alert("hi");
});
Is it possible to add a click event to an image with a hole inside, allowing the image behind it to show through?
Check out this JSFIDDLE for reference
//javascript code
$('#ant').click(function()
{
alert("hi");
});
To efficiently create an interactive Image Map, consider using tools like or refer to W3Schools for guidance on the <map> tag: http://www.w3schools.com/tags/tag_map.asp
Trying to accomplish this with jQuery can be tricky (the top image always seems to capture the click event). My recommendation is to explore the <map>
tag:
One issue is that the top image remains visible, even if it is transparent. To find out where a user has clicked on the top image, you can utilize the following approach:
$('#rainbow').click(function (e) {
var offset = $(this).offset();
var left = e.clientX - offset.left;
var top = e.clientY - offset.top;
if (left > 95 && left < 300) {
if (top > 95 && top < 220) {
alert("hi");
}
}
});
The above code snippet is close to a solution, but since the image shape isn't square, it may not be entirely accurate. By logging the values of left
and top
, you can experiment with adjustments and introduce additional logic for a more precise outcome.
In jQuery, you have the ability to attach a click event to both images, where clicking on the top image will activate the click event of the bottom image.
$("#topImage").click(function(e) {
e.preventDefault();
$("#bottomImage").trigger("click");
});
$("#bottomImage").click(function(e) {
alert("Bottom image sound");
});
Therefore, when the top image is clicked, it triggers the onclick function of the bottom image.
Utilize a background image for the first DIV, position the second DIV in the center of the container, and use the third DIV to display an alert message.
<script>
$(function(){
$('#ant).click(function()
{
$('#message).html("Hi. This is event inside hole...");
});
});
</script>
<div class="background-image">
<div class="container">
<div id="message"></div>
</div>
</div>
<button type="button" id="ant">Click and write</button>
Remember to customize everything with CSS accordingly...
Aside from the points mentioned earlier, utilizing the <area>
tag can be beneficial.
While coordinates may seem like an outdated method of writing code, they allow you to pinpoint specific areas on an image by specifying x1,y1,x2,y2
for a shape=rect
, x,y,radius
for a shape="circle"
, and even shape="poly"
for polygons with coordinates listed as x1,y1,x2,y2,..,xn,yn
.
I recommend experimenting with these techniques to determine which works best for your needs and preferences.
W3SCHOOLS AREA TAG EXPLANATION
My HTML includes a <div>...</div> section that serves as a toolbar. Is there a method to position this section at the bottom of the webpage (document, not viewport) and align it to the center? ...
I've created a WCF restful service that has a login method exposed to the outside world. The purpose of this method is to validate user credentials with a database (specifically the login table) and return the result in json format. C# code: [Operat ...
Currently, I am facing an issue with the jQuery code I am using to highlight the selected row in my grid. It seems to be taking longer than anticipated to select the row. Does anyone have suggestions on how I can optimize this code for better performance? ...
Previously, I created a functionality for handling a single set of tabs. However, as the application has expanded, this functionality is no longer sufficient to accommodate multiple sets of tabs. The initial function looked like this: var iconTabs = func ...
I have a JSP page that contains the following code snippet: <li id="notifications"> <c:choose> <c:when test="${empty alerts}"> <p class="text-default">There are no Service Reminders at this time</p> ...
Is there a way to display a popup message before redirecting to another page when clicking on a button? Here's the scenario: <a href="addorder.php?id=<? echo $row01['id']; ?>" ><button id="myButton" class="btn btn-primary btn ...
Currently, I am dealing with an XML file and attempting to extract data from it. The structure of the XML file is as follows: <doc> <str name="name">Rocky</str> <str name="Last_name">balboa</str> <str name="age ...
Is there a way to detect when the refreshed content is the same as the original in jQuery? I am using JQuery's $('#somediv').load() and $.ajax() to refresh content, but I want to slow down the process if the new content is identical to the ...
After receiving an array of data from a JQuery .ajax function, I noticed that the fields in the array are named and numbered like part1, part2, part3, etc. I attempted to loop through this data using the code below, but unfortunately, it resulted in NaN: ...
I am attempting to transform my static bootstrap data table, which displays the total count of fruits harvested in various months in an incremental manner, into a dynamic one using the JSON provided below: JSON { "fruit": [ { "fruitName": "Al ...
Looking for help with styling an element created using document.createElement("img")? let fireball; //global variable fireball = document.createElement("img") //variable on local fireballArray.push(someFunction(fireball, { src: "img.png&qu ...
I'm utilizing vue-slick-carousel to populate schedule data for a specific slide (in this case, a month). <vue-slick-carousel @afterChange="afterChange" @beforeChange="beforeChange" @swipe="swipe" class="te ...
My current file structure looks like this: Wamp>www>Newlinks CSS (folder) header.php footer.php Profiles (folder) MainPHPfile.php I'm trying to include the header and footer files into MainPHPfile.php, but it's not working ...
I am in the process of upgrading a website that is built with Foundation to version 5.2.0 in order to address some Orbit issues and other improvements. I typically initialize components using data attributes like data-orbit and have had success with using ...
Is there a way to achieve this layout view image here (currently done using tables) while maintaining semantic markup? I believe the best tag for this would be dl. Each cell should have the height of its corresponding row. EDIT: The left column contains d ...
What is the best way to target a div element that contains the text "my content"? <table> <tr> <td class="ms-disc-bordered-noleft"> <div class=""> <div>some content</div> <div>my conten ...
One challenge that I am facing is setting object property values. The object in question looks like this: const newPlan = { name: '', description: '', number: '', monday: { breakfast: '', ...
I want to implement a feature where a div is hidden when its child element is empty. To achieve this, I aim to assign the class .no-content to the div if it contains no elements. Below is my existing code with spaces: <div class="ee-posts-list&quo ...
I'm currently facing an issue with my chart component in a view. I've been trying to reduce its size using max-width property but it doesn't seem to be working. Below are the relevant code snippets: <div id="chart"> < ...
I have created a unique jsfiddle with 20 boxes that I am trying to animate using the Animate.css plugin. The plugin can be found at daneden.me/animate. My goal is to animate each box one after the other in a sequential manner, but I seem to be having trou ...