Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle smaller when loaded in hidden div #106

Open
Voorsie opened this issue Mar 7, 2016 · 2 comments
Open

Toggle smaller when loaded in hidden div #106

Voorsie opened this issue Mar 7, 2016 · 2 comments

Comments

@Voorsie
Copy link

Voorsie commented Mar 7, 2016

When using toggles that shown after showing a div (that was hidden initially), the toggle is smaller than normal.

When removing the initial 'hidden state', the toggles are the same size as expected.

Check this JSFiddle for a 'working' example

@nietha
Copy link

nietha commented Apr 14, 2016

I have fixed this issue by using the outerwidth trick by cloning the hidden element

var width = this.options.width || Math.max($toggleOn.outerWidth(), $toggleOff.outerWidth()) + ($toggleHandle.outerWidth() / 2)

    // outerwidth fix for hidden elements
    if (width == 0) {
        width = this.options.width || Math.max(getOuterWidth($toggleOn), getOuterWidth($toggleOff)) + (getOuterWidth($toggleHandle) / 2)            
    }

function getOuterWidth(obj) {
if ($(obj).length == 0) {
return false;
}

    var clone = obj.clone();
    clone.css({
        visibility: 'hidden',
        width: '',
        height: '',
        maxWidth: '',
        maxHeight: ''
    });
    $('body').append(clone);
    var width = clone.outerWidth();
    clone.remove();
    return width;
}

@GarethBlain
Copy link

I have used a modified version of this to create a pull request...
#114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants