Switching between different CSS transition effects

Perhaps my approach is not ideal, so please feel free to provide feedback if this is not considered best practice.

I have created DIVs that contain a checkbox and label. These styled DIVs resemble buttons, and I have implemented code to allow users to toggle the checkbox value or state by clicking (or tapping) on the DIV (this functionality is not shown in the code below).

Below is an example of what the HTML for the DIV looks like:

<div class="funkyCheckBox">
<label for="inputName">Label Text</label>
<input type="checkbox"  name="inputName" id="inputID" />
</div>

Additionally, when a user clicks or taps on the DIV, I would like to change the appearance of the container DIV with the .funkyCheckBox class to visually indicate to the user that the checkbox state has changed. I utilize jQuery toggle to apply an active state to the DIV (adding or removing the class funkyCheckBoxActive).

Here is the CSS code:

.funkyCheckBox{
    display:block;
    border-radius: 1em 1em 1em 1em;
    margin-bottom:.5em;
    background: #ffffff; /* Old browsers */
    /* Add more gradient styles here */
    padding:.5em;
}

.funkyCheckBoxActive{
    background: blue; 
    -webkit-transition: background-color 1000ms linear;
    -moz-transition: background-color 1000ms linear;
    -o-transition: background-color 1000ms linear;
    -ms-transition: background-color 1000ms linear;
    transition: background-color 1000ms linear;
}

Below is my updated jQuery code:

$(".funkyCheckBox").live("click, tap", function(){
    $(this).toggleClass("funkyCheckBoxActive");
});

When a user clicks one of the .funkyCheckBox Divs, the new class is added with a smooth CSS transition. However, upon clicking again, the .funkyCheckBoxActive class is removed instantly. I am seeking a way to implement a similar transition effect when the class is removed, rather than it being an instant removal. Any suggestions on the best approach? I had considered adding a transition to the .funkyCheckBox class, but I understand this may not achieve the desired effect. Your thoughts?

If my explanation is unclear, please let me know, and I will try to clarify further.

Answer №1

Enhance your funkyCheckBox design by incorporating CSS transitions instead of relying solely on background gradients for a more dynamic effect.

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

Arranging several collapsible DIVs in the navbar using Bootstrap

Currently, my navbar design includes a search field placed before the menu items. These elements are contained in separate collapsible DIVs to allow for individual toggles. The issue I am facing is that there is a noticeable gap between the search bar an ...

Having an issue with the pop state function not functioning correctly

I am facing an issue with my images where clicking on a specific image changes the URL to that ID. However, I can only go back once and then the same URL is repeated every time I press the back button. Additionally, the forward button does not work at all. ...

The Rmarkdown HTML matrix output is displaying in a width that is too slim

I have explored the available solutions to increase output width : option(width=200) The problem arises when using rmarkdown to convert directly from an R file to html, as the output is constrained by the size of the html container, not the specified R o ...

Solving the "ExpressionChangedAfterItHasBeenCheckedError" in Ionic: A Guide

//html <span style="margin-left:43%;background-color:rgb(229,229,229);border- radius:10%">&nbsp;&nbsp;{{formatEpoch(epoch)}}&nbsp;&nbsp;</span> //ts lastdate:any; formatEpoch(epoch): string { ...

I'm having trouble getting my modal to work and display properly; I need to send it to the code behind for further assistance

I'm having trouble with my modal. I'm trying to create a sign-up modal and send it to my code behind page. I've incorporated bootstrap lumen and jquery, but I could use some assistance. Any help would be greatly appreciated. Thank you in adv ...

managing the speed at which animated gifs are loaded and played

I am facing a challenge with a slideshow that features multiple animated gifs. Each slide is equipped with its own animated gif. My goal is to ensure that the animated gifs play in synchronization with the timeline I have set up in photoshop, starting fro ...

The parsererror occurred while executing the jQuery.ajax() function

When attempting to retrieve JSON data from using the following code: (Using jQuery 1.6.2) $.ajax({ type: "GET", url: url, dataType: "jsonp", success: function (result) { alert("SUCCESS!!!"); }, error: function (xhr, ajaxO ...

X-editable does not verify if the checklist values are checked

Hello everyone, currently I am working on a Laravel project where I have implemented the X-editable library for inline editing functionalities. I am facing an issue with updating a many-to-many relationship table (pivot table) and I am trying to use the X- ...

Utilize HTML code within a .php file without it being parsed

When I include HTML code in my PHP file, the HTML code doesn't get interpreted and just appears as text in the browser. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title>Document</title> ...

Using a SASS watcher to keep an eye on every folder and compile them into a single CSS

I'm interested in setting up a folder structure like this: assets - scss - folder file.scss anotherfile.scss anotherfile.scss anotherfile.scss - anotherfolder file.scss anotherfile.scss anotherfile.scss ...

Ways to bypass a transition using JavaScript

Hello everyone, I would like to start by apologizing for any mistakes in my English. I have been working on a website, which is currently available here: As you scroll down, the height of the image below the menu decreases. I am trying to make the navig ...

How can I retrieve a list of dynamic dropdown/selectbox options using JavaScript and Laravel?

I am facing an issue with a dynamic dropdown field in my update form modal/popup within Laravel 5.2. The dropdown list works only in the first row, and when I add more dropdowns, the lists do not show up because I am unsure how to implement foreach in the ...

Updating an element in jQuery using the .each() method

HTML code: var values=[5, 10, 15, 20, 25, 30] $.each(values, function(position, number) { setTimeout(function() { $('#contentBox').text(number); }, position * 5000 ); }); I am attempting to update the content of the contentBox d ...

Get rid of the ad wrapper that prompts users to disable their adblocker on the news page

Everyday, I visit the Norwegian news site "www.vg.no" to catch up on the latest news. However, one day while browsing on my school computer with adblock installed, I noticed that the ads were removed but an ad wrapper appeared asking to turn off adblock. B ...

Conceal the form after it has been submitted

I am working with the following JavaScript function: var form = $('#review-contact-form'); form.submit(function(event){ event.preventDefault(); var form_status = $('<div class="form_status center"></div>'); $.aj ...

What could be causing me to have to click the button twice in order to view my dropdown list? Any suggestions on how to

I am facing an issue where I have to click twice on the "Action" button in order to see my dropdown list. How can I resolve this? Is there a way to fix it? $(document).ready(function() { $(".actionButton").click(function() { $dropdown = $("#cont ...

Adjust the text orientation using CSS within an SVG element

Here is the SVG code snippet that I am working with: https://jsfiddle.net/danpan/m3ofzrc1/. It generates the image shown below. The image consists of two lines of text wrapped around a circle: HELLO_WORLD_1 HELLO_WORLD_2 I want to change the direction ...

Tips for transforming an html form into an ajax request for a rest controller when dealing with a multi-select field

I am encountering an issue with the field "roles" as it is a select list with multiple choices. I need to convert this field into an array, but I have not been able to find any information on how to do so. Any assistance would be greatly appreciated. Thi ...

Having trouble getting my image and text to align properly in two columns

<img id="story_image" src="images/builder_story_side.png" alt="photo"/> <div id="story_right"> <h2 class="story_header">fdgdfgdfgdfgdfgfdgdfgfdgdfgdfgdfgdfgdfgdfgdfgdfgdfgfdgdfgdfgdfgdfgdfgdfgdfgdfgdfgdfgdfgdfgdfgdfgdfg</h2> <p ...

Chakra UI is providing an incorrect font style

I recently attempted to incorporate the M Plus Rounded 1c font into my project by following the guidance provided by Chakra UI on using custom fonts (link: https://chakra-ui.com/community/recipes/using-fonts). However, I encountered an issue where Chakra U ...