A step-by-step guide on modifying the box-shadow color using jquery

I have developed some JavaScript code that adjusts the box-shadow of buttons to be a darker version of their background color. This allows users to dynamically change the button background colors.

The current code successfully changes the box shadow based on the background color, but I'm having difficulty making it so that the box shadow values only change on hover. Right now, the entire property is being affected instead of just the color of the shadow.

$("input[type=submit]").each(function() {
    //get button color
    var btnclr = $(this).css("background-color");
    //make darker
    $(this).css({
        "box-shadow": "0 -3px 7px " + LightenDarkenColor(rgb2hex(btnclr), -80) + " inset"
    });
});
input[type=submit] {
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #555753;
    background-color: cor11;
    font-weight: normal;
    text-transform: uppercase;
    box-shadow: 0 -3px 7px #888a85 inset;
}
input[type=submit]:hover {
    box-shadow: 0px 3px 7px #888a85 inset;
    text-shadow: 0 0;
}

While I could create a hover animation in JavaScript, I would prefer to stick with CSS as it is more lightweight. Any suggestions on how I can modify the box-shadow property by only changing the color part?

Answer №1

Yes, the CSS will be updated for input[type=submit] to include the hover effect. Instead of repeating all the necessary styles, only the additional styles for the hover state need to be defined.

input[type=submit] {
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #555753;
    background-color: cor11;
    font-weight: normal;
    text-transform: uppercase;
    box-shadow: 0 -3px 7px #888a85 inset;
}
input[type=submit]:hover {
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #555753;
    background-color: cor11;
    font-weight: normal;
    text-transform: uppercase;
    box-shadow: 0px 3px 7px #888a85 inset;
    text-shadow: 0 0;
}

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

Retrieve JSON data generated within a JavaScript-powered webpage

My issue involves two HTML pages: 1) The first HTML Page (page1.html): <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script> <script type="text/ ...

I am unable to display my JSON data in Next.js using a fetch request

I'm having trouble understanding the code, and it seems like the API is open to anyone since it's just a simple JSON. However, I keep getting an error: Error Message: Reason: `undefined` cannot be serialized as JSON. Please use `null` or omit th ...

Checkbox Trouble: Troubleshooting AJAX Integration

One of the requirements I have is to implement a checkbox list that updates the page via AJAX when one of the checkboxes is clicked. $(document).on("click", ".selectlist input", update_results); My client has requested that one of the checkboxes be pre-s ...

Firebase version 9 - Retrieve the content of a referenced document

I'm having trouble locating the documentation I need. Within my Firebase Firestore project, there is a collection called users. Within users, there are three collections: companies, policies, and stores. In the policies collection, I have fields for ...

Is there a way to create a dynamic associative array using jquery?

I am looking to create an array structured like the following:- arr[0][from] = value arr[0][to] = value arr[1][from] = value arr[1][to] = value . . And so forth. I have input array html elements for the from & to fields. <input type="text" name ...

Leveraging Font Awesome icons within a WordPress theme

After installing the flat-responsive theme, I noticed that it includes Font Awesome CSS. Additionally, there is a reference to this in the functions.php file: wp_enqueue_style( 'flat_responsive_font-awesome', get_template_directory_uri() . &apos ...

Utilize jQuery to dynamically assign classes to list items within a unordered list based on the length of an array

HTML: <ul class="tickboxes"> <li><i class="fa fa-check"></i></li> <li><i class="fa fa-check"></i></li> <li><i class="fa fa-check"></i>< ...

Managing promises - updating database entry if it already exists

I'm encountering a new challenge with Promises. Objective: Update the database entry only if P_KEY exists. The current database is accessible through a module that has both get and put methods for the database, each returning a Promise. Approach: ...

The duration from when the Ajax request is sent to when the response is received results in

Has anyone experienced strange results when measuring the time between sending and receiving an ajax request? Sometimes I get negative values. Can someone shed light on this peculiar behavior? var before = 0; var after = 0; $.ajax({ url: 'data.ph ...

The Javafx WebEngine's executescript() function is unable to send a multiline string

Issue: I'm struggling to make the JavaFX WebEngine trigger a JavaScript function when using a Java String object with multiple lines. If I input the following example in HTML: "asd" ENTER "qwe" into the textArea, and then click the send button, the f ...

Tips for shifting a div to the left with AngularJS

I am working with a div structure that looks like the following: <div class="col-xs-1 scroll-button"><i class="glyphicon glyphicon-chevron-left"></i> </div> <div class="customer-ust-bant col-xs-22" id="letters"> <box n ...

Move your cursor over a div element while utilizing NgClass

I'm currently working on implementing a hover effect on a div using an Angular ngClass directive. Within the template file, I have a div element with the class "list-item-container" that includes another div with the class "list-item." This "list-item ...

Basic HTML code that displays either one or two columns based on the width of the screen

My monitoring website displays dynamic rrd graphs in png format with fixed dimensions. I am looking to adjust the layout based on browser window size - showing the graphs in 1 column if the width is below a certain threshold, and in 2 columns if it exceed ...

Setting !important to every property's value at once

One interesting approach I am using is applying !important to all of the css properties' values like this: .someclass{ color: #f00 !important; background-color: #ff0 !important; margin: 0 !important; padding: 0 !important; width: 100% ! ...

Utilize the split() function to break down a string into separate

I'm facing an issue with splitting a string into an array using a regex that doesn't seem to be working properly. Here is my code: <script type="text/javascript"> function GetURLParameter(sParam) { var sPageURL = window.l ...

Tag-specific jQuery JSON search engine

I enjoy using Font-Awesome, but finding the right icon can be a tedious task. For example, there is no "fa-help" icon - it's actually "fa-question". The same goes for "fa-magnifying-glass" and "fa-view" which are actually "fa-search", causing unnecess ...

Is it possible to instantiate a Backbone view by referencing its string name that is stored within a JavaScript object?

I am currently working on a visual builder that utilizes different views for each component. Each view is defined as shown below: $(function() { var parallaxView = new Backbone.view.extend({ .... }); var parallaxView = new Backbone.view.e ...

Utilizing Jquery to retrieve an array as the return value from a $.post request

After going through numerous discussions on this topic, I'm still struggling to make it work. However, I've made significant progress. I have a scenario where I send data from jQuery to my database. The database returns a record consisting of two ...

How to transfer a user's comment from HTML to a C# model through a list within the MVC framework

I have been attempting various solutions, but none seem to be working. My goal is to create post and comment partial classes for a main page where end users can add comments. Currently, I am using MVC 5 and the page loads posts and previous comments. Howe ...

There seems to be an issue with the $scope variable not being properly updated within the function in

<button class="button button-primary" ng-click="updateSchedule(controlCenter.selected)"> Update Schedule </button> Calling the updateSchedule function from the button $scope.data = []; $scope.updateSchedule = function(selectedData) ...