React CSS Transition Carousel

Size
4,985 Kb
Views
18,216

How do I make an react css transition carousel?

A simple image slider that uses ReactCSSTransitionGroup for animations.. What is a react css transition carousel? How do you make a react css transition carousel? This script and codes were developed by Joseph Martucci on 25 October 2022, Tuesday.

React CSS Transition Carousel Previews

React CSS Transition Carousel - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>React CSS Transition Carousel</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="carousel"></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-with-addons.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-dom.js'></script> <script src="js/index.js"></script>
</body>
</html>

React CSS Transition Carousel - Script Codes CSS Codes

body { overflow: hidden;
}
.carousel { width: 100vw; height: 100vh; overflow: hidden;
}
.carousel__prev, .carousel__next { cursor: pointer; position: absolute; background: rgba(0, 0, 0, 0.6); font-size: 32px; color: white; width: 60px; height: 60px; text-align: center; line-height: 60px; top: 50%; margin-top: -30px; z-index: 1000;
}
.carousel__prev { left: 40px;
}
.carousel__next { right: 40px;
}
.carousel__slide { width: 100%; height: 100%;
}
.carousel__slide div { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-size: cover;
}
.translate-enter { -webkit-transform: translateX(100vw); transform: translateX(100vw);
}
.translate-enter.translate-enter-active { -webkit-transform: translateX(0); transform: translateX(0); -webkit-transition: all 500ms ease-in-out; transition: all 500ms ease-in-out;
}
.translate-leave { -webkit-transform: translateX(0); transform: translateX(0);
}
.translate-leave.translate-leave-active { -webkit-transform: translateX(-100vw); transform: translateX(-100vw); -webkit-transition: all 500ms ease-in-out; transition: all 500ms ease-in-out;
}
.scale-appear, .blur-appear, .rotate-appear, .translate-appear { -webkit-filter: grayscale(100%); filter: grayscale(100%); -webkit-transition: all 1000ms ease-in-out; transition: all 1000ms ease-in-out;
}
.scale-appear.scale-appear-active, .blur-appear.blur-appear-active, .rotate-appear.rotate-appear-active, .translate-appear.translate-appear-active { -webkit-filter: grayscale(0); filter: grayscale(0);
}
.scale-enter { -webkit-transform: scale(1); transform: scale(1);
}
.scale-enter.scale-enter-active { -webkit-transform: scale(1); transform: scale(1); -webkit-transition: all 500ms ease-in-out; transition: all 500ms ease-in-out;
}
.scale-leave { -webkit-transform: scale(1); transform: scale(1); opacity: 1;
}
.scale-leave.scale-leave-active { -webkit-transform: scale(1.2); transform: scale(1.2); opacity: .01; -webkit-transition: all 500ms ease-in-out; transition: all 500ms ease-in-out;
}
.blur-enter { -webkit-transform: scale(1); transform: scale(1);
}
.blur-enter.blur-enter-active { -webkit-transform: scale(1); transform: scale(1); -webkit-transition: all 500ms ease-in-out; transition: all 500ms ease-in-out;
}
.blur-leave { -webkit-transform: scale(1); transform: scale(1); opacity: 1;
}
.blur-leave.blur-leave-active { -webkit-filter: blur(40px); filter: blur(40px); opacity: .01; -webkit-transition: all 500ms ease-in-out; transition: all 500ms ease-in-out;
}
.rotate-enter { -webkit-filter: hue-rotate(-180deg); filter: hue-rotate(-180deg); opacity: .01;
}
.rotate-enter.rotate-enter-active { -webkit-filter: hue-rotate(0deg); filter: hue-rotate(0deg); opacity: 1; -webkit-transition: all 500ms ease-in-out; transition: all 500ms ease-in-out;
}
.rotate-leave { -webkit-filter: hue-rotate(0deg); filter: hue-rotate(0deg); opacity: 1;
}
.rotate-leave.rotate-leave-active { -webkit-filter: hue-rotate(180deg); filter: hue-rotate(180deg); opacity: .01; -webkit-transition: all 500ms ease-in-out; transition: all 500ms ease-in-out;
}

React CSS Transition Carousel - Script Codes JS Codes

'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// Change the slide transition type.
var transition = 'scale';
// try translate, scale, blur, rotate
var appearTransition = true;
// Change it to true to add an appear transition that fades the image in from grayscale to full color.
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
var ReactDOM = ReactDOM;
var slides = ['https://images.unsplash.com/photo-1444703686981-a3abbc4d4fe3?fit=crop&fm=jpg&h=825&q=80&w=1325', 'https://images.unsplash.com/photo-1445251836269-d158eaa028a6?fit=crop&fm=jpg&h=825&q=80&w=1325', 'https://images.unsplash.com/photo-1443926818681-717d074a57af?fit=crop&fm=jpg&h=825&q=80&w=1325'];
var Carousel = function (_React$Component) { _inherits(Carousel, _React$Component); function Carousel(props) { _classCallCheck(this, Carousel); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.state = { counter: 0 }; _this.prevSlide = _this.prevSlide.bind(_this); _this.nextSlide = _this.nextSlide.bind(_this); return _this; } Carousel.prototype.prevSlide = function prevSlide() { var prevSlide = this.state.counter - 1 < 0 ? this.props.slides.length - 1 : this.state.counter - 1; this.setState({ counter: prevSlide }); }; Carousel.prototype.nextSlide = function nextSlide() { var nextSlide = this.state.counter + 1 < this.props.slides.length ? this.state.counter + 1 : 0; this.setState({ counter: nextSlide }); }; Carousel.prototype.render = function render() { var style = { backgroundImage: 'url(' + this.props.slides[this.state.counter] + ')' }; return React.createElement( 'div', { className: 'carousel' }, React.createElement( 'div', { className: 'carousel__prev', onClick: this.prevSlide }, '◀︎' ), React.createElement( 'div', { className: 'carousel__next', onClick: this.nextSlide }, '▶︎' ), React.createElement( ReactCSSTransitionGroup, { transitionName: transition, transitionEnterTimeout: 500, transitionLeaveTimeout: 500, component: 'div', className: 'carousel__slide', transitionAppear: appearTransition, transitionAppearTimeout: 1000 }, React.createElement('div', { style: style, key: this.state.counter }) ) ); }; return Carousel;
}(React.Component);
ReactDOM.render(React.createElement(Carousel, { slides: slides }), document.getElementById('carousel'));
React CSS Transition Carousel - Script Codes
React CSS Transition Carousel - Script Codes
Home Page Home
Developer Joseph Martucci
Username jjmartucci
Uploaded October 25, 2022
Rating 3
Size 4,985 Kb
Views 18,216
Do you need developer help for React CSS Transition Carousel?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Joseph Martucci (jjmartucci) Script Codes
Create amazing Facebook ads with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!