Changing color when mouse hovers using Jquery

Currently, I am in the process of converting a flash ad into an html5 ad.

I found this demo here, and I would like to replicate the mouse hover effect showcased. When the cursor hovers over the details text in the banner, the entire background changes to black and shows a disclaimer message. How can I achieve this same effect?

You can view my current code on JSFiddle

<div id = "wrapper">       
 <div id="mainContainer">
    <div id="text">
        <img id="Image_Car" src="http://i.share.pho.to/c43dc6d7_o.png" />
    </div>  
     <div id="Div1">
      <p id="disclaimer">Details*</p>
    </div>
 </div>
</div>

Answer №1

If I have grasped your concern correctly, this solution might be helpful:

Check out this Live Demo

Utilizing jQuery's built-in .hover() method, you can toggle a class on the wrapper and display the hidden copy block as demonstrated below:

Javascript:

$('#discalimer').hover(
    function () {
        $('#wrapper').toggleClass('hovered');
        $('.copy').show();
    }, function () {
        $('#wrapper').toggleClass('hovered');
        $('.copy').hide();
    }
);

Answer №2

If you are not in need of any animations, you can simply follow these steps:

$('#warning').hover(
    function () {
        $('#container').addClass('active');
    }, function () {
        $('#container').removeClass('active');
    }
);

Then utilize CSS for the desired styling:

.message {display: none;color: black; padding: 5px;}
.active .message { display: block; }
.active #wrapperBox { background: white; border-color: gray; }
.active #Image_Plane { display: none; }

http://jsfiddle.net/abcd123/45/

Answer №3

Check out the demo

Here is the HTML code:

<div id="wrapper">
    <div id="mainContainer" class="mcClass">
        <div id="text">
            <img id="Image_Car" src="http://i.share.pho.to/c43dc6d7_o.png" />
        </div>
        <div id="Div1">
            <p id="discalimer">Details*</p>
            <p id="realDisclaimer" style="display:none">This is the real disclaimer</p>
        </div>
    </div>
</div>

The CSS for styling:

#wrapper {
    left: 50px;
    top: 50px;
    width: 300px;
    height:250px;
    position: absolute;
}

#realDisclaimer{
    color:white;
}
#Div1 {
    top:142px;
    left:76px;
    width:50px;
    height:30px;
    position: absolute;
}
.unselectable, #Div1 p {
    -webkit-user-select: none;
    /* Chrome/Safari */
    -moz-user-select: none;
    /* Firefox */
    -ms-user-select: none;
    /* IE10+ */
    /* Rules below not implemented in browsers yet */
    -o-user-select: none;
    user-select: none;
    cursor:default;
}
.mcHoverState {
    background-color:black;
}
.mcClass {
    background: url('https://secure-ds.serving-sys.com/BurstingRes/Site-8188/Type-0/5fefb401-b187-4d82-b4db-cbd2ef29cc48.gif');
}
#mainContainer {
    width:300px;
    height:250px;
    overflow: hidden;
    position: absolute;
}
#Image_Car {
    position:absolute;
    overflow: hidden;
    margin:60px 8px;
    left: -120px;
}

Lastly, the JavaScript function:

 $(document).ready(function () {
     bannerAnimation();
     $("#Div1").mouseenter(

     function (evt) {
         $("#text").hide();
         $("#mainContainer").removeClass("mcClass").addClass("mcHoverState");
         $("#discalimer").hide();
         $("#realDisclaimer").show();
     })
         .mouseleave(

     function (evt) {
         $("#realDisclaimer").hide();
         $("#text").show();
         $("#discalimer").show();
         $("#mainContainer").removeClass("mcHoverState").addClass("mcClass");
     });
 });

 function bannerAnimation() {
     //Jquery Animation
     $("#Image_Car").animate({
         left: "30"
     }, 500, function () {
         $("#Image_Car").animate({
             left: "10"
         }, 200);
     });
 }

Answer №4

Here We Go Again! Have you tried using that windy plugin yet?

I'm not exactly sure what you're asking for, but here's a possible solution:

Before diving in, let's talk about colors: on the web, color is defined by Red Green Blue values. You can pinpoint the X and Y coordinates of your jQuery code and create some mathematical formulas based on that:

Check out this jsfiddle link

#wrapper:hover #mainContainer
{
    background:silver;
}
#wrapper:hover
{
    background:black !important;
    box-shadow:3px 3px 3px rgba(186,202,228,1);
    color:white;
}

Also, here's a demo showcasing the code in black color: Take a look at this demo

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

Guide on modifying HTML attribute with TFHpple in the Swift programming language

I have received an HTML string and I want to modify the elements inside them, specifically the img tags, so that they have a style of width = 100% and height set to auto. This way, when I embed these images into a web view, they can easily adjust to fit th ...

In a Twitter Bootstrap environment, the button cursor transforms into an I-beam when activated

After utilizing twitter bootstrap to construct a small blog site and integrating a third-party file upload application into the project, I encountered an issue. The CSS files in the file uploader style the "upload button," but when my cursor hovers over it ...

Having trouble deciphering this snippet of Express JS source code

Upon reviewing the Express JS source code, I came across the main module where express is being exported. module.exports = createApplication; function createApplication() { var app = function(req, res, next) { app.handle(req, res, next); }; m ...

How to place a div within another div without using absolute positioning

I've been searching for a solution to this issue, but nothing seems to be working. I want the inner div to be positioned at the bottom of the outer div, with a 5px margin separating them. However, using absolute positioning disrupts the width and cent ...

Tips for sending and showcasing a multi-dimensional array using ajax

Currently, I am implementing my project with an Object-Oriented Programming approach. One of the tasks involves passing all database values in the form of a multidimensional array through AJAX, displaying the array using 'text' datatype in consol ...

Enhancing the functionality of hidden input fields using jQuery

I'm looking to dynamically update the value of a hidden input element when a button is clicked. Here's what I have so far: Hidden Input Element: <input type="hidden" value="action" id="action" /> Buttons: <INPUT name=submit value=~#S ...

The persistent Bulma dropdown glitch that refuses to close

In the project I'm working on, I have implemented a Bulma dropdown. While the dropdown functions correctly, I am facing an issue when adding multiple dropdowns in different columns with backend integration. When one dropdown is open and another is cli ...

Sending string variable from Perl CGI script to HTML frontend

Having just begun experimenting with AJAX, I'm encountering difficulties in passing variables back to my HTML script. In this setup, I'm using a combination of a XAMPP webserver, JavaScript, and jQuery for the HTML script, along with a Perl cgi ...

Menu drop down offset in Internet Explorer 7

Having some difficulty with a dropdown menu specifically in IE7. The menu functions correctly in all other browsers, but in IE7 it seems to be misaligned for some reason. Any suggestions or insights would be greatly appreciated. Please refer to the menu co ...

JQuery draggable and JavaScript functionality become disabled following an AJAX request

I have a click event declared as follows: $('body').on('click', 'input#searchVariables', function () { var datasetId = $('.TSDatasetID').val(); var term = $('#searchTextbox').val(); ...

Conceal additional recipients in the "to" address field when sending emails with Node.js using Nodemailer

I am currently working on a project called EmailSender using node.js, and I have found that the nodemailer package is incredibly helpful. However, when sending emails to multiple contacts, all recipients are able to see each other's email addresses i ...

Unfortunately, CSS3 PIE is not compatible with border-radius and box-shadow properties

I created a basic HTML/CSS code for testing purposes, but I'm having trouble getting the library to function properly. I've placed the .htc, .php and .js files in the same directory as index.html, but it just won't work. Check out the code ...

The code below is not working as it should be to redirect to the home page after logging in using Angular. Follow these steps to troubleshoot and properly

When looking at this snippet of code: this.router.navigate(['/login'],{queryParams:{returnUrl:state.url}}); An error is displayed stating that "Property 'url' does not exist on type '(name: string, styles: AnimationStyleMetadata". ...

Developing a Typescript module, the dependent module is searching for an import within the local directory but encounters an issue - the module cannot be found and

After creating and publishing a Typescript package, I encountered an issue where the dependent module was not being imported from the expected location. Instead of searching in node_modules, it was looking in the current folder and failing to locate the mo ...

When trying to reference a vanilla JavaScript file in TypeScript, encountering the issue of the file not being recognized

I have been attempting to import a file into TypeScript that resembles a typical js file intended for use in a script tag. Despite my efforts, I have not found success with various methods. // global.d.ts declare module 'myfile.js' Within the re ...

Is it possible to integrate a Backbone app as a component within a separate app?

I am currently in the process of familiarizing myself with Backbone.js and front-end development, as my background is more focused on back-end development. I have a question related to composition. Imagine that I need to create a reusable component, like ...

Guide to positioning an image absolutely within a div

I am struggling to position a small close image within a div without success. The goal is for the image to always appear on the left side of the div, regardless of the content. The content consists of a text label with a maximum length of 8 characters. Iss ...

Styling elements with inline-block in IE8

Although there are countless questions addressing this particular issue, allow me to provide more details: The Dilemma The situation is as follows: aside { display: inline-block; } section { display: inline-block; margin-left: 2em; } Here, the eleme ...

Enable scrolling exclusively for the content within a tab, without affecting the tab label in Clarity Tabs

I have a tab with lengthy content in my project (check out the StackBlitz reference here). This causes the appearance of a scroll. The corresponding code snippet is provided below: <div class="content-container"> <div class=&qu ...

AngularJS: Toggle footer visibility with custom message

My goal is to develop an Angular app using Intel XDK with 3 page scripts in index.html, each having a separate footer. The requirement is for the footer and its message to display and hide every 5 seconds when running each page. app.js app.controller(&ap ...