473,414 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Scroll Position Reset "jerks"

Frinavale
9,735 Expert Mod 8TB
I think I'm trying to do something impossible.

I have a <div> element with a overflow style set to "scroll". In other words my <div> element allows the user to scroll the content within it.

There are a number of elements within this <div> that cause the <div> to participate in an Ajax call to the server.

In order to maintain the scroll position of the <div> during the Ajax request I store the scroll value in a hidden field so that when the Ajax request returns to the browser I can call a JavaScript function that retrieves this value and resets the scroll position of the <div>.

Everything's doing what it should except that in some browsers the process is very apparent when the scroll position is reset upon returning from the Ajax request. Let me try to explain this better.

The scroll position of the <div> is set to 0 when the Ajax request returns and then after everything has loaded the JavaScript is called to reset the scroll position to it's last value. There is a Split second where the content is redrawn at the 0 position and when the scroll is reset to it's previous position the content (and scroll bar) "jerks" into the right position.

I am trying to get rid of the "jerkyness" but I have No idea how to solve this problem.

I thought that if I placed the content of the scrollable <div> into another child <div>, that maybe I could set the scroll position of the scrollable <div> before the child <div> loaded but apparently I can't do this. (I cannot set the scroll position larger than the maximum that the content can be scrolled and since the content isn't loaded it's 0 ...so you can see why I'm having problems with this attempt.)

Does anyone have any pointers on how to solve this problem?

Thanks!

-Frinny
Apr 9 '09 #1
12 7778
gits
5,390 Expert Mod 4TB
i'm trying to follow ;) ... is there much content in that div? in case there are not a lot of nodes i would try to just clone the div node and place it 'over' the div in question. now do everything in the 'hidden' or better invisible div and then remove the 'masking' div ... or do you have a scroll-animation that you want to have explicitly shown on the scroll-operation?

kind regards
Apr 10 '09 #2
Frinavale
9,735 Expert Mod 8TB
I'm not following you with regards to the "cloning" thing.

In my case there is a table that has 40 columns and 512 rows of hyperlinks (plus any links in the headers or the "row headers" down the side). So, the content is quite large.

I do not want the scrolling process to be animated, it should not be apparent at all really. When the user clicks one of the links it posts to the server which updates some content in a different section on the page with the details of what they clicked on.

I'm interested in your "cloning" idea. Could you please elaborate?

Thanks :)

-Frinny
Apr 10 '09 #3
hsriat
1,654 Expert 1GB
I was wondering if setting the overflow to fixed temporarily just after sending the request, and changing it back to auto when request completed would do something useful for you.
Apr 10 '09 #4
gits
5,390 Expert Mod 4TB
i was talking about cloneNode() and setting a z-index of 1000 or something like that ... and placing the cloned node absolutely over the 'base' node ... but may be hsriat's idea would work and you could forget about the 'cloning' idea :) ....

kind regards
Apr 11 '09 #5
Frinavale
9,735 Expert Mod 8TB
What?

The overflow property cannot be set to a value of "fixed".

Did you mean to suggest setting the position property to "fixed"?

I tried this (setting the position property to fixed) and it seemed fixed the "jerk" effect (in IE8) but it's causing other problems: it moves the element to the left side of the screen over top of the rest of the content which is particularly bad in my page.

I changed the position property to "relative" instead and this "sort of" fixes the problem:

In IE8: the scroll bar and content still "jerks".

In IE7: the scroll bar and content still "jerks".

In FireFox3: the content blinks (disappears then reappears) when the position property is set to relative; the scroll bar still "jerks" but the content does not.

In FireFox2: the process is even more apparent because it takes longer to happen: the content is set to 0, both scroll bars appear and are enabled (even though the vertical one is not needed), the content is moved to the new position and the vertical scroll bar is disabled. The whole thing is about a second or two and it really isn't nice (I thought it was broken at first).

Chrome: works fine.

Safari: works fine.

[edit]
I changed the implementation so that the scrollable <div> always has a relative position by default. I am no longer setting this property using JavaScript...

This seems to have fixed the slow load time in FireFox 2 (but the scroll bars still appear and "jerk"... however the content does not "jerk") and has gotten rid of the blink problem in FireFox 3 but the horizontal scroll bar still jerks.
[/edit]

This solution is not quite up to my liking. I'm going to continue to look for a better one since it doesn't solve the problem in IE... but it was a good suggestion. Thanks a lot.



-Frinny
Apr 13 '09 #6
Frinavale
9,735 Expert Mod 8TB
I removed the relative position and tested in all browsers and discovered that this actually doesn't change anything.

The symptoms described in my last post exists regardless of setting the element's position to relative....it doesn't make any difference.

-Frinny
Apr 13 '09 #7
acoder
16,027 Expert Mod 8TB
How about the scrollIntoView() method?
Apr 13 '09 #8
Frinavale
9,735 Expert Mod 8TB
I never knew that method existed, thanks acoder.

I tried it using the w3c schools "try-it" utility and I can see that it'd be useful in certain scenarios :)

The main problem I have with using this method is that I'd have to track which element caused the Ajax call in order call it. It would be difficult for me to track this element (I'm not sure how I would go about doing that really)

Right now, I'm setting the scrollLeft property of the <div> which scrolls to the scrollLeft position that the <div> had before the Ajax call. I am able to track the scrollLeft position because of the nature of my JavaScript (and .NET ) Objects.

Call me lazy, but I don't want to spend a few days researching/attempting to track child .net controls in a JavaScript enabled Server control in order to try out this method in my application.

There wasn't a lot of documentation on this method.... Do you think it somehow help in preventing the <div>'s contents from being drawn at 0,0?
Apr 13 '09 #9
acoder
16,027 Expert Mod 8TB
scrollIntoView() is not part of any specification, but it's a useful enough method that most browser vendors saw fit to include support for it. I don't know exactly how it's implemented.

I'm afraid I don't have much experience with .NET, so I can't help much on that front. I thought you knew or at least could easily find out which element was the target/source in which case this method would be useful.
Apr 14 '09 #10
hsriat
1,654 Expert 1GB
@Frinavale
Apologies, but I meant to suggest to set scroll to hidden (temporarily)... got confused hidden with fixed.
Apr 15 '09 #11
Frinavale
9,735 Expert Mod 8TB
@hsriat
Ahh, I see.

I tried it but this did not help the situation....it just made the scroll bars disappear for split second.

Thanks for the recommendation.
Apr 15 '09 #12
gits
5,390 Expert Mod 4TB
so now you seem to be interested enough in the first mentioned 'clone-overlay' workaround? :) .... i'm not sure whether this wold be the best solution but i guess it would be a quite simple hack that gives you time to find a better solution later on :) .... just retrieve the div node, its position and then cloneNode(true) it ... place it absolutely over the 'scrolling'-div and remove the cloned node when the content should be ready ...
Apr 16 '09 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.