Window.scrollTo Fails Under OVERFLOW-Y: auto Style.
I was trying to subclass a Web Treeview control for my own evil purposes and ran into a sticky problem - scrollTo not working! Just for background, my evil purpose was to replace the Infragistics ultra web tree control, since we only use about 5% of the functionality, but pay the full price of upgrades and page size for the other 95%.
anyway, all was going well, until I tried to implement the ScrollTo functionality.
My first pass looked something like this:
[javascript]
<Script Type="text/javascript">
<!–
var ele = document.getElementById(nodeID);
window.scrollTo(ele.parentElement.offsetParent.offsetLeft ,ele.parentElement.offsetParent.offsetTop);
//–>
</Script>
[/javascript]
Now this worked great in my sample text page, but when I dropped it into the main application page, it didn’t do a damn thing. What gives?
Well, I traced the problem down to a style tag on the wrapping div tag:
[css]
OVERFLOW-Y: auto;
[/css]
It seems that the auto setting disallowed my scrolling to a specific x,y coordinate when that coordinate was outside the visible space.
That really stunk because I didn’t have the ability to modify the existing container page, beyond replacing the Infragistics control tag.
Luckily, I found a workaround:
[javascript]
<Script Type="text/javascript">
<!–
var ele = document.getElementById(nodeID);
ele.scrollIntoView();
//–>
</Script>
[/javascript]
Not only does this work within the CSS overflow directive, but it’s also a bit more elegant since I no longer have to worry about all that parent offset nonsense.
Related Posts - How to find what's running under SVCHost.exe My PC was behaving sluggishly the other day. I tried to be patient, but had to fire up the task manager when I could bear it no longer. That's when...
- Annoying "next message" behavior in Thunderbird, and how to stop it! I love the Thunderbird email client. I use the portable version on my thumb drive, but one thing has always bugged the hell out of me when I use it:...
- Arraylist and generics don't mix with IEnumerable(Of T).GetEnumerator. The other day I was writing an in-house tool to assist in some upgrades we were performing on client installations. This tool was supposed to perform its operations on a...
- The 3 Most Important Questions You Should Ask About Each Bug You Find. I stumbled upon (quite literally) an article by Tom Van Vleck titled Three Questions About Each Bug You Find today, and thought I would share it: "The key idea behind...
- Microsoft FxCop doesn't like Microsoft generated code! The other day I thought it might be nice to "do the right thing" and give my code a run against Microsoft's FxCop. I ran it right out of the...
Related Websites - Understanding the Simple SEO Structure From Title, to Meta, to Content Unfortunately I see so many people performing search engine optimization services in this day and age, however they don't understand the basic website structure to perform well in the search engines. This may seem like a no brainer article, however after you read this article take a look at......
- Website Optimization For Newbies - 3 Important Tips For Keyword Placement in Your Website Website optimization requires placing your main keywords in specific places on your web pages. After you have performed a keyword search and chosen the specific keywords that you want the search engines to recognize, you should place one or more of these keywords on each web page. But don't......
- Save Time, Money and Space in Over 80 Ways If you're looking for handy gadgets, tools and various items that can save you time, money or space (or all three!) this list of more than 80 top products is just what you need. Everyone's got saving money on their minds these days. Some of us are always looking to......
- Optimizing Title Tags For Success Properly optimizing the title tag (or more appropriately, the HTML title element) of a web page can yield big benefits from a search engine optimization (SEO) perspective. The following document explains why titles are so important and provides useful tips on how to optimize a title tag.Title tags are......
- Maximize Your Search Results-Part2 This is excellent information for everyone. I am surprised that more internet users do not know these simple types of searches. I am even more surprised at how many marketers do not know this. The search engines are here to give us targeted info regarding our searches but they are......
