简体   繁体   English

变形按钮概念在Internet Explorer IE 9中不起作用

[英]Morphing buttons concept not working in internet explorer IE 9

Im using the "morphing buttons concept" from here http://tympanus.net/codrops/2014/05/12/morphing-buttons-concept/ 我在这里使用的是“变形按钮概念” http://tympanus.net/codrops/2014/05/12/morphing-buttons-concept/

The problem is that its not working in IE9. 问题是它在IE9中不起作用。 The error says: if( ev.target !== this ) {exception} undefined or null 错误显示:if(ev.target!== this){exception}未定义或为null

I found this on stackoverflow https://stackoverflow.com/a/1143236/3310123 我在stackoverflow https://stackoverflow.com/a/1143236/3310123上找到了

But i cant seem to implement it to the uiMorphingButton_fixed.js that comes with "morphing buttons" 但我似乎无法将其实现为带有“变形按钮”的uiMorphingButton_fixed.js

Does anyone know what to change to make it work in IE 9 (its working in 10 and 11)? 有谁知道更改以使其能够在IE 9中工作(在10和11中工作)?

The if( ev.target !== this ) can be found on line 90 in uiMorphingButton_fixed.js: var self = this, onEndTransitionFn = function( ev ) { if( ev.target !== this ) return false; if(ev.target!== this)可以在uiMorphingButton_fixed.js的第90行找到:var self = this,onEndTransitionFn = function(ev){if(ev.target!== this)返回false;

            if( support.transitions ) {
                // open: first opacity then width/height/left/top
                // close: first width/height/left/top then opacity
                if( self.expanded && ev.propertyName !== 'opacity' || !self.expanded && ev.propertyName !== 'width' && ev.propertyName !== 'height' && ev.propertyName !== 'left' && ev.propertyName !== 'top' ) {
                    return false;
                }
                this.removeEventListener( transEndEventName, onEndTransitionFn );
            }
            self.isAnimating = false;

            // callback
            if( self.expanded ) {
                // remove class active (after closing)
                classie.removeClass( self.el, 'active' );
                self.options.onAfterClose();
            }
            else {
                self.options.onAfterOpen();
            }

            self.expanded = !self.expanded;
        };

    if( support.transitions ) {
        this.contentEl.addEventListener( transEndEventName, onEndTransitionFn );
    }
    else {
        onEndTransitionFn();
    }

The problem seems to be here: 问题似乎在这里:

support.transitions is returning false , so onEndTransitionFn() is run (in the else at the end). support.transitions返回false ,因此onEndTransitionFn()运行(在else末尾)。

That sends no params to the onEndTransitionFn function. 这不会向onEndTransitionFn函数发送任何参数。

But that function expects a parameter, and expects that parameter to have a target attribute. 但是该函数需要一个参数,并希望该参数具有target属性。 So calling it with no params will create the error you are seeing. 因此,在不使用参数的情况下调用它会产生您所看到的错误。

Maybe remove the else after the last if statement. 也许在最后一个if语句之后删除else。 But there's no way round the fact that support.transitions will still be false, so the morphing probably still won't work. 但是,无法绕过support.transitions仍然为false的事实,因此变形可能仍然不起作用。

I got the .js updated so it now works on IE9 aswell. 我更新了.js,因此现在也可以在IE9上使用。 Replace the whole uiMorphingButton_fixed.js with this: 将整个uiMorphingButton_fixed.js替换为:

Hope this help someone :) 希望这可以帮助某人:)

/** * uiMorphingButton_fixed.js v1.0.0 * http://www.codrops.com * Licensed under the MIT license. / ** * uiMorphingButton_fixed.js v1.0.0 * http://www.codrops.com *根据MIT许可证获得许可。 * http://www.opensource.org/licenses/mit-license.php * Copyright 2014, Codrops */ * http://www.opensource.org/licenses/mit-license.php *版权所有2014,Codrops * /

    ;( function( window ) {

    'use strict';

    var transEndEventNames = {
            'WebkitTransition': 'webkitTransitionEnd',
            'MozTransition': 'transitionend',
            'OTransition': 'oTransitionEnd',
            'msTransition': 'MSTransitionEnd',
            'transition': 'transitionend'
        },
        transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ],
        support = { transitions : Modernizr.csstransitions };

    function extend( a, b ) {
        for( var key in b ) { 
            if( b.hasOwnProperty( key ) ) {
                a[key] = b[key];
            }
        }
        return a;
    }

    function UIMorphingButton( el, options ) {
        this.el = el;
        this.options = extend( {}, this.options );
        extend( this.options, options );
        this._init();
    }

    UIMorphingButton.prototype.options = {
        closeEl : '',
        onBeforeOpen : function() { return false; },
        onAfterOpen : function() { return false; },
        onBeforeClose : function() { return false; },
        onAfterClose : function() { return false; }
    }

    UIMorphingButton.prototype._init = function() {
        // the button
        this.button = this.el.querySelector( 'button' );
        // state
        this.expanded = false;
        // content el
        this.contentEl = this.el.querySelector( '.morph-content' );
        // init events
        this._initEvents();
    }

    UIMorphingButton.prototype._initEvents = function() {
        var self = this;
        // open
        this.button.addEventListener( 'click', function() { 
            if(support.transitions) {
              self.toggle(); 
            } else {
              classie.addClass( self.el, 'active open' );
            } 
        } );
        // close
        if( this.options.closeEl !== '' ) {
            var closeEl = this.el.querySelector( this.options.closeEl );
            if( closeEl ) {
                closeEl.addEventListener( 'click', function() { 
                    if(support.transitions) {
                      self.toggle(); 
                    } else {
                      classie.removeClass( self.el, 'active open' );
                    } 
                } );
            }
        }
    }

    UIMorphingButton.prototype.toggle = function() {
        if( this.isAnimating ) return false;

        // callback
        if( this.expanded ) {
            this.options.onBeforeClose();
        }
        else {
            // add class active (solves z-index problem when more than one button is in the page)
            classie.addClass( this.el, 'active' );
            this.options.onBeforeOpen();
        }

        this.isAnimating = true;

        var self = this,
            onEndTransitionFn = function( ev ) {
                if( ev.target !== this ) return false;

                if( support.transitions ) {
                    // open: first opacity then width/height/left/top
                    // close: first width/height/left/top then opacity
                    if( self.expanded && ev.propertyName !== 'opacity' || !self.expanded && ev.propertyName !== 'width' && ev.propertyName !== 'height' && ev.propertyName !== 'left' && ev.propertyName !== 'top' ) {
                        return false;
                    }
                    this.removeEventListener( transEndEventName, onEndTransitionFn );
                }
                self.isAnimating = false;

                // callback
                if( self.expanded ) {
                    // remove class active (after closing)
                    classie.removeClass( self.el, 'active' );
                    self.options.onAfterClose();
                }
                else {
                    self.options.onAfterOpen();
                }

                self.expanded = !self.expanded;
            };

        if( support.transitions ) {
            this.contentEl.addEventListener( transEndEventName, onEndTransitionFn );
        }
        else {
            onEndTransitionFn();
        }

        // set the left and top values of the contentEl (same like the button)
        var buttonPos = this.button.getBoundingClientRect();
        // need to reset
        classie.addClass( this.contentEl, 'no-transition' );
        this.contentEl.style.left = 'auto';
        this.contentEl.style.top = 'auto';

        // add/remove class "open" to the button wraper
        setTimeout( function() { 
            self.contentEl.style.left = buttonPos.left + 'px';
            self.contentEl.style.top = buttonPos.top + 'px';

            if( self.expanded ) {
                classie.removeClass( self.contentEl, 'no-transition' );
                classie.removeClass( self.el, 'open' );
            }
            else {
                setTimeout( function() { 
                    classie.removeClass( self.contentEl, 'no-transition' );
                    classie.addClass( self.el, 'open' ); 
                }, 25 );
            }
        }, 25 );
    }

    // add to global namespace
    window.UIMorphingButton = UIMorphingButton;

})( window );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM