Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <style>
- #adoric_smartbox_870f53c7e844d .adoric_element.element-embed.responsive-carousel {
- width: auto !important;
- height: auto !important;
- position: absolute !important;
- left: 50% !important;
- transform: translate(-50%, 0) !important;
- top: 0 !important;
- }
- #adoric_smartbox_870f53c7e844d .ant-carousel {
- top: -30px;
- margin: 50px auto;
- padding-top: 10px;
- padding-bottom: 10px;
- border: 1px solid #ccd;
- background-color: white;
- width: auto;
- position: relative;
- flex-direction: column;
- justify-content: center;
- display: flex;
- }
- @media screen and (min-width: 911px) {
- #adoric_smartbox_870f53c7e844d .ant-carousel {
- width: 810px;
- height: 266px;
- }
- }
- @media screen and (min-width: 641px) and (max-width: 910px) {
- #adoric_smartbox_870f53c7e844d .ant-carousel {
- width: 540px;
- height: 266px;
- }
- }
- @media screen and (max-width: 640px) {
- #adoric_smartbox_870f53c7e844d .ant-carousel {
- width: 270px;
- height: 266px;
- }
- }
- #adoric_smartbox_870f53c7e844d.ant-carousel-display-none {
- display: none;
- }
- #adoric_smartbox_870f53c7e844d .ant-carousel-element {
- width: 270px;
- text-align: center;
- display: block;
- flex: 0 0 auto;
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- #adoric_smartbox_870f53c7e844d .ant-carousel-hider {
- overflow: hidden;
- }
- #adoric_smartbox_870f53c7e844d .ant-carousel-list {
- width: auto;
- margin: 0;
- padding: 0;
- list-style-type: none;
- display: flex;
- flex-direction: row;
- }
- #adoric_smartbox_870f53c7e844d .carousel-item-customm-btn {
- width: 220px !important;
- font-size: 13px !important;
- padding: 20px !important;
- }
- #adoric_smartbox_870f53c7e844d .carousel-item-customm-out-of-stock {
- background-color: transparent !important;
- color: rgb(52 48 61) !important;
- border: rgb(52 48 61) !important;
- pointer-events: none !important;
- }
- #adoric_smartbox_870f53c7e844d .carousel-item-customm-out-of-stock::after {
- display: none !important;
- }
- #adoric_smartbox_870f53c7e844d div.ant-carousel-arrow-left {
- width: 22px;
- height: 40px;
- position: absolute;
- cursor: pointer;
- opacity: 0.6;
- z-index: 32;
- left: -40px;
- top: 40%;
- display: block;
- background: url(https://storage.googleapis.com/adoric-user-images/956c05bf-3272-4205-a333-8384eb288460.svg) center/cover no-repeat;
- }
- #adoric_smartbox_870f53c7e844d div.ant-carousel-arrow-right {
- width: 22px;
- height: 40px;
- position: absolute;
- cursor: pointer;
- opacity: 0.6;
- z-index: 32;
- right: -40px;
- top: 40%;
- display: block;
- background: url(https://storage.googleapis.com/adoric-user-images/8c68a159-2b08-4116-8824-4f278540e091.svg) center/cover no-repeat;
- }
- #adoric_smartbox_870f53c7e844d div.ant-carousel-arrow-left:hover {
- opacity: 1.0;
- }
- #adoric_smartbox_870f53c7e844d div.ant-carousel-arrow-right:hover {
- opacity: 1.0;
- }
- #adoric_smartbox_870f53c7e844d div.ant-carousel-dots {
- width: 100%;
- height: auto;
- position: absolute;
- left: 0;
- bottom: -30px;
- z-index: 30;
- text-align: center;
- display: none;
- }
- #adoric_smartbox_870f53c7e844d span.ant-dot {
- width: 10px;
- height: 10px;
- margin: 5px 7px;
- padding: 0;
- display: inline-block;
- background-color: #BBB;
- border-radius: 5px;
- cursor: pointer;
- }
- </style>
- <div class="ant-carousel">
- <div class="ant-carousel-hider">
- <div class="ant-carousel-list"></div>
- </div>
- <div class="ant-carousel-arrow-left"></div>
- <div class="ant-carousel-arrow-right"></div>
- <div class="ant-carousel-dots"></div>
- </div>
- <script>
- (function() {
- (function() {
- const productsArr = [];
- for (let productItem = 1; productItem <= 8; productItem++) {
- productsArr.push({
- 'title': `title ${productItem}`,
- 'description': `description ${productItem}`,
- 'price': `price ${productItem}`
- });
- }
- let out = '';
- for (let i of productsArr) {
- out += `<div class="ant-carousel-element"><img src="https://apod.nasa.gov/apod/image/1310/IMG_0228dakotalapse.jpg" width="200px" height="200px"><div>${i.title}</div><div>${i.description}</div><div>${i.price}</div></div>`;
- }
- document.querySelector('.ant-carousel-list').innerHTML = out;
- carousel();
- })();
- function carousel() {
- /* Carousel elements */
- const CRSL_CONTAINER = document.querySelector('.ant-carousel');
- const CRSL_LIST = CRSL_CONTAINER.querySelector('.ant-carousel-list');
- const CRSL_ITEMS = CRSL_LIST.querySelectorAll('.ant-carousel-element');
- const CRSL_FIRST_ITEM = CRSL_LIST.querySelector('.ant-carousel-element');
- const LEFT_ARROW = CRSL_CONTAINER.querySelector('div.ant-carousel-arrow-left');
- const RIGHT_ARROW = CRSL_CONTAINER.querySelector('div.ant-carousel-arrow-right');
- const DOTS_INDICATOR = CRSL_CONTAINER.querySelector('div.ant-carousel-dots'); /* carousel functionality */
- const CAROUSEL_PARAMETERS = {
- elemVisible: 1,
- loop: true,
- auto: true,
- interval: 8000,
- speed: 750,
- touch: true,
- arrows: true,
- dots: true,
- vertical: false,
- quantityItemVertical: 3
- }; /* element quantity */
- let elemCount = CRSL_ITEMS.length; /* visible dots quantity */
- let dotsVisible = elemCount;
- let elemStyle = window.getComputedStyle(CRSL_FIRST_ITEM); /* element width with margins */
- let elemWidth = parseInt(elemStyle.width) + parseInt(elemStyle.marginLeft) + parseInt(elemStyle.marginRight);
- let currentElement = 0;
- let currentOffset = 0;
- let touchPrev = true;
- let touchNext = true;
- let autoScroll;
- let DOTS_INDICATOR_All; /* create crsl functionality */
- (function() {
- let xTouch, yTouch, xDiff, yDiff, stTime, mvTime;
- let bgTime = getTime(); /* disable navigation */
- if (elemCount <= CAROUSEL_PARAMETERS.elemVisible) {
- CAROUSEL_PARAMETERS.auto = false;
- CAROUSEL_PARAMETERS.touch = false;
- CAROUSEL_PARAMETERS.arrows = false;
- CAROUSEL_PARAMETERS.dots = false;
- LEFT_ARROW.style.display = 'none';
- RIGHT_ARROW.style.display = 'none'
- }; /* if crsl is not infinite */
- if (!CAROUSEL_PARAMETERS.loop) {
- dotsVisible = elemCount - CAROUSEL_PARAMETERS.elemVisible + 1;
- LEFT_ARROW.style.display = 'none';
- touchPrev = false;
- CAROUSEL_PARAMETERS.auto = false;
- } /* crsl auto run */
- else if (CAROUSEL_PARAMETERS.auto) {
- setAutoScroll();
- CRSL_LIST.addEventListener('mouseenter', function() {
- clearInterval(autoScroll)
- }, false);
- CRSL_LIST.addEventListener('mouseleave', setAutoScroll, false)
- }; /* crsl on touch event */
- if (CAROUSEL_PARAMETERS.touch) {
- CRSL_LIST.addEventListener('touchstart', function(e) {
- xTouch = parseInt(e.touches[0].clientX);
- yTouch = parseInt(e.touches[0].clientY);
- stTime = getTime()
- }, false);
- CRSL_LIST.addEventListener('touchmove', function(e) {
- if (!xTouch || !yTouch) {
- return;
- }
- xDiff = xTouch - parseInt(e.touches[0].clientX);
- yDiff = yTouch - parseInt(e.touches[0].clientY);
- mvTime = getTime();
- if (Math.abs(xDiff) > 15 && Math.abs(xDiff) > Math.abs(yDiff) && mvTime - stTime < 75) {
- stTime = 0;
- if (touchNext && xDiff > 0) {
- bgTime = mvTime;
- elemNext();
- } else if (touchPrev && xDiff < 0) {
- bgTime = mvTime;
- elemPrev();
- }
- }
- }, false)
- }; /* crsl on vertical event */
- if (CAROUSEL_PARAMETERS.vertical) {
- const WIDTH_ITEM = 270;
- const CURRENT_WIDTH = WIDTH_ITEM * CAROUSEL_PARAMETERS.quantityItemVertical + 'px';
- let styleDirection = document.createElement("style");
- styleDirection.innerText = `.adoric_element.element-embed.responsive-carousel, .ant-carousel-element{transform: rotate(-90deg);} .ant-carousel{transform: rotate(90deg); width: ${CURRENT_WIDTH} !important;}`;
- document.body.appendChild(styleDirection);
- }; /* crsl on arrow click event */
- if (CAROUSEL_PARAMETERS.arrows) {
- if (!CAROUSEL_PARAMETERS.loop) {
- CRSL_LIST.style.cssText = 'transition:margin ' + CAROUSEL_PARAMETERS.speed + 'ms ease;';
- }
- LEFT_ARROW.addEventListener('click', function() {
- let fnTime = getTime();
- if (fnTime - bgTime > CAROUSEL_PARAMETERS.speed) {
- bgTime = fnTime;
- elemPrev();
- }
- }, false);
- RIGHT_ARROW.addEventListener('click', function() {
- let fnTime = getTime();
- if (fnTime - bgTime > CAROUSEL_PARAMETERS.speed) {
- bgTime = fnTime;
- elemNext();
- }
- }, false)
- } else {
- LEFT_ARROW.style.display = 'none';
- RIGHT_ARROW.style.display = 'none'
- }; /* create dots navigation */
- if (CAROUSEL_PARAMETERS.dots) {
- let sum = '';
- let diffNum;
- for (let i = 0; i < dotsVisible; i++) {
- sum += '<span class="ant-dot"></span>';
- };
- DOTS_INDICATOR.innerHTML = sum;
- DOTS_INDICATOR_All = CRSL_CONTAINER.querySelectorAll('span.ant-dot'); /* dot click event */
- for (let n = 0; n < dotsVisible; n++) {
- DOTS_INDICATOR_All[n].addEventListener('click', function() {
- diffNum = Math.abs(n - currentElement);
- if (n < currentElement) {
- bgTime = getTime();
- elemPrev(diffNum);
- } else if (n > currentElement) {
- bgTime = getTime();
- elemNext(diffNum);
- }
- }, false);
- }; /* first dot is off other are active */
- dotOff(0);
- for (let i = 1; i < dotsVisible; i++) {
- dotOn(i);
- }
- }
- function getTime() {
- return new Date().getTime();
- };
- function setAutoScroll() {
- autoScroll = setInterval(function() {
- let fnTime = getTime();
- if (fnTime - bgTime + 10 > CAROUSEL_PARAMETERS.interval) {
- bgTime = fnTime;
- elemNext();
- }
- }, CAROUSEL_PARAMETERS.interval)
- };
- })();
- function elemPrev(num) {
- num = num || 1;
- if (CAROUSEL_PARAMETERS.dots) {
- dotOn(currentElement);
- }
- currentElement -= num;
- if (currentElement < 0) {
- currentElement = dotsVisible - 1;
- }
- if (CAROUSEL_PARAMETERS.dots) {
- dotOff(currentElement);
- } /* move carousel to the right side. NOT Infinite carousel */
- if (!CAROUSEL_PARAMETERS.loop) {
- currentOffset += elemWidth * num;
- CRSL_LIST.style.marginLeft = currentOffset + 'px';
- if (currentElement == 0) {
- LEFT_ARROW.style.display = 'none';
- touchPrev = false;
- }
- RIGHT_ARROW.style.display = 'block';
- touchNext = true;
- } /* move carousel to the right side. Infinite carousel */
- else {
- let elm, buf;
- for (let i = 0; i < num; i++) {
- elm = CRSL_LIST.lastElementChild;
- buf = elm.cloneNode(true);
- CRSL_LIST.insertBefore(buf, CRSL_LIST.firstElementChild);
- CRSL_LIST.removeChild(elm);
- };
- CRSL_LIST.style.marginLeft = '-' + elemWidth * num + 'px';
- let compStyle = window.getComputedStyle(CRSL_LIST).marginLeft;
- CRSL_LIST.style.cssText = 'transition:margin ' + CAROUSEL_PARAMETERS.speed + 'ms ease;';
- CRSL_LIST.style.marginLeft = '0px';
- setTimeout(function() {
- CRSL_LIST.style.cssText = 'transition:none;'
- }, CAROUSEL_PARAMETERS.speed)
- }
- };
- function elemNext(num) {
- num = num || 1;
- if (CAROUSEL_PARAMETERS.dots) {
- dotOn(currentElement);
- }
- currentElement += num;
- if (currentElement >= dotsVisible) {
- currentElement = 0;
- }
- if (CAROUSEL_PARAMETERS.dots) {
- dotOff(currentElement);
- } /* move carousel to the left side. NOT Infinite carousel */
- if (!CAROUSEL_PARAMETERS.loop) {
- currentOffset -= elemWidth * num;
- CRSL_LIST.style.marginLeft = currentOffset + 'px';
- if (currentElement == dotsVisible - 1) {
- RIGHT_ARROW.style.display = 'none';
- touchNext = false;
- }
- LEFT_ARROW.style.display = 'block';
- touchPrev = true;
- } /* move carousel to the left side. Infinite carousel */
- else {
- let elm, buf;
- CRSL_LIST.style.cssText = 'transition:margin ' + CAROUSEL_PARAMETERS.speed + 'ms ease;';
- CRSL_LIST.style.marginLeft = '-' + elemWidth * num + 'px';
- setTimeout(function() {
- CRSL_LIST.style.cssText = 'transition:none;';
- for (let i = 0; i < num; i++) {
- elm = CRSL_LIST.firstElementChild;
- buf = elm.cloneNode(true);
- CRSL_LIST.appendChild(buf);
- CRSL_LIST.removeChild(elm)
- };
- CRSL_LIST.style.marginLeft = '0px'
- }, CAROUSEL_PARAMETERS.speed);
- }
- }
- function dotOn(num) {
- DOTS_INDICATOR_All[num].style.cssText = 'background-color:#BBB; cursor:pointer;'
- }
- function dotOff(num) {
- DOTS_INDICATOR_All[num].style.cssText = 'background-color:#556; cursor:default;'
- }
- }
- })();
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement