0

To condition something in jquery for IE7, I read here it's best to use this in the <HEAD>:

<!--[if IE 7]>         <html class="ie7"> <![endif]-->

Now, out of the following code,

I want transition: "elastic", to be there only if it's ie7:

$(document).ready(function() {
    $(".cbox").click(function(e) {
        e.preventDefault();
        $.colorbox({
            transition: "elastic",
            overlayClose: false,
            opacity: 0.8,
        });
        return false
    })
});

So I tried doing something like:

$(document).ready(function() {
    $(".cbox").click(function(e) {
        e.preventDefault();
        $.colorbox({
            if ($('html').hasClass('ie7') {transition: "elastic",}
            overlayClose: false,
            opacity: 0.8,
        });
        return false
    })
});

But it's not the way to do this I guess... how should this be done?

Community
  • 1
  • 1
rockyraw
  • 1,125
  • 2
  • 15
  • 36

3 Answers3

2

If the html element definitely has that class on it, the proper way to structure your options for the colorbox would be something like:

$(document).ready(function() {
    $(".cbox").click(function(e) {
        e.preventDefault();
        var opt = {
            overlayClose: false,
            opacity: 0.8
        };
        if ($('html').hasClass('ie7'))        
            opt.transition = 'elastic';
        $.colorbox(opt);
        return false
    });
});
James Thorpe
  • 31,411
  • 5
  • 72
  • 93
2

You can use a ternary operator to dynamically set the transition

transition: $("html").hasClass("ie7") ? "elastic":"none",

Note according to the documentation the default value is elastic so really you do not need to set a transition at all, unless you want non-ie7 browsers to have some other transition type.

Patrick Evans
  • 41,991
  • 6
  • 74
  • 87
0

Very straight forward answer to this, just read carefully this link : jQuery.browser

jQuery.browser property was removed in jQuery 1.9 and is available only through the jQuery.migrate plugin.

The best practice when you do have jQuery 1.9 or earlier version is that you should use this approach for specific browser detection.

Pradip R.
  • 450
  • 1
  • 14
  • 31