Igor's Blog

Not long ago I wrote about Mobile Safari scrolling problem with an input field inside a fixed DIV and provided a solution that used a small amount of CSS to make the scrolling issue go away. This worked really well until I discovered that by setting overflow to auto caused the 'scroll' event to never fire. I rely on the scroll event firing so that I can dynamically load more data into a page, so this forced me into finding a better solution and here it is.

To reiterate the problem below is a video that shows how the background page jumps to the top whenever an input field gets focus (the field appears in a fixed position DIV)...

safarifixeddivissue2.png


My solution depends on having two main fixed position DIVs. The first one is the page 'header', the second is the page 'body wrapper'. These together take up 100% of the page height. Inside the 'header' is another DIV that holds all of the popup DIVs that I wish to display (not visible initially). The 'body wrapper' DIV is another fixed position DIV that is simply offset from the top by the value equal to the height of the 'header' DIV. This DIV has it's overflow-y set to 'scroll' so the scroll event can be captured. Inside the 'body wrapper' DIV is another DIV that contains the actual content of the page.

Now when I display a popup, since it's inside the header which is always visible, the 'body wrapper' isn't affected. Perfect!

Here's the HTML...
 HTML
<body>
<div class="tb_header">
...header content...
<div class="tb_popup_holder">
...popup divs...
</div>
</div>
<div class="tb_body_wrapper">
<div class="tb_body">
...body content...
</div>
</div>
</body>




...and the CSS (leaving out any extra styling)...
 CSS
html, body {
margin: 0 0;
height: 100%;
width: 100%;
}
.tb_header {
width: 100%;
height: 40px;
position: fixed;
left: 0;
top: 0;
}
.tb_body_wrapper {
padding-bottom: 40px;
height: 100%;
width: 100%;
position: fixed;
left: 0;
top: 40px;
overflow-y: scroll;
}
.tb_body {
width: 100%;
display: inline-block;
}


The 'body wrapper' has a 40px padding at the bottom so that any content that goes to the end of the page isn't cut off due to the 40px header.

Now I can listen to the scroll event on the 'body wrapper' like so:
 JavaScript
$('.tb_body_wrapper').scroll(function() {
// handle scroll
})


-i

comments powered by Disqus
Other posts you may like...
Programming, DIY, Games, Hacks, and Tech

Recent Blog Posts

Converting a CSV file containing commas in quotes to a pipe separated file using Awk and Bash

How to get Facybox gallery popup to work for images with dynamic URLs

jQuery UI Photoboxr plugin updated to version 0.2

Learn How to Add Disclaimer to All Outgoing Emails in Office 365

How to securely host your web site for free with Google Cloud and CloudFlare (part 3)

How to securely host your web site for free with Google Cloud and CloudFlare (part 2)

How to securely host your web site for free with Google Cloud and CloudFlare (part 1)

Beware of the subtle difference in date format strings between MySQL and SQLite

Postman reporting Unexpected 'N' error in response body

Adding extra shelves to the Ikea Detolf display cabinet

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
300 George St Blogumentary

My Online Tools

UUID to OID Converter
Guru JSON-RPC Tester
Extrudifier Object Designer
Travel ┬ÁBlog

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Please follow me for more great content!
     
Don't show this again