Question

I am experiencing the Firefox bug (overflow property not implemented on fieldset) when using the slide up/down function within jquery.

So I want to:

  1. add an inner div via jquery on click
  2. slide this div up/down
  3. remove the inner div

This is what I have so far:

var $searchBtn = $form.find('.search-reveal');          
$searchBtn.click(function(e){               
    var $this = $(this),
        $fieldset = $this.next();

    $this.toggleClass('open');

    // FIX Firefox bug - https://bugzilla.mozilla.org/show_bug.cgi?id=261037
    var $fieldsetInner = $fieldset.children().eq(0)
    if(!$fieldsetInner.is("div")){
        $fieldsetInner = $fieldset.innerWrap("<div></div>");
    }

    if($this.hasClass('open')){
        $fieldset.addClass('open');
        $form.addClass('active');
        $fieldsetInner.slideDown('fast', 'easeInQuad', function(){
            // REMOVE Firefox bug fix
        });
    } else {
        $fieldsetInner.slideUp('fast', 'easeOutQuad', function(){
            $fieldset.removeClass('open');
            $form.removeClass('active');
            // REMOVE Firefox bug fix
        });
    }

    e.preventDefault();
});

I have tried this suggest fix using display: table-column but this made no difference.

Was it helpful?

Solution

I wrote a standalone jQuery function to do this:

$.fn.fieldsetSlideToggle = function (speed) {
    var $this = $(this),
        $inner = $this.children().eq(0),
        display = $this.css('display'),
        slideSpeed = speed ? speed : 'fast';

    // 1. Check if first child of fieldset is <div>
    // 2. Wrap contents in <div> if not
    if (!$inner.is("div")) {
        $inner = $('<div />').html($this.html());
        $this.empty().append($inner);
    }

    // 3. SlideToggle on div
    if (display == 'none') {
        $this.show();
        $inner.hide().slideDown(slideSpeed, function () {
            $this.html($inner.html());
        });
    } else {
        $inner.slideUp(slideSpeed, function () {
            $this.html($inner.html()).hide();
        });
    }
}

Fiddle: http://jsfiddle.net/tbDRu/6/. Click on the button to slideup/down the fieldset.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top