Thanks everybody!

Kevin,
you probably meant offsetHeight, cause outerHeight works only for
browser window not for element.

Mark,
$(myElement).css('height') works when height is set in CSS, otherwise
it's not defined. Anyway - thanks!

So, finally I ended up with the following code:


// Function returns Y offset of element from the very root element
(html?).
// We need this function to get to the root element,
// cause for IE .offsetParent for cloned elements is some intermediate
parent,
// and not root element like in FF and other "good" browsers...
function getPosition(obj) {
         var y=0;
         while(obj) {
            y+=obj.offsetTop;
            obj=obj.offsetParent;
         }
         return y;
}

// ...
// Then when creating a new_entity in the DOM, scroll down if it's
outside of viewport

var cur_scrollY = document.body.scrollTop;
var new_scrollY = getPosition(new_entity.get(0))
        + new_entity.get(0).offsetHeight
        - document.body.clientHeight
        + 10;
if (new_scrollY > cur_scrollY) {
        $.scrollTo(new_scrollY, 300);
}



On Oct 17, 8:02 pm, Kevin Dalman <[email protected]> wrote:
> Actually $(myElement).outerHeight() would be better. You can pass
> 'true' to add the element's margins, or you could add a few pixels
> (+10) so your element is not jammed right up against the bottom of the
> screen.
>
> On Oct 14, 4:23 am, Mark <[email protected]> wrote:
>
> > Try:  $(myElement).css('height')
>
> > Also this may be the wrong forum for this discussion 
> > perhapshttp://groups.google.com/group/jquery-enismore relevant.
>
> > 2009/10/14 Ivan <[email protected]>
>
> > > Mark, great, thanks, this is what I thought to use!
>
> > > So I need to figure out these 3 things
> > > 1) myWindowHeight: document.body.clientHeight seems to work in my set
> > > of browsers (IE8, FF3.5, Opera 10, Chrome 1, Safari 4), not sure about
> > > earliers.
> > > 2) myElementHeight: can't find yet...
> > > 3) currentScrollPosition: can't find yet... I need it to understand if
> > > I have to scroll, if element is in visible area - I don't.
>
> > > Any ideas from JS gurus? :)
>
> > > Regards,
> > > Ivan.
>
> > > On Oct 14, 8:50 am, Mark <[email protected]> wrote:
> > > > Ivan,
>
> > > > Try using the offset setting.
>
> > > > Something like :
>
> > > $.scrollTo($('#bottomElem'),1000,{offset:-1*(myWindowHeight-myElementHeight­)});
>
> > > > Mark
>
> > > > 2009/10/14 Ivan <[email protected]>
>
> > > > > Hi All
>
> > > > > I'm trying to use scrollTo() plugin.
> > > > > When user clicks on some button, I create a new element in the DOM at
> > > > > some place below this button.
> > > > > And if it's outside of visible page area - I want page to be scrolled
> > > > > to that new element.
> > > > > But I don't want to scroll till the element will be in the left-top
> > > > > corner, but till it will be in the bottom of the visible page area,
> > > > > but with all content shown.
>
> > > > > I probably need to specify somehow position = the element - window
> > > > > height + element height.
> > > > > But I'm not so good in JavaScript.
>
> > > > > Any help will be greatly appreciated!
>
> > > > > Ivan..- Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to