Animated slide-out menu with icon using jQuery

I am in the process of creating a menu using CSS and jQuery that will display an icon for each menu item. When a user hovers over a menu item for 0.5 seconds, I want it to slide slowly to the left to show the name of the menu. This is similar to what you can see in this plugin. I have set up a jsfiddle here for reference. As I am still new to front-end web development, I have hit a roadblock. Any assistance would be greatly appreciated. Thank you.

<div id="menuDiv">
    <a href="#" id="home">App Home</a>
    <a href="#" id="help">Help</a>
    <a href="#" id="photos">See photos</a>
    <a href="#" id="mail">Send a Mail</a>
</div>

Answer №1

I believe there are some adjustments needed in your code

JSFiddle

HTML:

<div id="menuDiv">
    <a href="#" id="home">
        <span class="menuIcon"></span>
        <span class="menuText">App Home</span>
    </a>
    <a href="#" id="help">
        <span class="menuIcon"></span>
        <span class="menuText">Help</span>
    </a>
    <a href="#" id="photos">
        <span class="menuIcon"></span>
        <span class="menuText">See photos</span>
    </a>
    <a href="#" id="mail">
        <span class="menuIcon"></span>
        <span class="menuText">Mail</span>
    </a>
</div>



CSS:

body{
    background-color: #E2E2E2;
}

*{
    padding :0px;
    margin: 0px;
}

#menuDiv{
    padding:5px;
    background: yellow;
    display: inline-block;
    float: right;
}

#menuDiv a {

    background: pink;
    width: 48px;
    height: 48px;
    float: right;
    overflow: hidden;
    position: relative;
    -webkit-transition: all 0.5s linear;
    transition: all 0.5s linear;
}

#menuDiv .menuIcon {

    width: 48px;
    height: 48px;
    float: left;
    -webkit-transition: all 0.5s linear;
    transition: all 0.5s linear;
}

#menuDiv a#home .menuIcon {
    background: url("http://3.ii.gl/e95k6KER.png") no-repeat left center;
}

#menuDiv a#help .menuIcon {
    background: url("http://3.ii.gl/E-E-GRnJt.png") no-repeat left center;
}

#menuDiv a#photos .menuIcon {
    background: url("http://3.ii.gl/saNZbewlk.png") no-repeat left center;
}

#menuDiv a#mail .menuIcon {
    background: url("http://3.ii.gl/eOns-8L.png") no-repeat left center;
}

#menuDiv .menuText {
    width: 100px;
    height: 48px;
    line-height: 48px;
    position: absolute;
    padding-left: 16px;
    text-decoration: none;
    left: 48px;
}

#menuDiv a:hover {
    width: 148px;
}

#menuDiv a:hover .menuIcon {
    -webkit-transform: rotate(-1440deg);
    transform: rotate(-1440deg);
}

Answer №2

To achieve this effect without using JavaScript, you can utilize CSS3 transition delay. Here is an example:

body {
background-color: #E2E2E2;
}
* {
padding: 0px;
margin: 0px;
}
#menuDiv {
padding: 5px;
background: yellow;
display: inline-block;
}

#menuDiv a {
display: inline-block;
float: left;
overflow: hidden;
width: 48px;
line-height: 48px; 
white-space: nowrap; 
margin: 8px; 
text-indent: 50px;

-webkit-transition-delay: .5s;
-moz-transition-delay: .5s;
-o-transition-delay: .5s;
transition-delay: .5s;

-webkit-transition-duration: 1s;
-moz-transition-duration: 1s;
-o-transition-duration: 1s;
transition-duration: 1s;

-webkit-transition-property: text-indent;
-moz-transition-property: text-indent;
-o-transition-property: text-indent;
transition-property: text-indent;
}
#menuDiv a:hover {
text-indent: 0;
}

#menuDiv a#home { background: pink url("http://3.ii.gl/e95k6KER.png") no-repeat left center;}

#menuDiv a#help { background: pink url("http://3.ii.gl/E-E-GRnJt.png") no-repeat left center;}
#menuDiv a#photos { background: pink url("http://3.ii.gl/saNZbewlk.png") no-repeat left center;}
#menuDiv a#mail { background: pink url("http://3.ii.gl/eOns-8L.png") no-repeat left center;}
<div id="menuDiv">
<a href="#" id="home">App Home</a>
<a href="#" id="help">Help</a>
<a href="#" id="photos">See photos</a>
<a href="#" id="mail">Send a Mail</a>
</div>

This code snippet animates the text-indent property. Feel free to customize it to fit your needs.

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

Utilizing the Bootstrap portfolio section, I aim to eliminate the 'ALL' tab and ensure a category is selected

Currently, I am utilizing this template If you scroll down to the WORK section, you will find the portfolio section which is filterable. The default selected option is "ALL," displaying all items. However, I would like to remove this and activate a diffe ...

Tips for effectively redirecting multiple links on a website

Can anyone advise me on how to redirect certain HTML pages to corresponding PHP pages? For instance, if a user lands on www.example.com/sample.html from another website, I want them to automatically be redirected to www.example.com/sample.php without seei ...

Ways to eliminate the Horizontal scroll bar

Currently, I am in the process of transforming a Static Page into a Responsive Page. However, when I resize my page to a lower width, I notice that a horizontal scroll-bar appears along with some margins at the bottom and right side of the last div/Footer. ...

capable of concentrating but unable to enter text into input field using jquery

I have a set of five rows, each containing three columns of text boxes, along with a single text area. When tabbing from the third column in a row, the focus should shift to the text area, and then tabbing from the text area should move to the next row of ...

Input form with multiple fields. Automatically display or hide labels based on whether each field is populated or empty

I am attempting to create a form where the placeholders move to the top of the input when it is focused or filled. However, I have encountered an issue with having multiple inputs on the same page. Currently, my JavaScript code affects all inputs on the pa ...

Modify the :after property of an element using jQuery

Is there a different approach I can take to achieve this desired outcome? Currently, the code snippet below is not yielding the expected results. $('.child_flyout:after').css({'top':'20px'}); Are there any alternative method ...

JavaScript not functioning properly with HTML loaded via .load()

I'm facing a perplexing dilemma: My issue revolves around this JS code: EDIT updated JS $(".img-thumb").on("click", function(){ // displaying the same behavior as .click() thumbID = $(this).attr("id"); console.log(thumbID); $(".gal-act" ...

Optimize the layout with Grid CSS to allow the last two items to dynamically occupy

I've been working on a layout that looks like this: X X X X X X X X A B Currently, I have used grid-template-columns: repeat(4, 1fr); to define the columns. However, what I actually want is for the last two items to take up the full width of the rem ...

Problem with the transform attribute in CSS

Having trouble rotating a div within another div. I tried using the transform property but it's not working as expected. I heard about another method which involves using :before pseudo-element, but I'm not sure what's wrong with that either ...

Enhance the visual appeal of incoming data using Angular Material's dynamic styling feature

Is it possible to enhance the text with some CSS styling to make each item stand out like in this example: https://i.stack.imgur.com/kSyZE.png I prefer not to include a cross button or provide users with the option to add tags. The data is coming from a R ...

Resolving the issue: "Unable to destructure the 'Title' property of 'fac' as it is undefined" in React JS

I'm facing an issue with react-bootstrap mapping in my component whereby I encounter the following error: Cannot destructure property 'Title' of 'fac' as it is undefined. It seems like there's an error when trying to de ...

PHP - WebCalendar - Show or Hide Field According to Selected Item in Dropdown List

Working with the WebCalendar app found at to make some personalized adjustments to how extra fields function. I've set up two additional fields: one is a dropdown list of counties, and the other is a text field. Within the dropdown list, there is an ...

Transform jQuery code to its equivalent in vanilla JavaScript

While I am proficient in using jQuery, my knowledge of pure JavaScript is somewhat limited. Below is the jQuery code that I have been working with: $(document).ready(function() { $.get('http://jsonip.com/', function(r){ var ip_addre ...

Modifying Checkbox BorderWidth in Material UI v5

Seeking assistance with adjusting the checkbox border width in Material UI v5. I currently have a custom checkbox and would like to remove the border width. Despite trying numerous solutions, I have been unsuccessful so far. checkbox <Checkbox de ...

Is there a way for me to position my arrow beside the header while still keeping the toggle function intact?

Can anyone assist me in positioning my arrow next to the header text, which I toggle on click? I attempted placing the arrow <div> into the H1 tag, but then the toggle function stops working. Any help would be greatly appreciated! Please includ ...

Include a search button within the search box of the Custom Search Engine

Can anyone help me with adding a search button to my HTML code? I've tried implementing it, but when I try to search something on a website like YouTube, the results show up without displaying my search query. How can I fix this issue and what changes ...

Excessive form inputs extend beyond the modal when utilizing Bootstrap 3

Having an issue loading a modal with Angular and populating it with a template. The main problem I'm facing is that the inputs are extending beyond the boundaries of the modal - attached below is a screenshot illustrating the problem: Below is the c ...

Efficiently transferring time values from dynamically created list items to an input box using JavaScript

Is there a way to store a dynamically generated time value from an li element into an input box using JavaScript? I have a basic timer functionality on my website that includes starting, stopping, pausing, taking time snaps, and resetting them. These time ...

Incorporating JavaScript into a Rails Application

When I click on a link "link_to" in my rails app, I am attempting to trigger a JS file. To confirm that the asset pipeline is functioning correctly, I conducted a test with: $(document).ready(function() { alert("test"); }); The alert successfully po ...

Assist me in temporarily altering the color of menu items in a sequential manner upon the page's loading

Currently, I'm working on a website that features a subtle dark grey menu at the top of every page. The menu is built using HTML and CSS with a list structure. To highlight the corresponding menu item based on the current page, I am utilizing the ID a ...