最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does my JQuery fading slider not work on any IE type? - Stack Overflow

programmeradmin0浏览0评论

My JQuery slider does not work in IE(in any documentmode). How could I fix this? My code slides down a div of text after a button is pressed(it fades in nicely too). The IE console gives me this error: "Object doesn't support property or method 'fadingSlideToggle'".

(function ($) {
    $.fn.fadingSlideToggle = function ($el, options) {
        var defaults = {
            duration: 500,
            easing: 'swing',
            trigger: 'click'
        };

        var settings = $.extend({}, defaults, options)
        $selector = $(this).selector;

        return this.each(function () {
            var $this = $(this);

            $(document).on(settings.trigger, $selector, function (e) {
                e.preventDefault();
                if ($($el).css('display') == 'none') {
                    $($el).animate({
                        opacity: 'toggle',
                        height: 'toggle'
                    }, settings.duration, settings.easing);
                } else {
                    $($el).animate({
                        opacity: 'toggle',
                        height: 'toggle'
                    }, settings.duration, settings.easing);
                }
            });
        });
    };
})(jQuery);

I wonder which part is not supported, and how to fix it. Thank you a lot!

EDIT: Here is the code where I call the function(it works on firefox and chrome):

 <button class="btn-custom btn-lg"" id="clickedEl"><span>Why rate/review websites?</span>        </button></br>
 <nav role="navigation" id="toggleEl">/*non relevant html*/</nav>

The rest of the javascript:

  $(function(){
   $('#clickedEl').fadingSlideToggle('#toggleEl');
  });

The JSFiddle that does not work in IE:

My JQuery slider does not work in IE(in any documentmode). How could I fix this? My code slides down a div of text after a button is pressed(it fades in nicely too). The IE console gives me this error: "Object doesn't support property or method 'fadingSlideToggle'".

(function ($) {
    $.fn.fadingSlideToggle = function ($el, options) {
        var defaults = {
            duration: 500,
            easing: 'swing',
            trigger: 'click'
        };

        var settings = $.extend({}, defaults, options)
        $selector = $(this).selector;

        return this.each(function () {
            var $this = $(this);

            $(document).on(settings.trigger, $selector, function (e) {
                e.preventDefault();
                if ($($el).css('display') == 'none') {
                    $($el).animate({
                        opacity: 'toggle',
                        height: 'toggle'
                    }, settings.duration, settings.easing);
                } else {
                    $($el).animate({
                        opacity: 'toggle',
                        height: 'toggle'
                    }, settings.duration, settings.easing);
                }
            });
        });
    };
})(jQuery);

I wonder which part is not supported, and how to fix it. Thank you a lot!

EDIT: Here is the code where I call the function(it works on firefox and chrome):

 <button class="btn-custom btn-lg"" id="clickedEl"><span>Why rate/review websites?</span>        </button></br>
 <nav role="navigation" id="toggleEl">/*non relevant html*/</nav>

The rest of the javascript:

  $(function(){
   $('#clickedEl').fadingSlideToggle('#toggleEl');
  });

The JSFiddle that does not work in IE: http://jsfiddle/3ymvv

Share Improve this question edited May 27, 2014 at 7:14 mfirdaus 4,5921 gold badge26 silver badges26 bronze badges asked May 22, 2014 at 19:09 user3353408user3353408 4
  • Could you also post the usage code? – Sean Johnson Commented May 26, 2014 at 19:21
  • 2 Could you please verify that there's not multiple calls to include the jQuery library? you could be overriding your modified one with an empty copy. – scragar Commented May 26, 2014 at 19:23
  • the html you appended does not show the code where you call the jQuery Plugin – Luke Commented May 26, 2014 at 20:07
  • @Luke My bad, I edited again. – user3353408 Commented May 26, 2014 at 20:12
Add a ment  | 

5 Answers 5

Reset to default 8 +25

The problem seems to e from jQuery 1.10.1 (#13936 #13980). Here's the error we got :

Access Denied - jQuery-1.10.1.js, line : 1513, column : 2

And the related lines :

// Support: IE>8
// If iframe document is assigned to "document" variable and if iframe has been reloaded,
// IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
if ( parent && parent.frameElement ) { // :1513   
    parent.attachEvent( "onbeforeunload", function() {
        setDocument();
    });
}

This happens early, and possibly prevent your script to be loaded.

Update jQuery to the 1.11.0 version (or more) and you'll see it works.

When I was testing in windows XP, ie8 and an old version of firefox exhibited the same behaviour (it suddenly appearing when #clickeEl first clicked) . Removing the <nav> element and just using the <ul> element seemed to fix it. Then I realized that the problem was the tag <nav> which is unknown to ie8 and firefox. As described in this article, the browsers do not know that <nav> is a block element. So adding

nav { display:block }

fixed the problem on me in ie8 in windows xp.

Demo

Actually, not sure how patible this is, but it seems the plugin is doing some unnecessary stuff, since it's using jQuery. So I added it a bit below. (Mostly it bothered me you have to set display:none in CSS with an ID instead of the plugin itself.

Proposed Changes

Here we clearly do not know where the problem might be.

  1. Your code looks fine.
  2. Please show us the code where you use your plugin
  3. There where you use your plugin, check if the plugin is defined console.log($.fn.fadingSlideToggle)
  4. check that the object you are calling your plugin on is actually a valid jQuery Object. console.log(obj instanceof jQuery) or (!!obj.jquery && typeof obj.jquery === "string")

a jquery object usualy has a property called jquery that has the current jQuery version in it. Also the jquery object is usually an instance of the jQuery Object itself. But keep in mind it is possible that using .noconflict() there is no global variable jQuery or $

The problem is the jQuery loading in the fiddle. Just load jQuery from a CDN and then initiate your plugin.

<script src="//ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
  // your plugin
</script>

Now it works fine in IE 8+.

Do you by any chance have a html element with the id of fadingSlideToggle? That could be the issue as explained here: https://stackoverflow./a/14003088/561957

发布评论

评论列表(0)

  1. 暂无评论