2014-10-28 70 views

回答

0

首先建立在HTML文件中emtry点:

<!DOCTYPE html> 
<html> 
    <body> 
    <script data-main="entrypoint" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.min.js"></script> 
    </body> 
</html> 

然后在entrypoint.js可以配置jQuery和荡气回肠弹出:

require.config({ 
    paths : { 
    jquery : '//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min', 
    magnificpopup : 'path/to/magnific-popup.min', 
    }, 
    shim: { 
    'magnificpopup': ['jquery'] 
    } 
}); 

require([ 'popuptest' ], function(popuptest) { 
    popuptest.show(); 
}); 

最后,popuptest.js我们可以打开一个youtube弹出像这样:

define(['jquery', 'magnificpopup'], function($, magnificpopup) { 
    return { 
    show: function() { 
     $.magnificPopup.open({ 
     items: { 
      src: 'https://www.youtube.com/watch?v=btPJPFnesV4' 
     }, 
     type: 'iframe', 
     iframe: { 
      cursor: null, 
      titleSrc: function(item) { 
      return 'Video title'; 
      }, 
      patterns: { 
      youtube_short: { 
       index: 'youtu.be/', 
       id: 'youtu.be/', 
       src: '//www.youtube.com/embed/%id%?autoplay=1' 
      } 
      } 
     } 
     }); 
    } 
    }); 
}); 

希望这会有所帮助。