tags:

views:

53

answers:

1

I have a fixed height div which looks like following. 2 issues.

1 - when I click the 'on_click"show_hidden_div' it does show the div but since the parent div is fixed height, I just get a scrollbar and now the user has to scroll down, any way to automatically scroll down when the hidden div is show?

2 - When the hidden div is hidden again(by clicking on the link), it seems the entire 'fixed_height' kinda does a jarring motion, while the div is being hidden. How to make this smooth?

I am using jquery obviously and this fixed height div is inside a jquery tools overlay div, basically this is a modal dialog.

here is the javascript

$('#on_click_show_hidden_div').live('click', function() {
        $('#on_click_show_hidden_div').toggle('slow');
        return false;
    });

  <div id='fixed_height>

    <div id='form-wrapper'>
    <!-- form and form element -->
    <form id='post_form'>
    <a id='on_click_show_hidden_div'></a>
    <div id='hidden_div_with_more_form_elements'></div>
    <input id='submit'/>
    </form>
    </div>

</div>
A: 

First, I'm going to assume that in your click event, you meant to toggle your hidden_div_with_more_form_elements, not the link itself.

Second, it would be helpful if you formatted your html sanely (i.e. double quotes)

Third, it would be helpful if you provided some basic CSS that shows the actual issue with the example html.

Finally, here's close to what you want:

$('#on_click_show_hidden_div').click(function() {
  $('#hidden_div_with_more_form_elements').toggle('slow', function(){
     var pos = $('#hidden_div_with_more_form_elements').position().top;
     $('#fixed_height').scrollTop(pos);
  });

  return false;
});

Here is a live example: http://jsfiddle.net/ryleyb/ewehW/

Essentially, jQuery's scrollTop provides what you want to do, and I'm using it in the callback from the toggle animation (i.e. scroll to it once it has been successfully animated in).

Ryley
Thanks. it does solve the first problem. But when the div is toggled to be hidden, the jarring still happens.
badnaam
I'm not 100% sure I see what you're talking about, does this help: http://jsfiddle.net/ewehW/1/
Ryley
Here is my code, i think what might be causing the issue is that the whole thing is wrapped in this overlay div.http://pastie.org/1187149
badnaam
I don't see any difference with the overlay or without it - can you edit this: http://jsfiddle.net/ryleyb/ewehW/2/ until it displays the issue you're having, then click the "Update" button (which saves it)? That way I can see what is going on...
Ryley
here you go, I updated it http://jsfiddle.net/ewehW/15/. When you hide it back again, there is a flash. It does not look as bad in this jsfiddle, as it does in my case, but you can see the jarring flash. What might be happening is that, in my site, when the overlay first shows up there is no scrollbar, it's sized to fit the form, and when the hidden div shows up the scrollbar appears and when you hide it it dissapears..may be that adjustment is causing this.
badnaam
It looks pretty good to me if I change the `50` to `slow`: http://jsfiddle.net/ewehW/18/ Also, a tip on using jsfiddle, you can just click "Run" if you are making tiny changes, but want to see what you've done, then hit "Update" when you really want to save it.
Ryley
hmm..well when I change it to 'slow' it is actually worse, noticably. But 50 does not give you the nice smooth animation. Isn't that what you see?
badnaam
Nope... the whole thing looks quite smooth
Ryley
Are you look at this one..http://jsfiddle.net/ewehW/18/. Even the collapse looks smooth to you?
badnaam
Yep, very smooth both out and in
Ryley
What browser are you using? I looked at IE7, IE8, FF3, Chrome, all seem just fine - if its one of those, maybe you could make a screencast so I can see what you see?
Ryley