Fx.Scroll in IE scroll to Element then back.

a place to get help

Moderator: 1.2 Moderators

Forum rules
  • Every time you need help create a new thread (but please use the search function before, as your problem maybe has already been solved)
  • use code highlighting (help)
  • After your problem has been solved you have to rename the subject to "[solved] <Topicname>" AND set the Topic icon as solved (the green check)

Fx.Scroll in IE scroll to Element then back.

Postby maslak on Sun Nov 30, 2008 1:35 am

Hello, I have funny efect in IE, have to made scroll next and previous buttons
In Firefox everything works well but in IE scrollNext button scroll to next element
then scroll back and scroll forward.

Can anybody would help me and show me where is the problem
or give me similar example.

http://www.maslak.waw.pl/scroll/

Thanks.
maslak
 
Posts: 1
Joined: Sun Nov 30, 2008 1:28 am

Re: Fx.Scroll in IE scroll to Element then back.

Postby e1zorro on Mon Dec 01, 2008 2:22 am

Hi,

I encountered this issue very recently. It appears to be a bug in the way IE measures positions/offsets introduced in mootools 1.2.1 (ironically as a fix for the a similar issue).

The solution therefore is to roll back to v1.2.0 or attempt an ugly hack to merge 1.2's getPosition/getOffset routines into the 1.2.1 codebase.

Here's a class I toyed with to do just that (although ultimately I decided to just go back to 1.2.0).

I tested it in your example page and it seemed to fix your issue ( drop the code below into your page and then switch your Fx call to Fx.Scroll2 instead of Fx.Scroll)

Hope that helps,

=elz=

  1.  
  2.  
  3. /* A workaround for IE issues in mootools 1.2.1
  4.  * - Recreates FX.Scroll() but utilises 1.2.0's getPosition/getOffset routines.
  5.  */
  6. Fx.Scroll2 = new Class({
  7.  
  8.     'Extends': Fx.Scroll,
  9.  
  10.     'styleString': Element.getComputedStyle,
  11.     'styleNumber': function(element, style) {
  12.         return this.styleString(element, style).toInt() || 0;
  13.     },
  14.     'borderBox': function(element) {
  15.         return this.styleString(element, '-moz-box-sizing') == 'border-box';
  16.     },
  17.     'topBorder': function(element) {
  18.         return this.styleNumber(element, 'border-top-width');
  19.     },
  20.     'leftBorder': function(element) {
  21.         return this.styleNumber(element, 'border-left-width');
  22.     },
  23.     'isBody': function(element) {
  24.         return (/^(?:body|html)$/i).test(element.tagName);
  25.     }, 
  26.     'toElement': function(el) {
  27.         var offset   = {x: 0, y: 0};
  28.         var element  = $(el);
  29.        
  30.         if (this.isBody(element)) {
  31.             return offset;
  32.         }
  33.         var scroll = element.getScrolls();
  34.                
  35.         while (element && !this.isBody(element)){
  36.             offset.x += element.offsetLeft;
  37.             offset.y += element.offsetTop;
  38.            
  39.             if (Browser.Engine.gecko){
  40.                 if (!this.borderBox(element)){
  41.                     offset.x += this.leftBorder(element);
  42.                     offset.y += this.topBorder(element);
  43.                 }
  44.                 var parent = element.parentNode;
  45.                 if (parent && this.styleString(parent, 'overflow') != 'visible'){
  46.                     offset.x += this.leftBorder(parent);
  47.                     offset.y += this.topBorder(parent);
  48.                 }
  49.             } else if (Browser.Engine.trident || Browser.Engine.webkit){
  50.                 offset.x += this.leftBorder(element);
  51.                 offset.y += this.topBorder(element);
  52.             }
  53.  
  54.             element = element.offsetParent;
  55.             if (Browser.Engine.trident) {
  56.                 while (element && !element.currentStyle.hasLayout) {
  57.                     element = element.offsetParent;
  58.                 }
  59.             }
  60.         }
  61.         if (Browser.Engine.gecko && !this.borderBox(element)){
  62.             offset.x -= this.leftBorder(element);
  63.             offset.y -= this.topBorder(element);
  64.         }
  65.        
  66.         var relative = this.element;
  67.         var relativePosition = (relative && (relative = $(relative))) ? relative.getPosition() : {x: 0, y: 0};
  68.         var position = {x: offset.x - scroll.x, y: offset.y - scroll.y};
  69.        
  70.         return this.start(position.x - relativePosition.x, position.y - relativePosition.y);
  71.     }
  72. });
  73.  
  74.  
e1zorro
 
Posts: 6
Joined: Mon Dec 01, 2008 2:16 am

Re: Fx.Scroll in IE scroll to Element then back.

Postby e1zorro on Mon Dec 01, 2008 2:34 am

Thought I should also mention that it's worth triple checking your CSS is the same as in the official demos- Fx.Scroll does normally work fine in IE but in my case we had a horrendously complex page layout with cascading styles/themes and it would have taken me forever to locate the reason why things weren't working as they should be under IE, so I decided on a workaround...
e1zorro
 
Posts: 6
Joined: Mon Dec 01, 2008 2:16 am

Re: Fx.Scroll in IE scroll to Element then back.

Postby hyperlinked on Tue Jan 13, 2009 5:34 am

e1zorro, you just cured hours and hours of frustration. There does appear to be something funny with the way Fx.Scroll works in IE7 and I don't think it's merely a CSS issue. I have a series of thumbnail images floated left with a left and right arrow to scroll horizontally through the thumbnails. The HTML and CSS was stripped down to the barest elements. It still didn't work right in IE7. The first click scrolls as expected, but all subsequent scrolls require two clicks. The first click either nudges the scrolled element a bit or it scrolls backward to a seemingly arbitrary spot in the wrong direction. Your fix worked wonders.
hyperlinked
 
Posts: 2
Joined: Sat Nov 15, 2008 3:28 pm

Re: Fx.Scroll in IE scroll to Element then back.

Postby e1zorro on Wed Jan 14, 2009 9:05 pm

Glad it helped.

I don't suppose you have your stripped down test version to hand and would be willing to post it here?

If so we could post a bug report with a solid test case (assuming it hasn't been done already)
e1zorro
 
Posts: 6
Joined: Mon Dec 01, 2008 2:16 am

Re: Fx.Scroll in IE scroll to Element then back.

Postby philip on Tue Jan 27, 2009 7:26 am

Just wanted to say thanks for that Scroll2 class, it did the trick for me.

My situation was very similar to what hyperlink described -- my scroller used to work great in 1.11 but started working strangely/randomly in IE6/IE7 after upgrading to 1.21. I spent HOURS scouring my (very minimal) JS and CSS, and couldn't find any errors. Once I added the Scroll2 class, *problem solved*! I wish all problems could be solved so easily.

Thanks again :D
philip
 
Posts: 1
Joined: Tue Jan 27, 2009 7:20 am

Re: Fx.Scroll in IE scroll to Element then back.

Postby carlosrodriguez on Sun Mar 29, 2009 5:06 pm

The Scroll2 class has been a Life Saver. I was experiencing errors in both IE6 and IE7 where my scroll would go to the first element, then back to the first, then to a random element, then back to the first again and so forth. After using the class the scroll now works on both versions of IE (hopefully it does on IE8 as well).

Thanks
carlosrodriguez
 
Posts: 1
Joined: Sun Mar 29, 2009 5:04 pm

Re: Fx.Scroll in IE scroll to Element then back.

Postby e1zorro on Fri Apr 03, 2009 10:42 am

No problem, glad it helped
e1zorro
 
Posts: 6
Joined: Mon Dec 01, 2008 2:16 am

Re: Fx.Scroll in IE scroll to Element then back.

Postby bbirnbaum on Sun Apr 05, 2009 8:49 pm

Just want to thank you for Scroll2!! I had the exact same issues as the other users in this post. Scroll2 was a lifesaver for me too. I hope this fix is incorporated in future updates.
bbirnbaum
 
Posts: 3
Joined: Tue Mar 24, 2009 4:58 pm

Re: Fx.Scroll in IE scroll to Element then back.

Postby fearlex on Wed May 06, 2009 4:57 am

Oh man, i owe you one, this has definitively being a life saver, from extensive amount of pulling my hair out. thanks
fearlex
 
Posts: 4
Joined: Sun Oct 05, 2008 5:41 am

Next

Return to Help

Who is online

Users browsing this forum: No registered users and 4 guests