1

I have this fiddle which if you look at it in Chrome or IE works fine. You just click on the orange box and the box slides out, and click again and it returns to it's exact original position.

However if you look at it in Firefox ( make sure the scrollbar is showing in the bottom right frame) then the CSS which positions the box

right: -290px;

sets the position relative to the left edge of the scrollbar as I'd expect...

but the jQuery (note =-290px which should reset it to where it was on second click )

$('#slideClick').toggle(function() {
                $(this).parent().animate( { right: '0px' }, {queue:false, duration: 500});
            }, function() {
                $(this).parent().animate( { right: '-290px' }, {queue:false, duration: 500});
            });

sets the position relative to the right edge of the scrollbar, giving a 17px inconsistency.

Is this a known bug, or am I just mistaken somewhere. What is the workaround if it's a bug?

byronyasgur
  • 4,627
  • 13
  • 52
  • 96

3 Answers3

2

This will work as well. I have had a similar problem and it was that firefox deals with the scroll bar differently. This solution is not supposed to work with JQuery 1.9 and later. You are supposed to use feature detection now http://api.jquery.com/jQuery.support/ but I have not gotten into that yet. Hope this helps :)

    jQuery(function($) {
        $('#slideClick').toggle(function() {
            $(this).parent().animate( { right: '0px' }, {queue:false, duration: 500});
        }, function() {
            if ($.browser.mozilla && ($(document).height() > $(window).height()))
            {
                $(this).parent().animate({right: '-275px'},500);
            }
            else $(this).parent().animate( { right: '-290px' }, {queue:false, duration: 500});
        });
    });
sareed
  • 665
  • 9
  • 19
1

Ended up fixing it like this ( detect if browser if FF and if scrollbar is visible - if so then add 17px right margin - not pretty but it works )

EDIT - added basic fiddle and updated fiddle that fixes element's position in a case where the browser window is eventually zoomed (or resized) by user.

    $('#slideClick').toggle(function() {
        $(this).parent().animate( { right: '0px' }, {queue:false, duration: 500});
    }, function() {
        $(this).parent().animate( { right: '-290px' }, {queue:false, duration: 500});

        // If UA is firefox and vert scrollbar present
        if ( ( navigator.userAgent.toLowerCase().indexOf('firefox') > -1 ) && ( $(document).height() > $(window).height() ) ) {
            $('#slideOut').css('margin-right', '17px');
        }
    });
Stano
  • 8,749
  • 6
  • 30
  • 44
byronyasgur
  • 4,627
  • 13
  • 52
  • 96
0

Might be related to this question and how firefox handles the scrollbar width differently than webkit

Community
  • 1
  • 1
Duncan Beattie
  • 2,306
  • 17
  • 17
  • thanks ... I had a look ... maybe I'm wrong but I think they're different issues, maybe related or something. This seems to be something to do with jQuery. – byronyasgur May 16 '13 at 00:11