Sticky sidebar panel featuring a stationary content block

I have a sidebar that is set to position:fixed; and overflow:auto;, causing the scrolling to occur within the fixed element.

When the sidebar is activated, the element remains static on the page without any movement.

My goal: I am looking to keep the .super-image-thumb fixed inside the scrolling element so that the thumbnails at the top remain fixed when scrolling occurs.

I have attempted a javascript solution but it still does not work as expected. Any suggestions?

Answer №1

It's a common issue that Fixed inside Fixed can be problematic. Instead of using 'top', let's try a different approach: bottom: http://jsfiddle.net/po29jx04/

function adjustPosition() {
  $('.floating-div').css({
      'bottom': $('.content-wrapper').scrollBottom()+'px'
    });
}
$('.content-wrapper').scroll(adjustPosition);
adjustPosition();

Answer №2

Adding Javascript to the mix will only serve to complicate things.

The key here is CSS, specifically utilizing position: fixed or absolute, which is always relative to the first ancestor with position: relative.

I recommend removing the jQuery code and incorporating the following CSS:

.slide-content {
    position:relative;
}
.super-image-thumb {
    position:fixed;
    background: #FFF;
    top:0;
    width:100%;
    z-index: 2;
}

.main-image-container {
    position:absolute;
    top:85px;
    z-index: 0;
}

You can view the implementation in this jsfiddle

Answer №3

It appears that using transitions and position: fixed simultaneously may not be fully supported in all browsers. Removing either of them resolves the issue. For potential solutions, you can refer to this resource on Stack Overflow.

I have created a code snippet without transitions and removed the JavaScript part as it seems unnecessary. Instead, I propose a CSS-only solution. While it is not completely finalized and requires some additional adjustments, the approach for addressing the problem should be clear.

.sliding-panel-content {
    z-index: 1204;
}
.middle-content {
    border-left: 1px solid #ddd;
    border-right: 1px solid #ddd;
}

.middle-content {
    position: fixed;
    left: 8%;
    top: auto;
    width: 85%;
}

.sliding-panel-content {
    overflow: auto;
    top: 0;
    bottom: 0;
    height: 100%;
    background-color: #fff;
    -webkit-overflow-scrolling: touch;
}

.super-image-thumb {
    position: fixed;
    top: 10px;
}

.main-image-container {
    margin-top: 100px;   // should be same as thumb height
}

 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<div class="js-menu sliding-panel-content middle-content is-visible">
  <span class="closeBtn sliding-panel-close"></span>
  <div class="slide-content">


    <div class="super-image-thumb">
      <div id="product-gallery-super">
        <a href="#" class="product-gallery">
          <img src="http://placehold.it/61x79?text=1">
        </a>
        <a href="#" class="product-gallery">
          <img src="http://placehold.it/61x79?text=2">
        </a>
        <a href="#" class="product-gallery">
          <img src="http://placehold.it/61x79?text=3">
        </a>
        <a href="#" class="product-gallery">
          <img src="http://placehold.it/61x79?text=4">
        </a>        
        <a href="#" class="product-gallery">
          <img src="http://placehold.it/61x79?text=5">
        </a>
        <a href="#" class="product-gallery">
          <img src="http://placehold.it/61x79?text=6">
        </a>
      </div>
    </div>

    <div class="main-image-container">
      <img class="main-image" src="http://placehold.it/500x2045">

      <button name="prev" id="super-prev">Prev</button>
      <button name="next" id="super-next">Next</button>
    </div>


  </div>
</div>

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

Not compatible with certain browsers, scrollable wrapper in fullscreen

I am looking to create a unique layout with a fullscreen div on top of a footer. The main element (#wrapper) should have a fullscreen background image and be scrollable to reveal the footer underneath. Check out my code on JSFiddle: https://jsfiddle.net/t ...

Working with jQuery: Creating multiple lightboxes using the same jQuery code

Is there a way to create a universal lightbox with the same code for all lightbox functions on the page using JQuery? $(document).ready(function() { $('.lightbox').click(function() { $('.backdrop, .box').animat ...

Dynamic Bootstrap Popover: Creating interactive popups by dynamically attaching events to buttons

I am looking to implement the Bootstrap Popover module to create a confirmation dialog for a delete action. When a <button> is clicked, instead of immediately executing a function, I want a popup to appear allowing the user to either confirm or dismi ...

Why are the $refs always empty or undefined within Vue components?

I am completely new to working with Vue and I've been attempting to utilize $refs to retrieve some elements within the DOM from a sibling component. My objective is very basic, as I just need to obtain their heights, but I haven't had much succes ...

Button Vote in Bootstrap is unresponsive

I have a voting system implemented on my website using normal CSS buttons, and it works perfectly fine. However, when trying to integrate it with Bootstrap buttons, it seems to not function properly. I am looking to switch to using Bootstrap buttons for t ...

Implementing OAuth2 in a Microservices architecture to establish a user account

In my current setup, I am utilizing a React Application along with a separate Express API. My goal is to allow users to register through my React app. To do this, I believe the oauth2 flows should follow these steps: Prompt the user for information (suc ...

Dynamically parallelizing functions with async and arrays

I have recently integrated the fantastic "async" module by caolan into my Node.js project: Below is a snippet of the code in question: exports.manageComments = function(req, res) { var toDeleteIds = []; var deleteFunctions = []; if (req.body. ...

Binding Data to Arrays in Polymer

I'm currently diving into the world of Polymer. My goal is to connect an array with my user interface in a way that allows for dynamic updates. Each object within the array contains a changing property, and I want my UI to reflect these changes accord ...

Tips for successfully using `cols=""` within a grid container alongside a textarea

It seems that both Chrome and Firefox are not following the cols attribute on textarea elements within a grid container: .grid { display: grid; } textarea:not([cols]) { width: 100%; } <h2>Not in a grid container:</h2> <div> <tex ...

Utilizing node.js as a standalone web server application

I've developed a node.js-based web server (Javascript file) designed to serve a Javascript-integrated web page for controlling immersive sound on mobile devices. The server utilizes native modules for MIDI and pcap communication, along with express fo ...

Issue with Bootstrap contact form functionality in PHP not working

I have experience in coding HTML and PHP, but unfortunately, [email protected] (mail address) is still unable to receive emails from my website (http://cloudsblack.info/) and when I click the submit button, it leads to a blank page (http://cloudsblack.info ...

Top strategy for monitoring a user's advancement in reading different text segments

If you are familiar with zyBooks, I am looking to implement a similar feature where users can track the sections they have read and mark them as completed with a button. However, I am struggling conceptually with determining how best to structure my mongo ...

What steps can I take to stop a browser from triggering a ContextMenu event when a user performs a prolonged touch

While touch events are supported by browsers and may trigger mouse events, in certain industrial settings, it is preferred to handle all touch events as click events. Is there a way to globally disable context menu events generated by the browser? Alternat ...

Problems arising from Jquery append functionality

When using the append method, my inner div is only attaching one WHEAT-COLORED-BOX, whereas when using appendTo, my inner div attaches all the required number of WHEAT-COLORED-BOXES. Therefore, in this case, appendTo gives the correct result while append f ...

Tips for extracting a specific attribute from an array of objects using both react and JavaScript while considering various conditions

I have a set of objects structured like this: const obj_arr = [ { id: '1', jobs: [ { completed: false, id: '11', run: { id: '6&apos ...

Passing data from child to parent in Angular using EventEmitter

I have integrated a child grid component into my Angular application's parent component, and I am facing an issue with emitting data from the child to the parent. Despite using event emitter to transmit the value to the parent, the variable containing ...

Determining the character encoding of a JavaScript source code file

For my German users, I want to display a status message with umlauts (ä/ü/ö) directly in the source file instead of requiring an extra download for messages. However, I'm having trouble defining the encoding for a JS source file. Is there a way si ...

Ways to implement schema.org and JSON-LD for data labeling on a homepage of a website

After reading extensively on utilizing schema.org to mark structured data, I have a couple of questions. Firstly, is it advisable to use json-ld considering that it's relatively new and not fully supported yet? Secondly, how can I implement schema.org ...

Tips and tricks for displaying JSON data in Angular 2.4.10

In my Angular project, I am facing an issue while trying to display specific JSON data instead of the entire JSON object. Scenario 1 : import { Component, OnInit } from '@angular/core'; import { HttpService } from 'app/http.service'; ...

Summon wicket from the non-wicket-component entity

I am currently utilizing js-lib to transform text into a rich-editor, complete with options such as "bold", "italic" and more. The RichEditor also includes an UploadImage button, for which I am able to modify the call-back function: function startUploadi ...