mirror of
https://github.com/a2nt/webpack-bootstrap-ui-kit.git
synced 2024-10-22 11:05:45 +02:00
UPD: Carousel
This commit is contained in:
parent
7c873e7c7f
commit
91ec8b538c
@ -48,6 +48,7 @@ export default ((W) => {
|
|||||||
return curEnv
|
return curEnv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
W.detectCSSScreenSize = detectCSSScreenSize
|
||||||
W.addEventListener(`${Events.LOADED}`, detectCSSScreenSize)
|
W.addEventListener(`${Events.LOADED}`, detectCSSScreenSize)
|
||||||
|
|
||||||
W.addEventListener(`${Events.RESIZE}`, detectCSSScreenSize)
|
W.addEventListener(`${Events.RESIZE}`, detectCSSScreenSize)
|
||||||
|
@ -31,5 +31,21 @@ funcs.getParents = (elem, selector) => {
|
|||||||
return parents
|
return parents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
funcs.ucwords = (strInitial) => {
|
||||||
|
let str = strInitial.toLowerCase();
|
||||||
|
const words = str.split(' ');
|
||||||
|
str = '';
|
||||||
|
for (var i = 0; i < words.length; i++) {
|
||||||
|
let word = words[i];
|
||||||
|
word = word.charAt(0).toUpperCase() + word.slice(1);
|
||||||
|
if (i > 0) { str = str + ' '; }
|
||||||
|
str = str + word;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
window.globalF = funcs
|
||||||
module.exports = funcs
|
module.exports = funcs
|
||||||
module.exports.default = funcs
|
module.exports.default = funcs
|
||||||
|
@ -4,4 +4,5 @@
|
|||||||
import './visibility'
|
import './visibility'
|
||||||
import './touch'
|
import './touch'
|
||||||
import './css-screen-size'
|
import './css-screen-size'
|
||||||
|
import './funcs'
|
||||||
import './main'
|
import './main'
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Events from '../_events'
|
import Events from '../_events'
|
||||||
|
import Consts from '../_consts'
|
||||||
import Carousel from 'bootstrap/js/src/carousel'
|
import Carousel from 'bootstrap/js/src/carousel'
|
||||||
|
|
||||||
const CarouselUI = ((window) => {
|
const CarouselUI = ((window) => {
|
||||||
@ -103,13 +104,25 @@ const CarouselUI = ((window) => {
|
|||||||
// fix animation glitch
|
// fix animation glitch
|
||||||
inner.style.left = '0px'
|
inner.style.left = '0px'
|
||||||
|
|
||||||
|
const getNumToDisplay = (el) => {
|
||||||
|
const screenSize = window.detectCSSScreenSize()
|
||||||
|
let curNum = parseInt(el.dataset['length'+window.globalF.ucwords(screenSize)]);
|
||||||
|
if(!curNum){
|
||||||
|
curNum = parseInt(el.dataset.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.min(curNum, numberOfItems)
|
||||||
|
}
|
||||||
|
|
||||||
const calculate = (entries) => {
|
const calculate = (entries) => {
|
||||||
const entry = entries[0]
|
const entry = entries[0]
|
||||||
const el = entry.target
|
const el = entry.target
|
||||||
const rect = entry.contentRect
|
const rect = entry.contentRect
|
||||||
const width = rect.width
|
//const width = rect.width
|
||||||
|
const width = el.querySelector('.carousel-inner-container').clientWidth
|
||||||
|
|
||||||
// const height = rect.height
|
// const height = rect.height
|
||||||
const numToDisplay = Math.min(parseInt(el.dataset.length), numberOfItems)
|
const numToDisplay = getNumToDisplay(el)
|
||||||
const itemWidth = width / numToDisplay
|
const itemWidth = width / numToDisplay
|
||||||
|
|
||||||
el.dataset.itemWidth = itemWidth
|
el.dataset.itemWidth = itemWidth
|
||||||
@ -121,7 +134,7 @@ const CarouselUI = ((window) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (numberOfItems === numToDisplay) {
|
if (numberOfItems === numToDisplay) {
|
||||||
el.classList.add('js-carousel-no-slide')
|
el.classList.add(`${NAME}-no-slide`)
|
||||||
carousel.pause()
|
carousel.pause()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -150,7 +163,7 @@ const CarouselUI = ((window) => {
|
|||||||
|
|
||||||
el.addEventListener('slide.bs.carousel', (e) => {
|
el.addEventListener('slide.bs.carousel', (e) => {
|
||||||
// infinite scroll
|
// infinite scroll
|
||||||
const numToDisplay = Math.min(parseInt(el.dataset.length), numberOfItems)
|
const numToDisplay = getNumToDisplay(el)
|
||||||
console.log(`.${NAME}: ${e.to} ${numberOfItems / 2}`);
|
console.log(`.${NAME}: ${e.to} ${numberOfItems / 2}`);
|
||||||
|
|
||||||
if(numberOfItems - numToDisplay < e.to){
|
if(numberOfItems - numToDisplay < e.to){
|
||||||
@ -177,7 +190,7 @@ const CarouselUI = ((window) => {
|
|||||||
el.classList.add(`${NAME}-multislide-active`)
|
el.classList.add(`${NAME}-multislide-active`)
|
||||||
} else {
|
} else {
|
||||||
if (items.length === 1) {
|
if (items.length === 1) {
|
||||||
el.classList.add('js-carousel-no-slide')
|
el.classList.add(`${NAME}-no-slide`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,14 +118,14 @@ $carousel-slide-img-loading-max-height: 25vh !default;
|
|||||||
|
|
||||||
.carousel-inner {
|
.carousel-inner {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: row;
|
||||||
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
transition: all 1s ease;
|
transition: all 1s ease;
|
||||||
@media (min-width: map-get($grid-breakpoints, "md")) {
|
/*@media (min-width: map-get($grid-breakpoints, "md")) {
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user