Guide for reducing the size of the menu upon hovering over a link with jquery

I have a code that I'm using and I want to make the tabs in the navigation bar shrink when I hover over them, similar to how it works on apple.com. When you click on the search bar on Apple's site, the other tabs shrink. How can I implement this feature in my code?

Here's the link to my code on jsfiddle

HTML:

<div id="wrapper">
    <nav id="mainnav">
        <ol>
            <li class="home"><a href="http://www.domain.com"></a></li>
            <li class="news"><a href="http://www.domain.com/p/">News</a></li>
            <li class="photos"><a href="http://www.domain.com/channels/s/">Photos</a> </li>
            <li class="biography"><a href="http://www.domain.com/e/">Biography</a></li>
        </ol>
    </nav>
</div>

CSS:

div#wrapper{
width:990px;
height:auto;
margin:0 auto;

font:15px Arial,Verdana,Helvetica,sans-serif;

}
div#wrapper #mainnav{
width:100%;
height:40px;

border-bottom:1px solid #c4c4c4;
float:left;
clear:both;
background-color: #5b5b5b;
background-image: -moz-linear-gradient(#5b5b5b,#4d4d4d,#3f3f3f); 
background-image: -webkit-linear-gradient(#5b5b5b,#4d4d4d,#3f3f3f); 
background-image: -o-linear-gradient(#5b5b5b,#4d4d4d,#3f3f3f);
background-image: -ms-linear-gradient(#5b5b5b,#4d4d4d,#3f3f3f);
background-image: linear-gradient(#5b5b5b,#4d4d4d,#3f3f3f);
}

Answer №1

For achieving a slow-motion effect similar to Apple's, consider using CSS3 instead of jQuery.

Utilize CSS3 transition properties:

transition: width 2s;
-moz-transition: width 2s; /* Firefox 4 */
-webkit-transition: width 2s; /* Safari and Chrome */
-o-transition: width 2s; /* Opera */

If you want a design similar to apple.com, you can explore this or this as well.

Check out the demo for more information.

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

A guide on dynamically sending data to a PHP script when an input is changed and displaying the results in a

I am trying to implement a feature where the data inputted into a text field is sent to posttothis.php and then the result is displayed in a content div. However, I am encountering difficulties in making it work. testscript.html <html> <head> ...

PHP not receiving POST information from $.ajax call

My JavaScript triggers a POST method when the datepicker loses focus, calling the script rent-fetch-pick-up-point.php. However, the PHP script gets stuck at the if-statement because it's not receiving the POST data. The datepicker is associated with a ...

Issues with sending POST requests using jQuery AJAX in Chrome mobile

I have encountered a strange issue where a JQuery POST request works fine in mobile safari, desktop safari, and desktop chrome, but fails on chrome for ios. Here is the ajax request code that I am using: $.ajax({ url: '/data', cache: false, ...

Adding options to a dropdown menu using jQuery and Ajax technique

After retrieving data from an Ajax call and attempting to append option values to a dropdown generated in jQuery, it doesn't seem to be working as expected. Here is the code snippet: $(document).on('focusout', '.generate', functio ...

Utilizing Node.js to dynamically inject variables in SASS compilation

I am currently working on an application where I need to dynamically compile SASS before rendering it on the client side (a caching system is in the works, so no worries there). At the moment, my tool of choice is node-sass and so far, everything is runnin ...

How can we trigger a function once an ajax request has finished, without directly interacting with the ajax

I am facing a challenge where I need to trigger a JS function after an ajax call is completed, specifically when filtering posts in WordPress. The issue lies in the fact that the ajax filter tool in use is part of a WordPress plugin that cannot be modified ...

Avoid the problem of animations triggering twice when clicking

Hey there, I am facing an issue with my slider. If you could take a look at this website , you will notice that after clicking on the arrows, the slider behaves asynchronously. It changes speed rapidly at times and then slows down, repeating this pattern ...

Utilize the Sed command to manipulate the input stream by substituting all occurrences of HTML <i> tags with <em> tags

I am attempting to create a regex with the sed command in order to process the input stream and replace all HTML tags with em tags. For example: This is <i id="x">emphasized text</i> and <i>so is this</i>. should be replaced by Thi ...

Determine the total count of files in queue with Uploadify prior to initiating the upload process

When I specify auto: false in the uploadify settings, the upload process will only start when the submit button is clicked. Once the onQueueComplete event is triggered, the form will be submitted. However, if no files are selected, the onQueueComplete even ...

Resizing Images Responsively Using Bootstrap

I'm working on specifying image sizes for different screen sizes. I'm wondering if there are any specific Bootstrap classes that only work at certain screen sizes. If so, it would be great because then I could use something like <img class = " ...

Can React JSX and non-JSX components be combined in a single project?

I'm currently faced with a question: If I have a parent component in JSX but need to include an HTML tag like <i class="fa fa-window-maximize" aria-hidden="true"></i>, which is not supported by React JSX (correct me if I'm wrong), can ...

Utilizing window.matchMedia in Javascript to retain user selections during page transitions

I am encountering difficulties with the prefers-color-scheme feature and the logic I am attempting to implement. Specifically, I have a toggle on my website that allows users to override their preferred color scheme (black or light mode). However, I am fac ...

Tips for making the text input smaller in a datepicker

https://i.sstatic.net/fuECu.png Is there a way to reduce the width of a datepicker while using Bootstrap? It's taking up too much space in my browser window. Below is the code snippet I am using for this functionality. <!---DatePicker ----> ...

Performing a JQuery Ajax request to post data and maintain current page displayed

How can I ensure that my request remains on the second page after data is posted from the first page? $.ajax({ cache: false, url: base_path + '/second.php', type: 'post', ...

Discover the methods for accessing an array of IDs by implementing an event trigger in conjunction with checkboxes

Can you assist me with a dilemma I'm facing? I've developed a static form containing numerous checkboxes and checklists. My challenge arises when trying to integrate a JavaScript code that automatically selects subcategories when parent checkboxe ...

When switching windows or tabs, the user interface of the browser extension vanishes

As someone who is new to web application development and browser extension creation, I have encountered a challenge with my browser extension. When the extension popup is open and I switch browser windows, the UI (popup.html) disappears. It reappears whe ...

Problematic PHP/AJAX: How come my getAttribute function is only selecting the initial line within the foreach loop?

My goal here is to display a list of users, each with a button that sends unique IDs to the database. The issue I'm facing is that the code only works for the first user in the list and not the rest. I suspect this is because every list item has the s ...

Display PHP array information in an HTML table

I am facing an issue with an array that contains a record set generated by the CodeIgniter model. When attempting to display these records in an HTML table using my view, the layout is not rendering correctly. Here is a snippet of my view: <html> & ...

Resize images smoothly without disrupting the anchor scrolling

I have created a website with the following design: (Caution: The site is built using AngularJS on a server that may not serve it correctly - please visit directly instead of using browser reload.) However, I am facing two conflicting requirements... ...

Python Selenium Webdriver: Dealing with the NoSuchElementException

I've encountered a strange situation while using Selenium Webdriver for Python on the Chrome browser. My goal is to extract information from Pipedrive, where I can successfully log in and search for a specific lead on the webpage. However, when I atte ...