Slide out a div when hovering over a button

Currently in the process of learning jQuery, I have managed to create a button that toggles a div containing colored buttons when clicked:

https://i.sstatic.net/VNxym.png

Once these colored buttons are pressed, the main white button changes color based on the selected option. However, I am now looking for a way to have this div of colored buttons slide out from the button div (preferably to the right) upon mouse hover so they can be easily selected.

Here is the progress I've made with jQuery so far:

//Functionality for clicking different colors
$("ul").on("click", "li", function() {
  $('button').removeClass().addClass(this.className);
});

//Action when white button is pressed
$("#revealColorSelect").click(function(){
  //Toggle visibility of color selection
  changeColor();
  $("#colorSelect").toggle();
});

//Update selected color
function changeColor() {
  var p = $("#pink").val();
  var pur = $("#purple").val();
  var r = $("#red").val();
  var b = $("#blue").val();
  var g = $("#green").val();
  var o = $("#orange").val();
};

Answer №1

To achieve a toggle effect, you can utilize the jQuery UI library. Make sure to include jQuery UI in your project before implementing the following code snippet:

$("#revealColorSelect").on("mouseover",function() {
  //Show color select or hide the color select
  $('#colorSelect').toggle('slide', {
    direction: 'right'
  }, 500, function() {
    changeColor();
  })    
});

Check out this working fiddle for a demo: https://jsfiddle.net/2o61gyyr/

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

What steps can I take to ensure my menu remains intact and functional on mobile devices?

I decided to use Bootstrap 4 for my responsive website, and I implemented its responsive Navbar component based on the instructions provided in this Bootstrap documentation. While the navbar functions properly on desktop, it seems to break on mobile device ...

performing iterations on html code with php

I have a code snippet inside an HTML file that I would like to loop using PHP. The goal is to repeat a paragraph on my HTML page as many times as needed. Any assistance with this would be greatly appreciated. <?php for($i=0;$i<=5;$i++){ <li ...

What is the name of the outlining structure in HTML5 known as?

A few days back, I came across an article discussing the usage of multiple h1 tags on the same web page. It also mentioned a specific structure that allows for multiple article, header, footer tags, and more. Unfortunately, today I'm struggling to rec ...

Having issues with customizing the design of MaterialUI Accordion header

Link to my code sandbox project I am encountering issues with the styling in my Accordion Heading. My Accordion Contents are set up like this: <Accordion heading1= { <DishItem name="Döner Teller Spezial" price="13,60€"/> ...

Verifying whether the field's value is null or empty

Is the following code snippet a reliable method for verifying if the value of a field is not null? if($('#person_data[document_type]').value() != 'NULL'){} Alternatively, are there more effective approaches to achieve this? ...

What could be causing my checkbox to become unresponsive and fail to reset?

I recently created a function to update my page title when the toggle button is clicked, but unfortunately, it seems to be getting stuck after the click. I can't seem to pinpoint the issue with this function, as I've tried coding it in both JQuer ...

Having trouble with the .load function not properly loading script functions. Is there a way to adjust the AJAX function

I attempted to use the .load function to load an HTML page with scripts, but unfortunately it is not working as expected. Is there a way to modify the existing code to utilize AJAX in order to load the complete HTML page along with its scripts? We specifi ...

The React Material UI table is having trouble stretching to fill the space

Currently, I am experimenting with developing my own virtualization technique using a different approach than react-virtualized. However, I am encountering difficulties when it comes to styling. I have come across an issue where the material table in the ...

Creating a consistent menu header across multiple webpages without the need to manually inserting the HTML on each individual page

Is there a way to display a consistent header across all web pages without manually duplicating the HTML code for each one? I'm looking to achieve this with JavaScript, without utilizing PHP. Would it be possible to leverage Angular JS ng-include func ...

Storing JSON results in cache using Twitter Bootstrap Typeahead

Using the twitter bootstrap library in my application has been a fantastic experience. I am currently working on implementing bootstrap typeahead for autocomplete and facing an issue with caching the results to reduce server requests. During my research, I ...

Display the JSON boolean value on the webpage using Ajax and Jquery

After using Ajax with a GET request to consume a REST web service, I now have the results displayed in my console. Here are some images related to the REST API I am consuming: https://i.sstatic.net/Nv7F7.png https://i.sstatic.net/OXhUg.png However, whe ...

Transfer the button value from a for loop to a modal in Django using Bootstrap

In my search for a solution to this issue, I have come across numerous discussions where the use of javascript, ajax, and other unfamiliar elements is prevalent... Within my list called movies, there are collections of movies with all their details. I am ...

Stop HTML Select/Option from resetting following jQuery AJAX request

Something strange is happening. Here's the problem I'm facing. In my online application, there are three tabs where users can input and view data - List, Time Preference, and Search Results. In the Time Preference tab, users can choose from a se ...

Establishing a jQuery extension

Reviewing some code on our website led me to this particular snippet: <script> (function (a) { _q = function () { return a; }; $ = function (f) { typeof f === 'function' && a.push(arguments); return $; }; ...

What is the best way to display form input fields depending on the selected value?

I've been struggling with a seemingly simple issue that I can't seem to find the right solution for, even after scouring Google. I have a form field for input and a select field with various values, including an "Other" option. Here's what ...

Troubles with Bootstrap's column functionality causing issues

Trying to create a menu using Bootstrap, but experiencing issues with the 'col' class not working correctly. Here is the sample HTML code provided: <div class="logo col"> <a href="index.html"><img src="C ...

Vertical tabs in Bootstrap display content when hovered over

I have implemented some tabs using Bootstrap and I want to show these tabs when hovering over them. Here is the link to view the tabs: https://jsfiddle.net/uzfxmrs3/ Below is the HTML code for the tabs: <div class="d-flex align-items-start respon ...

Guide on syncing Bootstrap 4 sliders using a single set of controls

Is it possible to synchronize a bootstrap 4 carousel with controls to a carousel without any controls? 1) When the control arrows are clicked, both carousels will slide simultaneously. 2) Hovering over either carousel will pause both carousels from slidi ...

Difficulty in adjusting the height of the popover menu that appears when using the Select Validator in Material UI

I am having trouble adjusting the height of a popover that emerges from a select validator form in Material UI. Despite attempting various methods, including adding the following CSS to the main class: '& .MuiPopover-paper': { height: &apos ...

The issue with the smooth scrolling feature in next/link has not been resolved

I am currently facing an issue where smooth scrolling is not working when using next/Link, but it works perfectly fine with anchor tags. However, the downside of using anchor tags is that the page reloads each time, whereas next/link does not reload the pa ...