Smoothly transition the neighboring div aside when utilizing jQuery's show function, instead of abruptly revealing it

I have been working on creating a flyout panel mechanism similar to the one used in Microsoft Azure's online portal. The portal has a flyout panel for menus that slide out from left to right when opening a new submenu, with the panel container aligned to the left of the page.

While this setup works well for me, I need my panels to appear on the right side of the screen. I have found a solution, but the issue arises when adding a new flyout panel - it abruptly repositions its neighbor and slides out using the show() function.

Link to Code Example

Essentially, I want the new panel to smoothly ease out its neighbor as it slides into view. I hope this explanation makes sense.

HTML:

<div id="flyoutcontainer" class="parentflyout">
    <div class="childflyout" style="display:block;">
        <button onclick="openNewFlyout('#flyoutcontainer')">OpenNew</button>  
        <button onclick="closePanel('#flyoutcontainer')">Close</button>
    </div>
</div>

CSS

/*Temp*/
body, html{height: 100%;}
.parentflyout{
    height:100%;
}
.childflyout:first-of-type{
    width:200px;
}
.childflyout:nth-of-type(2){
    overflow:hidden;
}
.childflyout{
    border:1px solid black;
    width: 340px;
    float:right;
    height:100%;
    display: none;
}

JQuery

function openNewFlyout(containerid){     
    var newFlyout = $('<div class="childflyout"></div>');
    var appended = $(containerid).prepend(newFlyout);
    newFlyout.show('slide', {direction: 'right'}, 800);
}
function closePanel(containerid){
    $(containerid + ' .childflyout:first-of-type').remove();
}

EDIT:

To clarify further, the red box demonstrates the current "animation" effect, while I am aiming for the smoother transition illustrated in the green box.

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

Answer №1

After delving into the animate function, I devised a successful solution. Rather than

function openNewFlyout(containerid){
    var newFlyout = $('<div class="childflyout"></div>');
    var appended = $(containerid).prepend(newFlyout);
    newFlyout.show('slide', {direction: 'right'}, 800);
}

I required this instead

function openNewFlyout(containerid) {
   var newFlyout = $('<div class="childflyout"></div>');
   var appended = $(containerid).prepend(newFlyout);
   newFlyout.animate({width:'toggle'},350); // This has been altered
}

You can refer to my updated jsfiddle link in the question for the working code.

If Pauli_D wishes to receive credit, they can respond to my inquiry and I will acknowledge their response. Otherwise, I will accept this once it's possible.

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

Positioning an image on the right side of text

I am struggling to align the image to the right side of the text. Despite trying various methods, the image keeps appearing below the text instead of alongside it. Although I believe my code is correct, the desired outcome is not being achieved. To view ...

Is it secure enough for a live website?

Is the method outlined below secure enough to use in a production environment? I am fetching data from a database and displaying it in a graph using Chart.js. My HTML code <div id="canvas-holder"> <canvas id="chart-area2" width="200" height= ...

Ensuring the validity of a file input through AJAX in a form built with Laravel

I am facing an issue with validating an image field in a Laravel form using AJAX. The field always appears to be empty even after selecting a file. How can I use ajax validation to check if the file input is empty or not? Here is the form code: {{ Form:: ...

SoundCloud cross-domain requests fail to work in Safari

I'm struggling to receive a json response when calling SoundCloud's API in Safari. var inputSet={url:setUrl}, clientId={client_id:client_id}; $.getJSON( "https://api.soundcloud.com/resolve.json", $.extend(inputSet, clientId), function( data ...

What advantages does creating a class that can freely float in either direction offer?

Recently, I noticed a common trend on websites like : .left { float: left; } <div class="col two left" /> Is this considered best practice? It goes against the idea of creating classes solely for styling purposes. If we wanted to change the floa ...

Generating an associative array in PHP using AJAX with JQUERY

Seeking assistance for the first time here. I'm struggling to find a suitable title, but it's all I can think of at the moment. I've been working on this for 2 days now and have read so many things that I feel completely lost. I'll try ...

Troubleshooting Bootstrap 4 Scrollspy CSS Selector Problem

As I work on my website, I am attempting to implement a scrollspy with Bootstrap 4. Unfortunately, it seems that the functionality is not working as expected. I suspect that the issue lies within the classes and selectors I have utilized. Interestingly, wh ...

Executing a function upon loading a page triggered by a submitted form

Recently on my index.php page, I implemented a form that posts data into a third-party newsletter system. After the form submission, the page reloads to index.php?mail&. Is there a way to detect when the page is loaded and determine if the form has bee ...

Is there a way to designate whether the <ul> element is displayed horizontally or vertically?

For example: <ul> <li>a</li> <li>b</li> </ul> The default output is: ab But I am looking for: a b Is there a way to achieve this? ...

What is the best way to stop this Jquery slider from moving?

I've been struggling with this issue for what feels like forever, and it's driving me crazy! I have a slider on the homepage that I'm trying to enhance with a "click to pause" feature (and maybe even a click to resume, for good measure). I ...

jQuery fails to function properly when using the .live("keyup") event

Below is the code snippet: $(document).ready(function() { $("#querybox").live("keyup", function(e) { var code = (e.keyCode ? e.keyCode : e.which); if (code == 13) { $("#querybox").blur(); } else { search(document.getElementB ...

Is it possible to highlight the original 'anchor' or position of an element that has been moved using the float property?

Can the XXX be displayed using a CSS trick without the need for an extra HTML element or container? I attempted to use pseudo-elements and translate, but it was unsuccessful. p { background-color: grey; max-width: 200px;} small { float: right; margin-r ...

Initiate callback from within the function

I am currently working on developing my own jQuery function to rearrange rows within a table. So far, the function seems to be working well. However, I am unsure of how to trigger the callback functions that should be configurable in the settings object. ...

Best practices for loading and invoking Javascript in WordPress child themes

After spending countless hours searching for a detailed tutorial on how to properly incorporate Javascript into a WordPress website, I came up empty-handed. Running the Genesis Framework with a child theme on my localhost, I am eager to add a fullscreen b ...

Bootstrap version 5 has a feature where the dropdown menu extends beyond the right side of the screen

I'm facing an issue with the default bootstrap 5 navbar. When I attempt to add a dropdown on the right side, the list of dropdown items extends beyond the screen on the right. You can see the problem here. I've tried the solutions suggested in s ...

Interested in the use of hide().after("") function in jQuery?

Check out some code here: html: <body> <p>This is a paragraph.</p> <button>click me</button> </body> Javascript: $(document).ready(function(){ $("button").click(function(){ $("p").hide().after('<p>h ...

Unable to modify the CSS of a template downloaded for free in a custom CSS file - changes have no impact. What could be the reason behind this

After downloading a free bootstrap template, I attempted to change the style using a custom CSS file. However, the CSS in the template did not adjust as expected. Changing background colors and text colors had no effect. Why isn't this working? Could ...

Responsive columns and fluid Flex row implemented in Bootstrap 4

I am striving to optimize this section for responsiveness. It looks fantastic on larger viewports, but as we start shrinking down, for instance, on a viewport around 930px, I'm facing difficulty in keeping the image perfectly aligned as shown in the i ...

Avoid form submission when the 'enter' key is pressed in Edge, but not in Chrome or Firefox

I'm dealing with an issue in HTML where a 'details' tag is set to open and close when the user presses enter. However, on Edge browser, pressing enter on the 'details' tag actually submits the form. I've been tasked with preve ...

Efficient File Upload Feature Compatible with all Browsers, Including Internet Explorer versions 7, 8, and 9

Can someone assist me with a problem I'm facing? I need a code script that enables multiple file uploading on all browsers. While HTML5 supports Chrome and Mozilla Firefox, it does not support IE. I am looking for a script/jquery solution that works ...