Fixed position on the calling card while scrolling

I am using Angular and compiling on iOS using Phonegap. I need to <div>

scroll and commit when it reaches the top of the page, similar to this post: https://css-tricks.com/scroll-fix-content/ .

This method works great for desktop browsers and Safari on iPhone, but breaks in Chrome on iPhone and on the native (Phonegap) iPhone app. <div>

will continue scrolling with the wrapper and then move to the desired position at the top of the page after scrolling ends.

Simplified HTML

<div class="wrapper">

  <other-content></other-content>

  <div id="top-shelf">
    scroll to fixed position
  </div>
</div>

      

CSS

.wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  margin:0;
  max-width:100%;
  overflow-x: hidden;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
}

.fixed-top-shelf #top-shelf {
  position: fixed;
  top: 48px;
  z-index: 1;
  width: 100%;
  -webkit-backface-visibility: hidden;
  -webkit-transform: translateZ(0);
}

      

And JS to add the class

element.on('scroll', handleScroll);

function handleScroll() {
  var st = element.scrollTop();

  if (st <= 80) {
    element.addClass('fixed-top-shelf');
  } else {
    element.removeClass('fixed-top-shelf');
  }

}

      

+3
html angularjs css ios cordova


source to share


No one has answered this question yet

Check out similar questions:

4078
How to horizontally center a <div>?
1929
How to make div 100% of browser window height
1889
How do I make a div no larger than its content?
1630
Make a div to fill the height of the remaining screen.
1452
Creating a div element in jQuery
1415
Navigate through div to base elements
1370
Get position (X, Y) of HTML element
1264
How can I automatically resize the image to fit the container div?
1014
How to center an absolutely positioned element in a div?
131
Have a fixed div position that should scroll if content overflows



All Articles
Loading...
X
Show
Funny
Dev
Pics