JQuery scrollTop issues for android

JavaScript related questions should go here.
Post Reply
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

JQuery scrollTop issues for android

Post by ExtremeGaming »

It seems android is more annoying than ie when it comes to this (for me at least ;)) The problem is that the JQuery scrollTop works on every device except android when it comes to overflow beind set to auto, or scroll. There is a workaround that is supposed to work, but it seems it doesn't for me. This is the workaround:
[syntax=javascript]
$("#chat_container").css('overflow', 'hidden');
$("#chat_container").scrollTop($("#chat_container")[0].scrollHeight);
$("#chat_container").css('overflow', 'auto');[/syntax]

It seems that the css is executing before the scrolltop, even with a delay() added to setting overflow back to auto. Without setting overflow back to auto, the scroll works, but users can't scroll because the overflow is now hidden...any ideas would be greatly appreciated :)

PS: Any attempts to find the location of scrollTop will be useless because android has a bug where it is always 0.
<?php while(!$succeed = try()); ?>
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: JQuery scrollTop issues for android

Post by Temor »

You've probably tried this already, but this guy seems to have a working solution:

http://blog.jonathanargentiero.com/?p=134

[syntax=javascript]
if (navigator.userAgent.match(/(iPod|iPhone|iPad|Android)/)) {
window.scrollTo(200,100) // first value for left offset, second value for top offset
}else{
$('html,body').animate({
scrollTop: 100,
scrollLeft: 200
}, 800, function(){
$('html,body').clearQueue();
});
}[/syntax]

The reason is because the mobile ios doesn’t know what $(‘html,body’)
is you have to animate $(“body”) instead.
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: JQuery scrollTop issues for android

Post by ExtremeGaming »

Thanks for the suggestion. I will try this after I get off work but at a quick glance, it looks like it will need the scrollTop of the div since it was originally meant for html/body.
<?php while(!$succeed = try()); ?>
ScTech
Posts: 92
Joined: Sat Aug 24, 2013 8:40 pm

Re: JQuery scrollTop issues for android

Post by ScTech »

Yes it appears that without knowing the distance left to scroll, that method is impossible to use for my purposes :(

I'm going to experiment with it a bit more and let you know how it goes. If there are any more suggestions I'd love to try them.


PS: It's EG. It was an old name based on a site I made but ended up selling so it kind of got old.
<?php while(!$succeed = try()); ?>
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: JQuery scrollTop issues for android

Post by Temor »

I see.

It's a shame Jacek isn't here. He could change your username.
ScTech
Posts: 92
Joined: Sat Aug 24, 2013 8:40 pm

Re: JQuery scrollTop issues for android

Post by ScTech »

Yea, but its ok. So I've figured out the issue. The css does not get executed before the scroll, rather, setting overflow back to auto resets it to scroll back to the top. I'm completely stumped as for what to do now.

EDIT: The issue seems to be the android browser. FireFox for android has a problem where it only scrolls partially down. Opera for android has no issue with this. I did more research and tried all of the popular open source chats and they all result in the same. It appears that there is no solution for this issue.
<?php while(!$succeed = try()); ?>
Post Reply