2

I have no code for this, as this is more of a concept question.

I have a jquery mobile page that has a section at the top of its content that I want to place above the viewport. What i've done is set a silentscroll that is equivalent to the height of this section, which makes the window scroll to just below the section i want hidden.

The problem I have right now is that between when the page is loaded and shown to when the silentscroll is thrown, there is a split second of being able to see the section to be hidden, which makes the page look buggy given that you can see the silentscroll jump by 100-sum pixels to hide the section. This is clearly because the silentscroll is execute after the page is shown.

Is there a way to set a scrollTop to jquery mobile for it to be executed before the page is shown, preferably around when the pagebeforeshow event is thrown? As far as I know, this event is thrown after all the jquery mobile widgets are initialized, so couldn't the scrollTop be set on the window at this time?

What I'm trying to do is set the scrollTop value on the window before the page is shown, so that the user doesn't have to see the page jump.

I haven't been able to correctly set it up myself, I'm wondering if it's event possible.

Here's a quick image of the setup i'm trying to recreate. The green square is the section I want 'hidden', above the window. The blue box represents the mobile window and the grey box represents the document.

enter image description here

EDIT: I've checked mobile browsers; safari has no jump/jitter when it corrects for the silentscroll. Chrome mobile on IOS does have the jump/jitter, I wonder if it's a question of browser performance, or the way it queues DOM/viewport changes...

Prusprus
  • 7,987
  • 9
  • 42
  • 57
  • 2
    No I don't think that is possible. You could hide your html , set the scrolltop and show your html again. – putvande Sep 05 '13 at 14:23
  • Vimeo has this effect on [video pages](http://vimeo.com/71370784) to show more videos by that creator. Might be worth it to investigate out how they do it. – MLM Sep 05 '13 at 14:33
  • Vimeo for desktop yes, but mobile doesn't have this feature. – Prusprus Sep 05 '13 at 14:39
  • @Prusprus I am on a nexus 7 Android 4.3 in Chrome and it is working fine for me. What does mobile mean to you? – MLM Sep 05 '13 at 23:02
  • I was checking CrIOS and safari mobile. I admit I wasn't clear on the phone used, but I haven't yet tried it on Android myself. It worked fine on Safari on my IOS, but not on chrome. – Prusprus Sep 06 '13 at 13:51

3 Answers3

3

DEMO: http://jsfiddle.net/gnsj6/

CSS:

.top {
    height: 200px;
    margin-top: -200px;
}

.container { 
    height: 1000px; 
}

jQuery:

$('html, body').animate({
    scrollTop: $("#topedge").offset().top + 200
}, 0, function() {

    $(".top").css("margin-top","0px");

});

I can't notice any jump with this solution. Neither with quite huge data (http://jsfiddle.net/gnsj6/4/)

Fez Vrasta
  • 14,110
  • 21
  • 98
  • 160
0

Add a class that hides the page, after you set scroll top remove the class.

Jeffpowrs
  • 4,430
  • 4
  • 30
  • 49
0

I would say something like this. Hide your body (with visibility, otherwise you can't scroll):

....
<body style="visibility:hidden;">....

And do this with jQuery:

$(function(){
    $('body').scrollTop('200px').css('visibility','');

});
putvande
  • 15,068
  • 3
  • 34
  • 50