JQuery animate scrollTop Container?

Up vote 0 down vote favorite share g+ share fb share tw.

I have the following snippet to scroll my form to the first error: $('html,body').stop(). Delay(500). Animate({scrollTop: $errors.

Filter(":first").offset(). Top -30},'slow'); The full block at the end of my jquery validation code looks like the following. If there is an error upon submission, it scrolls the form to the first error.

Var $errors = $(". McError"); if($errors.size() > 0){ if(settings. McScrollToError){ $('html,body').stop().

Delay(500). Animate({scrollTop: $errors. Filter(":first").offset().

Top -30},'slow'); } return false; } else{ mcResponse('', false); return true; } However, if I replace the $('html,body') with the name of a container element such as a div class $('. MyDivClass'), it doesn't seem to work well. It just scrolls to random places.

The css of the container element looks like this (so you know what I mean): . McModalWrap1{ position:fixed; top:0; bottom:0; left:0; right:0; padding:50px; background-image:url(images/overlay. Png); overflow:auto; z-index:999; display:none; } jquery scrolltop link|improve this question edited Feb 8 at 20:53 asked Feb 8 at 20:50user10020399516 92% accept rate.

.offset(): Get the current coordinates of the first element in the set of matched elements, relative to the document. Source: api.jquery.com/offset/ You want to use .position() to get the relative position:: Get the current coordinates of the first element in the set of matched elements, relative to the offset parent. Source: api.jquery.com/position For example: $('.

MyDivClass').stop(). Delay(500). Animate({ scrollTop: ($errors.

Filter(":first").position(). Top -30) },'slow').

I seem to get the same results. – user1002039 Feb 8 at 21:03 Could you post a link so I could see the behavior? – Jasper Feb 8 at 21:04 Sorry I couldn't upload the files.

I will accept the answer though. Thank you! – user1002039 Feb 8 at 22:10.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions