function loadCss(url) {
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = url;
document.getElementsByTagName("head")[0].appendChild(link);
}
(function () {
requirejs.config(
{
baseUrl: '',
paths: {
text:'vendors/require/text',
i18n:'vendors/require/i18n',
swiper:'vendors/swiper/swiper'
},
shim:{
'swiper':{exports:'swiper'}
}
}
);
define(['swiper'],function (aswiper) {
var cssUrl = "css/swiper.css";
loadCss(cssUrl);
var aswiper = new Swiper('.swiper-container', {
pagination: '.swiper-pagination',
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
paginationClickable: true,
spaceBetween: 30,
centeredSlides: true,
autoplay: 2500,
autoplayDisableOnInteraction: false
});
});
})();// JavaScript Document
转载请注明:谷谷点程序 » web前端require.js的简单使用方法【原创】