CSSgirl
CSSgirl

Reputation: 132

Removing body class onClose with simplemodal

I'm using Eric Martin's SimpleModal plugin for a page that has several different modals. One of the modal's has a different height and width than the others on the page, so I've added a class to the body when the link for the bigger modal is clicked. This works fine as far as controlling the style of that particular modal. But, removing the class when that modal is closed is an issue. I originally tried to use the onClose function, but I didn't have any success. So I tried to attach removeClass when you click the close link, but it's not removing the body class? Help?

Basically I want to do something like this to ensure that the class is removed when the modal is closed through any of the built in methods using the onClose function:

$("#element-id").modal({onClose: function () {
    $('body').removeClass('classname');
}});

Thanks in advance!

Upvotes: 2

Views: 1063

Answers (1)

Lian
Lian

Reputation: 2357

Try this:

$('#sample').modal({
    onOpen: function(dialog) {
        $('body').addClass('classname');
        dialog.overlay.show();
        dialog.container.show();
        dialog.data.show();
    },
    onClose: function(dialog) {
        $('body').removeClass('classname');
        $.modal.close()
    }
});​

If you want some smooth animation, you'll have to change .show() to something else. Docs here.

Upvotes: 0

Related Questions