When the mouse hovers over the image within the div, it undergo

I want to create "links" that are actually titles of equipment or items I wish to review. When the title is moused over, I want the image to change, but remain changed even after the mouse moves away.

Existing code options don't meet my requirements. I'm open to using jquery, css, or javascript for implementation on a Wordpress site.

The simple concept involves having something like:

PICTURE GOES HERE

Equipment 1: front | back | side Equipment 2: front | back | side

Initially, Equipment 1: front would be displayed above. Then, upon hovering over any other option such as front, back, or side, the picture would change and hold until moving to another text.

Pre-loading is acceptable since it already exists on the site. The goal is to make it function similar to regular images on WP where clicking enlarges the picture, hovering provides caption, etc.

The desired appearance should mirror this example, featuring more titles below an image which can be hovered over.

I've tried using jquery with no success, as well as css that alters images upon mouse out – not the behavior I desire.

JQUERY - Attempted Code 1 (not effective):

<script type="text/javascript>
  $(document).ready(function() {

    $("#picture_links a").hover(function(){
        var src = $(this).attr("href");
        $("#picture_holder img").attr("src", src);
    })

    $("#picture_links a").click(function(){
        return false;
    })

})
</script>

CSS - Alternative Script (functional but not ideal):

/* On mouse image roll over */

img.nohover {
border:0
}
img.hover {
border:0;
display:none
}
a:hover img.hover {
display:inline
}
a:hover img.nohover {
display:none
}

Answer №1

Here is a handy jQuery function to swap images on mouseover:

jQuery("elementid").mouseover(function() 
{
    var imageId = jQuery(this).attr("imageID");
    var image = jQuery(this).css('background-image');

    var newImageId = imageId++;
    if (newImageId >= 3)
        newImageId = 0;

    var newImage = image.replace(imageID, newImageId);
    jQuery(this).css({ "background-image": "newImage " })

}

Keep in mind that this script will only work if your images are named sequentially and do not have numbers in their actual file names besides the sequence number. Make sure to add an attribute named imageId to your div elements for it to function properly.

Answer №2

This is the method they employ

function updateImage(docID, objName)
{
    document[docID].src = eval(objName + '.src');
} 

Are you looking for a visual image or would a background suffice?

Your initial code snippet appears to be correct. Could you demonstrate its functionality somewhere? I am intrigued.

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

VueJS does not update values instantly as they change

I have implemented a JS class with the following code: class Field { public Value = null; public Items = []; public UniqueKey = null; public getItems() { let items = [...this.Items]; items = items.filter((item) => { ...

Identify the CSS Framework being used in conjunction with Selenium

I have developed a program that crawls through various web pages and conducts tests using Selenium. My current task is to identify which CSS Frameworks are utilized on these websites for statistical analysis. Currently, I am using the FireFox Webdriver to ...

The link in the HTML code has been prevented from opening in a new

echo "<tr><th align='left'><a href=\"$email\">$name</a></th> I recently transformed a PHP Email App into a saving app. However, I am encountering an issue with opening links within the application. You ca ...

Angular and CSS: incompatible with each other when it comes to formatting

It's quite unexpected that the formatting I apply is not being accepted. When I insert it within the index, everything looks perfect: <main role="main" class="container-fluid"> ... </main> The design displays correctly with "ABC" positio ...

Malfunction in function calling due to improper ajax response (JSON)

There seems to be an issue with the success function not being executed in the JavaScript code below: $.ajax({ type: 'POST', url: 'http://localhost/hf_latest_desktop/st_pages/user_area/acc_buttons/pass_change/pass_ ...

Navigate through content to reach the bottom of the webpage

I am currently working on a layout that is similar to Facebook's messaging system (facebook.com/messages). I have made some progress with it, but not quite there yet. You can view my work so far here: https://jsfiddle.net/3nd0b17m/23/ https://i.sstati ...

This issue with ng-include not functioning properly in Chrome but working fine in Firefox

My code is running only in Firefox and not working in Chrome. HTML Code <div ng-controller="myController1"> Select View: <select ng-model="employeeview"> <option value="1.html">1</option> < ...

What steps should I take to enable Google Maps style on mobile devices?

Hi there! I'm having some trouble styling my Google map. Sometimes the style loads correctly in browsers, and sometimes it doesn't. Another issue I've noticed is that when I view the page on mobile platforms like Android Chrome, iOS Safari, ...

Convert string IDs from a JSON object to numerical IDs in JavaScript

My goal is to convert the IDs in a JSON object received from PHP into numeric keys using JavaScript. The initial structure of my JSON object looks like this: let foo = {"66":"test","65":"footest"}; What I aim for is to transform it into this format: let f ...

What steps should I take to transform this into an ajax form?

I'm struggling with converting this code into an Ajax form. Can someone guide me on the process? @using (Html.BeginForm("", "CollaborativeProjects", FormMethod.Post, new {enctype="multipart/form-data"})) { <input type="file" name="FileUpload1 ...

"Transform the appearance of the character pointer in Atom Editor by customizing the theme

Hey everyone, I need help with a couple of things. I'm trying to figure out how to adjust the color of the cursor in Atom. Any tips on how to do this? Another issue I'm having is with the find function in Atom. The highlighted words that ma ...

Tips for selecting the appropriate cssSelector value within the Chrome browser using the Developer Tools (F12) feature

What is the process for selecting a cssSelector() in Chrome Browser using Chrome Developer Tools? Could you provide an example for the given code snippet below? WebElement searchBox = driver.findElement(By.cssSelector("selector")); searchBox.click(); ...

Tips for managing the background color of a box when the function is constantly refreshing in Internet Explorer

function process(Objects) { var objectId = Objects; displayContent(objectId); } function displayContent(objectId) { var boxId = objectId.id; var color = ret ...

Using SVG Mask to enhance shape Fill

I am having trouble achieving the desired effect of darkening the fill of objects based on a specified gradient. Instead, when the mask is applied over the fill, it actually lightens it. I suspect that this issue arises from the color blending method being ...

Tips for lining up two images and text on the same row

I am facing a simple issue - how can I align an image and text in one line like this [image - text - image] and repeat the pattern. <html> <head> <title></title> <style> img { width: 100px; h ...

Exploring CakePHP 3's capabilities with JSON response: Enhancing response data format by connecting with related tables

I am working with two tables, each with their own set of attributes: Sessions id staff_id Staff id firstname lastname When a link is clicked, it triggers a JavaScript function to open a modal. An AJAX call is then made to retrieve data in JSO ...

Extract TypeScript classes and interfaces from a consolidated file

I am seeking a way to consolidate the export of my classes, interfaces, and enums from multiple files into a single file. In JavaScript, I achieved this using the following method: module.exports = { Something = require("./src/something").default, ...

How come the data from the Firebase real-time database is only displaying in the console and not on the page when using Vue.js?

I am encountering an issue while trying to display a value stored in my Firebase Realtime Database using the {{ exams.name }} syntax in Vue. Although I can see the value when I console.log it, it does not render on the page. However, when I attempted the s ...

Unable to connect state to props when utilizing combineReducers

I'm currently working on integrating my state with a specific component using Redux. To achieve this, I have implemented two reducers and utilized combineReducers to merge them into a rootReducer before initializing my store. const rootReducer = comb ...

FancyBox: Struggling to adjust dimensions accurately

Currently using Fancybox 1.2.6 in conjunction with JQuery 1.2.6, Sample Code: <script type="text/javascript> $(document).ready(function() { $("a.iframe").fancybox({ 'width' : 300, 'hei ...