简体   繁体   中英

es6 import - fancybox is not a function

Im trying to use fancybox in a project, however when importing it, I still get an error (fancybox is not a function) - This is what im doing:

import $ from 'jquery';
import jQuery from 'jquery'; 
import 'fancybox'; 

And later on, im trying to do:

// export jQuery for others scripts to use /inline scripts in some controls
window.$ = $;
window.jQuery = jQuery;

$(".list__item--img").fancybox({
'titlePosition': 'inside',
'transitionIn': 'none',
'transitionOut': 'none',
"padding": 0,
"overlayOpacity": 0.8,
"overlayColor": "#000",
"autoDimensions": false,
"width": 355,
"height": 190,
"showCloseButton": false
});

If you are using the fancybox npm module it looks like you need to pass your jquery object to it.

fancybox($) // or fancybox(jQuery)

This is where fancybox attaches itself to the jquery object.

Otherwise there is always the old fashion of way of including the second script tag on the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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