Element with a fixed position within an iScroll container

Has anyone encountered an issue with fixing an element with position: fixed inside a big Iscroll page? It seems like the element scrolls along with the content due to the transition imposed by Iscroll.

I'm trying to fix the "FIXTHIS" element, but it doesn't stay fixed in place. Is there a solution to this problem?

Check out the JSFiddle example: https://jsfiddle.net/10amw389/1/

<div id="wrapper">
<div id="scroller">
    <div class="fixthis">FIX THIS</div>
    <ul>
        <li><a href="javascript:myScroll.scrollToElement(document.querySelector('#scroller li:nth-child(10)'))">Scroll to element 10</a></li>
        <li>Pretty row 2</li>
        <li>Pretty row 3</li>
        <li>Pretty row 4</li>
        <li>Pretty row 5</li>
        <li>Pretty row 6</li>
        <li>Pretty row 7</li>
        <li>Pretty row 8</li>
        <li>Pretty row 9</li>
        <li><a href="javascript:myScroll.scrollToElement(document.querySelector('#scroller li:nth-child(25)'), null, null, true)">Center element 25 to screen</a></li>
        <li>Pretty row 11</li>
        <li>Pretty row 12</li>
        <li>Pretty row 13</li>
        <li>Pretty row 14</li>
        <li>Pretty row 15</li>
    </ul>
</div>

JS

var myScroll;

function loaded() {
    myScroll = new IScroll('#wrapper', { mouseWheel: true, click: true, HWCompositing: false });
}

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

loaded();

CSS

.fixthis {
  position: fixed;
  width: 100%;
  text-align: center;
  padding: 25px;
  background: #009BFF;
  color: #FFFFFF;
}

* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

html {
  -ms-touch-action: none;
}

body,ul,li {
  padding: 0;
  margin: 0;
  border: 0;
}

body {
  font-size: 12px;
  font-family: ubuntu, helvetica, arial;
  overflow: hidden; /* this is important to prevent the whole page from bouncing */
}

#wrapper {
  position: absolute;
  z-index: 1;
  top: 45px;
  bottom: 48px;
  left: 0;
  width: 100%;
  background: #ccc;
  overflow: hidden;
}

#scroller {
  position: absolute;
  z-index: 1;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
  width: 100%;
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  -o-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: none;
  -moz-text-size-adjust: none;
  -ms-text-size-adjust: none;
  -o-text-size-adjust: none;
  text-size-adjust: none;
}

#scroller ul {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
  text-align: left;
}

#scroller li {
  padding: 0 10px;
  height: 40px;
  line-height: 40px;
  border-bottom: 1px solid #ccc;
  border-top: 1px solid #fff;
  background-color: #fafafa;
  font-size: 14px;
}

Any advice or tips on how to address this issue would be greatly appreciated.

Answer №1

Kindly relocate the fixthis element to immediately follow the closing tag of the scroller div and ensure its z-index is set higher than the desired element.

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

Sending data to API using AngularJS Http Post

Upon clicking "Add new User", a modal pop-up will appear with a form containing a text field and a checkbox. However, upon clicking the create button, the data is not being posted to the API and the modal pop-up remains open without closing. I would like ...

A pop-up appears, prompting me to redirect to an external URL when clicking on a link that opens in a new tab on my WordPress website

Seeking assistance in dealing with a popup that appears when trying to open a link redirected to an external URL. The popup prompts for permission to open the link in a new tab. Upon inspecting the Element, the code snippet below is revealed: <div cla ...

PersistJS callback function is malfunctioning

I stumbled upon a great library for managing client storage. You can find the latest version here: https://github.com/jeremydurham/persist-js However, I encountered an issue with the callback function. var result = store.get('saved_data', func ...

Can the labelDisplayedRows be disabled in the table pagination actions of Material UI?

I am currently working on customizing the table pagination actions in Material UI's table and I need to remove the labelDisplayedRows function. My goal is to only show next/previous icons in the footer without the counter (e.g., 1 of 5). I managed t ...

Using conditional statements in CodeIgniter to display various menus

I encountered an issue with a variable in my code. When I attempt to retrieve its value, it shows up as undefined despite having stored the session of the variable "$level" and passing it to the view. I find it strange that the condition of the variable tu ...

Is there a smooth and effective method to implement a timeout restriction while loading a sluggish external file using JavaScript?

Incorporating content from an external PHP file on a different server using JavaScript can sometimes be problematic. There are instances where the other service may be slow to load or not load at all. Is there a method in JavaScript to attempt fetching th ...

Implementing MySQL in JavaScript code leads to various possibilities

I am working on a web application that requires retrieving values from a MySQL database. The process involves: PHP code generates an HTML page successfully. Clicking a button updates a cookie, which also works. Using the cookie in a MySQL query, which is ...

The content within a container that has flex-grow: 1 is exceeding its bounds instead of being able to scroll

I am currently facing an issue with a container that is set to grow within a fixed size container and I need help figuring out how to make the content wrapper element scrollable. Specifically, the flex-grow container houses a div that is larger than the c ...

What is the process for ensuring that an image is set as the submit button in an HTML form on IE 7?

My HTML form is designed with an action on a PHP script, and the submit button displays a custom image instead of the default grey. While this code works perfectly in Chrome, it fails to function properly in Internet Explorer 7. Do you have any suggestions ...

Numerous links were chosen and multiple div elements were displayed on the screen

Currently, I have a setup where selecting one div will show its content. However, I am looking to enhance this by allowing multiple divs to be displayed simultaneously. For example, if 'Div 1' is selected and shown, I want the content of 'Di ...

extracting an empty value from this variable

When I click on an anchor tag using this operator, the value appears blank. I have multiple divs with the same class, so I used the .each() function, but I can't figure out where I'm going wrong. The desired output is that when I click on one of ...

Using Razor view form with various submit buttons

In my razor view, I have a BeginForm command surrounded by a loop that generates an HTML table with a submit button in each row. My concern is how do I identify which specific row the submitted form corresponds to when sending it back to the controller? T ...

Creating a Dynamic Navigation Bar with HTML and CSS

I've been exploring the code on w3schools.com, and while there are some great examples, I'm struggling to understand it all. Unfortunately, there aren't any instructions on customizing the code for a third level of menus. Can someone simplif ...

combining: enhancing the value of the background-image property

Here is a mixin that I would like to modify: .a () {background-image: url(one.png);} I want to create a new class .b which inherits properties from .a, but also includes an additional background image layer, like this: .b { .a; ...

Tips for customizing the appearance of an HTML dropdown menu

Here is the code snippet: <select name="xyz" id="abc"> <option value="x">10/Page</option> <option value="y">20/Page</option> <option value="z">30/Pa ...

What would be more efficient: inputting all items in a form at once or adding them one by one consecutively

My mind is preoccupied with a dilemma: is it better to have all possible items already on the form, or should items only be added when the user requests them? Let me elaborate - Imagine I have a form with 4 input fields and one textarea. Alongside that, t ...

I am in need of a efficient loader for a slow-loading page on my website. Any recommendations on where to find one that works

I'm experiencing slow loading times on my website and I'm looking to implement a loader that will hide the page until all elements are fully loaded. I've tested several loaders, but they all seem to briefly display the page before the loader ...

Retrieving the text from the img tag of a bs4.element.Tag

I have a question that needs to be addressed. My concern involves a list of bs4.element.Tags, similar to the one illustrated in the image below. The issue at hand is filtering out only the href tags that are preceded by an <img> tag. How can this s ...

Browsing through files on IE8 within one window

I recently encountered an issue that I have never experienced before. Typically, when browsing through my folders in Internet Explorer, everything worked smoothly for me. If I included various directory links, I could easily navigate back and forth to expl ...

Aligning the wp_nav_menu vertically within the site-header

Is there a way to vertically center the WordPress function wp_nav_menu in my site header? Although I followed the learnWebCode tutorial for the menu, I am struggling to implement it successfully. Is there anyone who can provide guidance or a solution? ...