调用方法未定义

时间:2016-06-10 08:28:02

标签: javascript jquery modal-dialog



var ModalEffects = function(){

	function init() {

		var overlay = document.querySelector( '.md-overlay' );

		[].slice.call( document.querySelectorAll( '.md-trigger' ) ).forEach( function( el, i ) {

			var modal = document.querySelector( '#' + el.getAttribute( 'data-modal' ) ),
				close = modal.querySelector( '.md-close' );

			function removeModal( hasPerspective ) {
				classie.remove( modal, 'md-show' );

				if( hasPerspective ) {
					classie.remove( document.documentElement, 'md-perspective' );
				}
			}

			function removeModalHandler() {
				removeModal( classie.has( el, 'md-setperspective' ) ); 
			}

			el.addEventListener( 'click', function( ev ) {
				classie.add( modal, 'md-show' );
				overlay.removeEventListener( 'click', removeModalHandler );
				overlay.addEventListener( 'click', removeModalHandler );

				if( classie.has( el, 'md-setperspective' ) ) {
					setTimeout( function() {
						classie.add( document.documentElement, 'md-perspective' );
					}, 25 );
				}
			});

			close.addEventListener( 'click', function( ev ) {
				ev.stopPropagation();
				removeModalHandler();
			});

		} );

	}

{init : init};

})();




// CALL ModalEffects() HERE

    var slot1 = [
    '<img class="0" src="imgs/temp-coffee-1.jpg" alt="coffee pot icon">',
    '<img class="1" src="imgs/temp-tea-1.jpg" alt="coffee pot icon">',
    '<img class="2" src="imgs/temp-espresso-1.jpg" alt="coffee pot icon">'
    ];
    var slot2 = [
    '<img class="0" src="imgs/temp-coffee-1.jpg" alt="coffee pot icon">',
    '<img class="1" src="imgs/temp-tea-1.jpg" alt="coffee pot icon">',
    '<img class="2" src="imgs/temp-espresso-1.jpg" alt="coffee pot icon">'
    ];
    var slot3 = [
    '<img class="0" src="imgs/temp-coffee-1.jpg" alt="coffee pot icon">',
    '<img class="1" src="imgs/temp-tea-1.jpg" alt="coffee pot icon">',
    '<img class="2" src="imgs/temp-espresso-1.jpg" alt="coffee pot icon">'
    ];


    function GetRandomInt(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function Go(){
        AddSlots($('#slot_a'));
        AddSlots($('#slot_b'));
        AddSlots($('#slot_c'));
        resultA = MoveSlots($('#slot_a'));
        resultB = MoveSlots($('#slot_b'));
        resultC = MoveSlots($('#slot_c'));

        console.log( 'one ' + resultA + ' two ' + resultB + ' three ' + resultC );

        if(resultA == resultB && resultA == resultC ){
            // ModalEffects.init();
            // ModalEffects["init"]();
            // $('.md-modal').ModalEffects['init']();
            console.log(";alksdjf;laksjdf");
        } else {
          
            // CALL ModalEffects here...................
          
            ModalEffects.init();
            // ModalEffects["init"]();
            // $('.md-modal').ModalEffects['init']();
            // classie.add( '#modal-17', 'md-show' );
            // classie.add( '#modal-17', 'md-perspective' );
            // overlay.removeEventListener( 'click', removeModalHandler );
            // overlay.addEventListener( 'click', removeModalHandler );
        }

    }

    function MoveSlots(el){
        var time = 4500;
        time += Math.round(Math.random()*2000);
        el.stop(true,true);

        var randomArrayItem = GetRandomInt(0, 2);
        var currentMarginTop = parseInt(el.css('margin-top'));

        console.log(currentMarginTop);
        

        var marginTop = currentMarginTop + ((-90 * 100) - (randomArrayItem * 100 )); //change 100 to height placeholder
        console.log(marginTop);
        
        el.animate(
            {"margin-top":marginTop+"px"},
            {'duration' : time, 'easing' : "easeInOutQuint"}
        );   

        return randomArrayItem;
    }

    function AddSlots(el){

        for(i=0; i<200; i++){
            el.append("<div class='content'>" + slot1[0] + "</div>");
            el.append("<div class='content'>" + slot2[1] + "</div>");
            el.append("<div class='content'>" + slot3[2] + "</div>");
        }
    }
&#13;
&#13;
&#13;

我到处查看过问题,它告诉我通过以下方式调用ModalEffects:ModalEffects.init();但它很顽固,不会工作!我把我的尝试留在那里,所以你可以看到我尝试过的一切......

**代码没有运行,我只是想显示:) ** 我在下面发布了2个以评论分隔的脚本。

&#13;
&#13;
//MODAL EFFECTS SCRIPT:

var ModalEffects = (function() {

	function init() {

		var overlay = document.querySelector( '.md-overlay' );

		[].slice.call( document.querySelectorAll( '.md-trigger' ) ).forEach( function( el, i ) {

			var modal = document.querySelector( '#' + el.getAttribute( 'data-modal' ) ),
				close = modal.querySelector( '.md-close' );

			function removeModal( hasPerspective ) {
				classie.remove( modal, 'md-show' );

				if( hasPerspective ) {
					classie.remove( document.documentElement, 'md-perspective' );
				}
			}

			function removeModalHandler() {
				removeModal( classie.has( el, 'md-setperspective' ) ); 
			}

			el.addEventListener( 'click', function( ev ) {
				classie.add( modal, 'md-show' );
				overlay.removeEventListener( 'click', removeModalHandler );
				overlay.addEventListener( 'click', removeModalHandler );

				if( classie.has( el, 'md-setperspective' ) ) {
					setTimeout( function() {
						classie.add( document.documentElement, 'md-perspective' );
					}, 25 );
				}
			});

			close.addEventListener( 'click', function( ev ) {
				ev.stopPropagation();
				removeModalHandler();
			});

		} );

	}

	init();

})();


//SCRIPT WHERE I NEED TO CALL IT
var slot1 = [
    '<img class="0" src="imgs/temp-coffee-1.jpg" alt="coffee pot icon">',
    '<img class="1" src="imgs/temp-tea-1.jpg" alt="coffee pot icon">',
    '<img class="2" src="imgs/temp-espresso-1.jpg" alt="coffee pot icon">'
    ];
    var slot2 = [
    '<img class="0" src="imgs/temp-coffee-1.jpg" alt="coffee pot icon">',
    '<img class="1" src="imgs/temp-tea-1.jpg" alt="coffee pot icon">',
    '<img class="2" src="imgs/temp-espresso-1.jpg" alt="coffee pot icon">'
    ];
    var slot3 = [
    '<img class="0" src="imgs/temp-coffee-1.jpg" alt="coffee pot icon">',
    '<img class="1" src="imgs/temp-tea-1.jpg" alt="coffee pot icon">',
    '<img class="2" src="imgs/temp-espresso-1.jpg" alt="coffee pot icon">'
    ];


    function GetRandomInt(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function Go(){
        AddSlots($('#slot_a'));
        AddSlots($('#slot_b'));
        AddSlots($('#slot_c'));
        resultA = MoveSlots($('#slot_a'));
        resultB = MoveSlots($('#slot_b'));
        resultC = MoveSlots($('#slot_c'));

        console.log( 'one ' + resultA + ' two ' + resultB + ' three ' + resultC );

        if(resultA == resultB && resultA == resultC ){
            // ModalEffects.init();
            // ModalEffects["init"]();
            // $('.md-modal').ModalEffects['init']();
            console.log(";alksdjf;laksjdf");
        } else {
            
            // *** THIS IS WHERE I NEED THE MODAL TO POP UP... SAYING ModalEffects is undefined. I have scripts in right order too...
          
            ModalEffects.init();
            // ModalEffects["init"]();
            // $('.md-modal').ModalEffects['init']();
            // classie.add( '#modal-17', 'md-show' );
            // classie.add( '#modal-17', 'md-perspective' );
            // overlay.removeEventListener( 'click', removeModalHandler );
            // overlay.addEventListener( 'click', removeModalHandler );
        }

    }

    function MoveSlots(el){
        var time = 4500;
        time += Math.round(Math.random()*2000);
        el.stop(true,true);

        var randomArrayItem = GetRandomInt(0, 2);
        var currentMarginTop = parseInt(el.css('margin-top'));

        console.log(currentMarginTop);
        

        var marginTop = currentMarginTop + ((-90 * 100) - (randomArrayItem * 100 )); //change 100 to height placeholder
        console.log(marginTop);
        
        el.animate(
            {"margin-top":marginTop+"px"},
            {'duration' : time, 'easing' : "easeInOutQuint"}
        );   

        return randomArrayItem;
    }

    function AddSlots(el){

        for(i=0; i<200; i++){
            el.append("<div class='content'>" + slot1[0] + "</div>");
            el.append("<div class='content'>" + slot2[1] + "</div>");
            el.append("<div class='content'>" + slot3[2] + "</div>");
        }
    }
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
&#13;
&#13;

0 个答案:

没有答案