Steps to create a button that moves along with a div slider using toggle functionality

I have successfully created a navbar that toggles when a button is clicked. However, the button remains fixed in one position and I would like it to move along with the sliding navbar. How can I achieve this?

$(document).ready(function() {
  $("#flip").click(function() {
    $("#panel").slideToggle("slow");
  });
});
.main_menu {
  position: fixed;
  top: 0;
  background-color: #358ef3;
  height: 9rem;
  width: 100%;
}

.wideScreen {
  margin-top: -0.625rem;
  width: 4rem;
  height: 1rem;
  position: fixed;
  top: 9rem;
  left: 0;
}

.wideScreen>button {
  width: 100%;
  height: 100%;
}

.wideScreen>button>img {
  width: 100%;
  height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="main_menu" id="panel">
  <form class="" action="index.html" method="post">
    <div class="slidecontainer">
      <h2>Bac+: <span id="output"></span></h2>
      <label for="myRange"></label><input type="range" min="1" max="8" value="0" class="slider" id="myRange">
    </div>
  </form>
</div>
<div class="wideScreen">
  <button id="flip">
    </button>
</div>

Answer №1

Is there a specific reason why the button cannot be contained within the header element?

$(document).ready(function() {
    $("#flip").click(function() {
        $("#panel-inner").slideToggle("slow");
    });
});
body {
    padding: 0;
    margin: 0;
}

#panel {
    position: fixed;
    top: 0;
    width: 100%;
}

.main_menu {
    background-color: #358ef3;
    height: 9rem;
    overflow: hidden;
}

.wideScreen {
    width: 4rem;
    height: 1rem;
}

.wideScreen>button {
    width: 100%;
    height: 100%;
}

.wideScreen>button>img {
    width: 100%;
    height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="panel">
    <div id="panel-inner" class="main_menu">
        <form class="" action="index.html" method="post">
            <div class="slidecontainer">
                <h2>Bac+: <span id="output"></span></h2>
                <label for="myRange"></label>
                <input type="range" min="1" max="8" value="0" class="slider" id="myRange">
            </div>
        </form>
    </div>

    <div class="wideScreen">
        <button id="flip">
        </button>
    </div>
</div>

Answer №2

Modify the CSS rules below

.wideScreen {
  margin-top: -0.625rem;
  width: 4rem;
  height: 1rem;
  position: fixed;
  top: 9rem;
  left: 0;
}

to become

.wideScreen {
  margin-top: -0.625rem;
  width: 4rem;
  height: 1rem;
 top: 9rem;
  left: 0;
}

The issue arises from the fixed positioning.

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

Guide to making a sliding animation appear when hovering over a menu using jQuery

I have noticed a common feature on many websites, but I am unsure of how to explain it. At times, there are sliding elements in the navigation, like an arrow under menu items that moves when the user hovers over different links. Here is an example of a s ...

The table's width exceeds the appropriate size

Take a look at the code snippet below <%-- Document : index Created on : Feb 7, 2014, 1:03:15 PM --%> <%@page import="java.util.Map"%> <%@page import="java.util.Iterator"%> <%@page import="analyzer.DataHolder"%> <%@p ...

Ways to conceal a primary page section upon clicking a different tab

I am currently implementing the w3schools HOW TO - tabs feature on my website to create tabbed navigation. However, I'm running into an issue where clicking on tabs other than 'Home' still displays the 'Home' content along with the ...

What could be causing the jQueryUI dialog to malfunction in IE9?

The code provided above successfully creates a jQueryUI modal popup dialog in various browsers such as Firefox, Chrome, and Opera. However, it encounters issues when running on Internet Explorer 9: <html><head> <link rel="stylesheet" href= ...

Ways to validate the present date and time using Jquery

Is there a method in Jquery to retrieve the current date and time? ...

What is causing the align content property to not function as expected in this situation?

Is it expected for the flex items of the .center-section-container to be closer together when using this property? They do not seem to be affected at all. I have applied flex wrap so the items are now in different lines but too far away from each other, I ...

Extracting text using Python and Selenium

Having trouble extracting text from HTML using Selenium and Python innerHTML <span data-select="" data-selected="Selected" data-deselect="Press enter to remove" class="multiselect__option"><span>ONE</span></span> <!----> ...

Unable to alter background color of checkbox with jQuery slide toggle

I've been working on changing the background colour of the toggle button to green when it's turned on. I feel like I've followed all the correct steps, but for some reason, the background just stays grey. Can anyone point out what might be ...

Getting Checkbox Values with Laravel and jQuery

I am facing an issue where I am only able to retrieve one value from checkboxes in jQuery, even though multiple checkboxes have different values. Here is the code snippet: <form method="post"> @foreach($services as $service) ...

Setting a fixed width for the body element results in alignment problems

I'm struggling with aligning divs properly on my HTML page that has a tab using CSS and jQuery. Whenever I try to set a fixed width for the body or main container, everything goes out of place... How can I ensure that the body has a minimum fixed widt ...

Using jQuery: When the API has loaded successfully, execute the specified function

As I dive into working with a search flight API, my goal is to configure some settings when the API loads. Below is the code snippet for loading the API: skyscanner.load('snippets', '1'); function main(){ var snippet=new skysc ...

The collision function is currently not functioning properly, causing a hindrance in movement. There are no other codes restricting movement

const rightPressed = false; const leftPressed = false; const upPressed = false; const downPressed = false; const players = []; players[0] = new victim(1234); const arrayw = 50; const arrayh = 50; const canvas = document.getElementById("myCanvas"); const ...

Pause after applying the "scroll" animation to an element located close to the bottom of the webpage

On my webpage, I have implemented a feature where a downward pointing arrow inside a circle, located just above the fold, indicates there is more content below. When this arrow is clicked, jQuery triggers an animated scroll to the bottom of the page and th ...

Modify the displayed text according to the content of the input field in HTML

I need to update the value of an <h3> tag based on user input in an input field. Here is my current code snippet: <input id="Medication" name="Medication" size="50" type="text" value=""> <script> $(document).ready(function () { $(&apos ...

What steps should I take to execute a task during input checkout?

Check out my code below: $(document).on('checkout', 'input', function(){ alert('input is not focused anymore'); }) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <i ...

Exploring how to utilize AJAX for data filtering within the Laravel framework has piqued

The current controller is returning a value even when the fields are empty. I need to display a message if all the fields are empty. Controller public function filterSearch(Request $request){ $obj = (new VaccinationInfo)->newQuery(); if($req ...

Obtain Phonegap Build CLI-5.2.0 and Close Directly from a Web Application

Struggling with integrating window open calls in my app using inappbrowser. Essentially, I am utilizing phonegap to wrap a mobile skinned CMS site with special app functionalities. Here is the snippet from index.html where I am deploying inappbrowser (wit ...

Transferring an array between jQuery and PHP and vice versa

When users select categories from a list of project options, the div below should update to display projects that match those categories. However, despite following instructions from a similar Stack Overflow post on sending arrays with Ajax to PHP scripts, ...

To ensure that the first three digits of a phone number are not zeros, you can implement a JavaScript function to validate the input

I've been working on validating a phone number using JavaScript, but I've hit a roadblock. I need to ensure that the area code (first 3 numbers in 999) cannot be all zeros (0). While I know how to create the desired format (like xxx-xxx-xxxx), ...

What is the best way to access the id attribute of a <td> element within a <tr> using jQuery?

Can someone assist me with this issue? Is there a way to get the ID of the first or second td element instead of using a loop? Here is an example: "<tr class='test_point' id="+fileName+"><td><img src='"+ROOT_PATH+"/assets/d ...