Sliding Toggle: Panel Revealed with Button Slide

Currently, I am working on implementing a jquery slide tab feature. The functionality is working fine on button click. However, I want the button to stick with the panel and slide along with it. At the moment, the button remains fixed while the panel slides as expected.

Here Is FIDDLE

HTML

    <button id="showmenu" type="button" class="feed_btn">Feed Back</button>         
<div class="sidebarmenu">
                  <div class="slide-out-div" style="z-index: 999;">
                      <form  class="generalForm bookingForm" action="#" method="post">
                    <div class="row">
                        <div class="col-sm-12">
                            <label>Name<span>*</span></label>
                            <input type="text" name="Name" class="required" />
                        </div>
                        <div class="col-sm-12 mar_top">
                            <label>Email <span>*</span></label>
                            <input type="text" name="Email" class="required" />

                        </div>
                        <div class="col-sm-12 mar_top">
                            <label>Contact No <span>*</span></label>
                            <input type="text" name="contact_no" class="required" />
                        </div>
                        <div class="col-sm-12 mar_top">
                            <label>Say Few Words<span>*</span></label>
                            <input type="text" name="feedback" class="required" />

                        </div>
                        <div class="col-sm-12">
                            <input type="submit" name="submit" value="Submit" style="background-image:none; padding-left:20px;" />
                        </div>
                    </div>
                </form>
                 </div>


            </div>
            </div>

CSS

    .sidebarmenu{
        position:absolute;
        right:-250px;
        z-index:999999;
    }

JS

    $('#showmenu').click(function() {
        var hidden = $('.sidebarmenu').data('hidden');

        if(hidden){
            $('.sidebarmenu').animate({
                right: '-250px'
            },500)

        } else {
            $('.sidebarmenu').animate({
                right: '0px'
            },500)
        }
        $('.sidebarmenu,.image').data("hidden", !hidden);

        });

Answer №1

To ensure the button moves along with the form, you can add a parent container and move that instead of the form itself. To see a demonstration, check out the demo here

HTML

<div class="panel">
    <button id="showmenu" type="button" class="feed_btn">Feed Back</button>
    <div class="sidebarmenu"> -- place your code here --</div>
</div>

JS

$('#showmenu').click(function () {
    var hidden = $('.sidebarmenu').data('hidden');

    if (hidden) {
        $('.panel').animate({
            marginRight: '-250px'
        }, 500)

    } else {
        $('.panel').animate({
            marginRight: '0px'
        }, 500)
    }
    $('.sidebarmenu,.image').data("hidden", !hidden);

});

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

SpineJS combined with Express

Are there any recommended tutorials or case studies showcasing the integration of SpineJS and Express in applications? I have experimented with both technologies, but am currently facing some challenges. My backend is set up to run Express by using coffee ...

Triggering an event on a checkbox following an AJAX response

My website has 3 different categories, each with a dropdown menu containing various values with checkboxes. When a checkbox is checked, an AJAX request is triggered to fetch a response. The problem I'm facing is that the dropdown menus disappear afte ...

Guide to enabling picklist editing in the specified component within an Angular application

Currently utilizing the p-picklist component and looking to customize the displayed data in the target list span. You can find the source code at: Is there a way to enable editing of the product name within the target list? <p-pickList [source]=&quo ...

Ensuring proper input with JavaScript form validation

Currently, I am working on implementing a basic form validation feature, but it is not functioning as intended. The desired behavior is for the field border to change color to green or red based on its validity, while displaying text indicating whether t ...

What is the reason behind TypeScript rejecting the syntax of checkbox input elements?

When trying to use the following checkbox in TypeScript, I encountered a warning: <input type="checkbox" onClick={(event: React.MouseEvent<HTMLInputElement>) => { setIsTOSAccepted(event.target.checked); }} defaultChecked={ ...

Enhance efficiency with Bootstrap typeahead prefetch capability

Currently, I am utilizing the Bootstrap typeahead API to generate a real-time search feature. The source option is quite useful as it enables an AJAX call to retrieve data from the server. However, I am interested in preloading the source upon page load a ...

I'm curious if there is a configuration option in nodejs that allows for monitoring every ajax call, similar to zend's predispatcher feature

In my current task, I am required to verify every API call for authentication purposes (checking if the API call includes an API key). If the API call contains the API key, then proceed with calling the API and returning its response; otherwise, return an ...

How to Adjust the Padding of Tree Row in GWT?

Have you ever seen a GWT tree before? It sort of resembles the following structure: <div class="gwt-Tree"> <div style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; margin-left: 0px; padding-left: ...

jQuery problem: Unable to access a property that is undefined

After testing my code on JSfiddle, I noticed that it works perfectly. However, when I try to implement it on a webpage with jQuery already loaded in the DOM, I encounter a console error, shown in the screenshot. I am certain that the iframe selector I am ...

Achieving proper layout in Material-UI Autocomplete by splitting long words

Exploring the Material-UI autocomplete feature for the first time has brought some challenges my way. I am working with usernames, which have a specific length limit but could exceed the space available in the autocomplete view. Upon examining the sandbox ...

ReactJS does not recognize the library mentioned

click here to access the pondjs folder inside node-modulesAfter installing pondjs(https://www.npmjs.com/package/pondjs) using npm install pondjs --save in my react application and confirming its presence in package.json, I encountered an issue in App.js. W ...

Is there a way to utilize JavaScript in order to trigger a CSS animation to occur at a designated time during a video

I have a cool animated image element that I want to play at a specific point in time during a video using JavaScript. I'm not sure how to make it happen, but I know the .currentTime property could be the key. My goal is for the animation to only play ...

What is the best way to incorporate interactive columns in DataTables?

I am utilizing jquery datatables to present data. <table class="report-tbl table-bordered" cellspacing="0" width="100%" id="report-tbl"> <thead> <tr> <th></th> ...

In what scenario should I respond with true or false to AJAX, and when is it more appropriate to use the echo function to output "true" or "false

It seems I have managed to confuse myself. I mistakenly believed that when using AJAX to communicate with PHP (like $.post), one had to echo back a "true" or "false" instead of simply returning true or false. I now realize this is not the case, but could ...

I'm curious if it's possible to modify a webpage loaded by HtmlUnit prior to the execution of any javascript code

To begin, I want to elaborate on the reasoning behind my question. My current task involves testing a complex web page using Selenium + HtmlUnit, which triggers various JavaScript scripts. This issue is likely a common one. One specific problem I encount ...

Empty POST request detected in select2 form submission

Looking for some assistance to help steer me in the right direction. My professor is unable to provide guidance. I'm currently struggling with handling POST requests in my form for select2 multiple fields. The issue arises from a Yes/No flag that dete ...

How exactly does this JavaScript code determine the index of the maximum value within an array?

Examining the specific line of code: let largest = arr.reduce((a,v,i) => v > a[1] ? [i,v] : a, [-1,0]); I find this part a, [-1,0] particularly perplexing, as I am unsure of its syntax. How does a function before the comma? ...

The functionality of Express' render/redirect is limited to being triggered only by a submit method within a form

Objective To execute a POST request through a JavaScript method in order to send variable values as parameters. Setup NodeJS Express BodyParser ejs Initial Approach Frontend: <html> <head> <script src='http://ajax.go ...

Ways to access c# session data using jquery and fetch attributes

Within my code, I have a user class which contains an id as integer and a name as string. This class is stored in a session once the user logs in. How can I retrieve the id of the object from this session using jQuery? ...

Identify all elements that possess a specific attribute with a precise value in jQuery, and return either true or false

I'm having a slight issue with jQuery. Below is the code in question: if ($("select[rendelo='" + rendelo + "'][nap='" + nap + "'][napszak='" + napszak + "']").val() == 0) { alert('sth'); ...