Is there a way to adjust the width and create the illusion that the div is sliding in from off screen?

I successfully animated a side navigation menu to slide in from the left of the screen. The animation is working perfectly, however, I had to set the div's width to 0px in order for it to appear as though it's sliding in from off-screen.

If I change the div's width to 200px, it displays on screen at 200px wide before widening to 400px after the animation completes.

How can I keep the div at a fixed width of 200px both during and after the animation?

For a demonstration, please refer to this jfiddle example: http://jsfiddle.net/kYRbJ/1/

Thank you

Answer №1

Here is a suggestion to try:

nav#cmNav{
position:fixed;top:0;left:0;
left:-200px;
height:100%;
width : 200px;
background-color:#323233;

-moz-box-shadow:    inset  0 0  #000000;
-webkit-box-shadow: inset  0  #000000;
box-shadow:         inset  -10px 0 10px -5px  #000000;

}

$(document).ready(function(){

    $("#cmNav").animate({left: 0}, 1000);


});

Answer №2

Here's a quick solution:

VIEW DEMO

$(document).ready(function(){
    $("#cmNav").find('*').css('width','200px').end().animate({width: 200}, 1000);
});

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

Generate a separate div in an HTML file for each item listed in a JSON document

I have a JSON file structured like this: { "text": "HelloWorld", "id&quo;t: "1", }, { "text": "HelloMoon", "id": "2", } Now, I want to generate a <div> in my HTML for ...

Accessing the selected value from a drop-down list in a Window.Open using the MVC model

Within my MVC View, there is a form containing a DropDownList element: @Html.DropDownList("ddlAbb" , new List<SelectListItem>(){ new SelectListItem { Selected = true, Text = "All", Value = "-1"}, new SelectListItem { ...

The onClick event in ReactJs appears to be ineffective when used with a button HTML element

Can someone help me troubleshoot this issue in my ReactJs app? import React from 'react' import '../../../assets/styles/authentication/login.css' import '../../../assets/bootstrap/css/bootstrap.min.css' import { login } fro ...

How to use Laravel to upload images using Ajax

My database table structure for users is as follows: id (integer) firstname (string) lastName (string) email (string) login (string) password (string) image (text) I want to be able to insert an image along with the user data using Ajax and jQuery. How ...

Choosing a CSS selector for a class that does not have a specific ID

Looking for a way to select all elements with the class .tab-pane except for those with the id #home. I attempted using .tab-pane:not#home{...}, but it proved unsuccessful. Any ideas on how to achieve this? Sample HTML <div id="home" class="tab-pan ...

The utilization of the jquery.form.js plugin is resulting in my form being submitted twice

In order to enable Ajax file uploads in my ASP.Net MVC project, I am utilizing the jquery plugin known as "jquery.form.js" (http://malsup.com/jquery/form/#getting-started). However, I am encountering an issue where the controller action responsible for han ...

Mouseover function ceases to function once an element is dropped

After referencing this discussion, I successfully managed to drag items from one scroll overflow to another. However, the issue arises when these items (or their clones) are in the other scroll overflow as they do not respond to .mouseover(). The goal is ...

The trio of Angular, jQuery, and Chrome extensions is a powerful

I'm currently working on developing a Chrome extension that can alter the content of a specific website. However, since I don't have access to the source code of the website, I need to make these modifications using JavaScript. The goal is to ma ...

Extract ID for Bootstrap modal display

In my project, I am using a bootstrap modal that displays various strings. The challenge I am facing involves a loop of cards, each with a distinct 'id'. When triggering the modal, I want to show the corresponding id inside the modal itself, whic ...

"Emphasizing the Html.ActionLink menu for improved user navigation and

Currently, I am facing an issue with my menu. I want to clear previously visited links while keeping the current one styled as a:visited in CSS. Although I have attempted to achieve this, unfortunately, the code is not functioning properly. Here is what I ...

Display a modal using jQuery, PHP, and Ajax to verify if a user is

Using a combination of jQuery, PHP, and Ajax, I am able to check if a user is logged in or not. JavaScript: jQuery(document).ready(function() { setInterval(function() { jQuery.ajax({ url: 'chkLoggedin.php', type: 'POST', ...

Formulate a multi-line string using a collection in React's JavaScript framework

I'm working on a React function that involves a set and I need to update an HTML element using the data from this set. Below is an example of my code: const updateElement = (mySet) => { document.getElementById('myId').innerHTML = Arra ...

Leveraging AJAX requests for database connectivity in CodeIgniter

I have encountered an issue with a script (applications/view/pages/home.php) that utilizes an AJAX request to fetch and display the content of another script (referred to as scheduler.php). The scheduler file contains dynamically modified HTML based on a p ...

Tips for extracting text content that is not within an HTML element

Looking to extract data from this particular webpage: The information I'm interested in scraping includes Product Sku, Price, and List Price. I've successfully scraped the Price but I'm encountering issues with the other two, particularly t ...

Is there a way to eliminate the shadow effect on a specific part of a material-ui AppBar?

I want to remove the shadow that appears on the navbar when it overlaps with the sidebar. https://i.sstatic.net/eHh0u.png Currently, I am using Material-UI's AppBar component for my NavBar. export default function NavBar() { return ( <div&g ...

Guidelines for retrieving a class name using jQuery when hovering over a div

I need assistance in fetching the class name by hovering over a div. Both divs have the same id but slightly different class names. Here is an example: <div id="1-someid" class="1-example-class border cz"> ...more elements go here.... </div> ...

Images for the background of the table header and sorting icons

Currently, I am utilizing jquery.tablesorter for table sorting functionality. However, I have a desire to apply a pattern to my table headers using a background-image. Unfortunately, when I do so, the .headerSortUp and .headerSortDown classes on the sorted ...

Is it possible to dynamically set the maximumSelectionLength in a select2 dropdown?

In my HTML, I have two select elements. One is for multiple selection of items in a dropdown and the other is for adding tags. If the number of selected items is 3, then users should only be allowed to add 3 tags - no more and no less. $(".js-example-b ...

selectors that seem to be floating

I attempted to line up certain selectors horizontally on the same line using float:left. However, it did not work as expected! Could someone please assist me with this issue? http://jsfiddle.net/6YKhT/ ...

How can we stop the navigation submenus (ULs) from appearing as if they are floating?

I've created a navigation bar with an unordered list consisting of smaller unordered lists, each with the class "subnav". When the screen is small, the navigation collapses and the menus stack on top of each other. I want the navigation to maintain i ...