If you visit this page on your iPad device on the latest version of iOS you can follow along.
http://fiddle.jshell.net/will/8VJ58/10/show/light/
I have two elements with the new -webkit-overflow-scrolling: touch; property and value applied. The left hand grey area has plenty of content and will scroll in portrait or landscape. The right will only scroll in landscape.
If you start in landscape (refresh in landscape) you can scroll both areas with the inertia scrolling. Works great. Now flip your iPad into portrait and only the left hand area will scroll. This is as intended. But when you flip back to landscape the right hand area will no longer scroll at all, whereas the left hand area is fine still.
It's obvious how to stop this happening, but I don't always have the content to fill the area.
So any ideas?
Thanks in advance,Will :)
Coming late with a similar, but simpler solution.
var $el = $('.myElementClass');
function setOverflow(){
$el.css({webkitOverflowScrolling: 'touch', overflow: 'auto'});
}
function resizeHandler(){
$el.css({webkitOverflowScrolling: 'auto', overflow: 'hidden'});
setTimeout(setOverflow,10);
}
[EDIT]
Watch out, after experimenting (a lot), I found out that display:none declarations will surely break the webkit-overflow-scrolling: touch feature.
Never use it on elements (or parents of elements) that are supposed to support touch scrolling.
I am actually having the exact same issue. I have narrowed it down to the fact that it affects DIVs whose content's no longer require scrolling when the orientation is changed.
In your example. The DIV on the right scrolls in landscape, does not NEED to scroll in portrait, but then needs to scroll again. I have tested this when both DIVs (left and right) need to scroll regardless of orientation and its not a problem.
UPDATE:
I actually seem to have fixed this!
The issue appears to be a timing issue. During resize the inner content is not big enough to warrant scrolling on the outer DIV that has overflow. After wasting a day on this, I finally came up with this hack:
<div id="header" style="position:fixed; height:100px">Header</div>
<div id="content" style="overflow: auto; -webkit-overflow-scrolling: touch">
<div id="contentInner">
content that is not long enough to always scroll during different orientations
</div>
</div>
Here is my logic whenever the page resizes:
function handleResize()
{
var iHeight = $(window).height() - $("#header").height();
// Height needs to be set, to allow for scrolling -
//this is the fixed container that will scroll
$('#content').height(iHeight - 10);
// Temporarily blow out the inner content, to FORCE ipad to scroll during resizing
// This is a timing issue where the inner content is not big enough during resize post orientation to require the outer DIV to scroll
$('#contentInner').height(1000);
// Set the heights back to something normal
// We have to "pause" long enough for the re-orientation resize to finish
window.setTimeout(delayFix, 10);
}
function delayFix()
{
var iHeight = $(window).height() - $("#header").height();
// Inner divs force the outer div to always have at least something to scroll. This makes the inner DIV always "rubber-band" and prevents
// the page from scrolling all over the place for no reason.
// The height of the inner guy needs to be AT LEAST as big as the container and actually a nip bigger to cause the
// scrollable area to 'rubber band' properly
$('#contentInner').height(iHeight + 20);
}
I was able to use a known "fix" to force an iOS6 redraw to correct this issue without having to use setTimeout.
$(window).on('orientationchange', function()
{
var $elem=$('[selector]');
var orgDisplay=$elem.css('display');
$elem.css('display','none');
$elem.get(0).offsetHeight;
$elem.css('display',orgDisplay);
});
I experienced the same bug on iPhone, iPod and iPad. This is not restricted to the latter only.
I tried everything that was suggested to be a solution, but eventually the sweet combination ended up being detaching the element, appending it to its container and explicitly assigning it its own height while doing this, like so:
$(window).on('orientationchange', function(){
var el = $('.troublemaker').detach(),
elh = el.height();
setTimeout( el.css({'height':elh+'px'}).appendTo('.container'), 50 );
});
Related
The bounty expires in 4 days. Answers to this question are eligible for a +50 reputation bounty.
Allen Y wants to draw more attention to this question.
My app's main screen is relatively simple - a header, a main body that's primarily a text input, and a footer. It's set up like this (I'm simplifying the code to just call out the major structural items):
SafeAreaProvider
SafeAreaView // flex: 1
KeyboardAvoidingView // behavior="height", flex: 1, children also have flex: 1
Header // fixed height, no flexGrow
Swipeable // This lets the user swipe the input left or right; set to flexGrow: 1 and children have style flexGrow: 1
View
TextInput // multiline
Footer // fixed height, no flexGrow
The bug is that this combination of elements isn't working as I'd expect. First, when the screen first loads, it looks like this, with an empty gap between the footer and the keyboard:
Moving to a different screen then back results in the keyboard showing, but the footer getting pushed all the way to the bottom of the screen, ie into the part where SafeArea is supposed to prevent it from going and hidden by the keyboard:
Why is that white gap showing on screen load, and why does the footer go into the SafeArea when the keyboard is dismissed?
Addendum: frustratingly, this bug does not repro when running the app locally on Expo Go - the Footer is flush against the top of the keyboard.
Addendum 2: A mystifying thing about this bug is that it doesn't seem to be consistent. For example, the observation from my original post about going to another screen and back resulting in the footer being too far down into the safearea exclusion part does not happen consistently. Now when I'm loading the app (I haven't changed anything), going to another screen and back results in the Footer being above the safearea exclusion zone as I'd expect.
I wonder if this inconsistency suggests it's some kind of race condition between different parts of the frontend?
can you add this prop in KeyboardAvoidingView
keyboardVerticalOffset={-80}
adjust with your requirements
I got my parallax effect to work perfectly on my laptop screen size. As soon as I viewed my site on a larger screen I noticed the parallax effect was not finishing because there was not enough room to scroll down. How do I fix this issue? Below is a snippet of my code showing two of the elements moving as I scroll down. I am using data attributes to transform. Should I be using something else? You can view my site here http://nsohail.github.io/Project3-HTML/
<div id="slide-1" class="slide"
data-0="transform:translate(-770px,0px);"
data-10p="transform:translate(-770px,0px);"
data-100p="transform:translate(185px,0px);">
</div>
<div id="slide-1" class="slide"
data-0="transform:translate(770px,0px);"
data-10p="transform:translate(770px,0px);"
data-100p="transform:translate(-220px,0px);">
</div>
Instead of using 100p (percentages) use pixels so it will end at an exact spot no matter what the screen height is. So adjust your percentages to just numbers. For example data-0, data-10, data-100.
The content on my screen is definitely able to fit into the given screen size, yet the app still shows scrollbars if the screen is shorter than a certain height.
This fiddle shows the issue, if you shrink the result pane to a certain height.
What I've tried:
Adding `overflow-y:hidden' to the body fixes this issue, but I want to be able to scroll in the y-direction if needed, just not when it's not needed.
How can I stop this scrolling when unnecessary?
The reason ended up being because of a rule in the jQueryMobile.css:
.ui-page, bla, bla{
min-height: 420px;
}
changing that to a smaller number that matches what I needed fixed the issue.
I want a div that can be dragged any direction and is about 4x width and 4x height of the screen.
I set the body height and width, and you can scroll it diagonally some of the time, but other times when you go to scroll it will go only straight vertically or straight horizontally. It seems to be when you start scrolling straight up, it sticks that way. Is this normal for scrolling in an oversized webview div, or is there something else that might explain this?
This is on an iPad, with a body set to width:4000px and height:3000px.
The iPhone's tendency to scroll exactly horizontally or exactly vertically is intentional, and it's usually a useful feature: if you're reading a tall column of text that could scroll horizontally, it's nice to be able to scroll down without worrying about accidentally moving the view from side to side as you go. As far as I'm aware there's no way to turn this behavior off.
there is a property name directionalLockEnabled that get a bool
in scrollView class.
this will do the trick:
theWebView.scrollView.directionalLockEnabled = NO;
Is is possible to create a scrolling div within a html5 IOS app where the height needs to be dynamic?
To give a bit of background to my headache - our app has 3 main panels - the user can left or right swipe to reveal the first and third panel which contain notifications/settings (as in the Facebook app. All 3 outer panels are fixed position.
The main panel contains 6 pages - which are all absolutely positioned divs which hide and show via menu selection. Each revealed div (or page) needs to scroll, but all content is dynamic - so I cant set a height.
I have found several solutions for fixed heights - but none so far for dynamic heights..
Any suggestions?
Scrolling Divs
Another new feature in iOS 5+ is divs can finally scroll. To make a div scroll you’ll just need to add the following (this example has a fixed header but adjust the positioning to fit your app):
.scrollable {
position: absolute;
top: 50px;
left: 0;
right: 0;
bottom: 0;
overflow: scroll;
-webkit-overflow-scrolling: touch;
}
The trick here is adding the -webkit-overflow-scrolling to anywhere you’d normally set your overflow. The downside of Apple’s implementation is that the div doesn’t bounce as you’d hope when you are already at the absolute top or bottom. Instead of bouncing the div being scrolled, it bounces the whole page and reveals the browser chrome. This is where you’ll need a javascript fix.
Please try this example for Scrollability.
Please see this Link
iScroll is a party lib which help in good scrolling.
It has a scrolling without providing height.
We just have to call a method refresh when dom elements of scrolling are added.