Simple React Slider
How do I make an simple react slider?
What is a simple react slider? How do you make a simple react slider? This script and codes were developed by Karsten Buckstegge on 10 September 2022, Saturday.
Simple React Slider - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Simple React Slider</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="root"></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/classnames/2.2.5/index.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-with-addons.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Simple React Slider - Script Codes CSS Codes
#root { max-width: 960px; margin: 20px auto; overflow: hidden;
}
.slider .content { width: 100%; height: 80vh; position: relative;
}
.slide { pointer-events: all; position: absolute; background: #bada55; text-align: center; border: 1px solid green; width: 60%; left: 50%; height: 100%; transition: transform .5s;
}
.slide.previous, .slide.next { opacity: 0.3; cursor: pointer;
}
.slide.current { transform: translateX(-50%);
}
.slide.previous { transform: translateX(-160%);
}
.slide.next { transform: translateX(60%);
}
.slide-enter.previous { transform: translateX(-270%);
}
.slide-enter-active.previous { transform: translateX(-160%);
}
.slide-leave.previous { transform: translateX(-160%);
}
.slide-leave-active.previous { transform: translateX(-270%);
}
.slide-enter.next { transform: translateX(170%);
}
.slide-enter-active.next { transform: translateX(60%);
}
.slide-leave.next { transform: translateX(60%);
}
.slide-leave-active.next { transform: translateX(170%);
}
.indicators { margin-top: 15px; display: flex; justify-content: center;
}
.indicator { margin: 0 2px; width: 10px; height: 10px; border: 1px solid black; border-radius: 50%; background-color: white;
}
.indicator.active { background-color: blue;
}
Simple React Slider - Script Codes JS Codes
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _class, _temp2;
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; }
var Slider = (_temp2 = _class = function (_React$Component) { _inherits(Slider, _React$Component); function Slider() { var _temp, _this, _ret; _classCallCheck(this, Slider); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = { index: 0 }, _this.renderChildSlides = function (currentIndex, children) { return React.Children.toArray(children).reduce(function (childrenToRender, _, index) { if (index < currentIndex - 1 || index > currentIndex + 1) { return childrenToRender; } var classes = classNames('slide', { current: index === currentIndex, previous: index === currentIndex - 1, next: index === currentIndex + 1 }); return [].concat(childrenToRender, [React.createElement( 'div', { key: index, className: classes, onClick: _this.selectSlide(index) }, index )]); }, []); }, _this.selectSlide = function (index) { return function () { _this.setState(_extends({}, _this.state, { index: index })); }; }, _this.renderDotIndicators = function (currentIndex, children) { return children.map(function (_, index) { var classes = classNames('indicator', { active: index === currentIndex }); return React.createElement('div', { className: classes }); }); }, _this.close = function () { alert('Closing'); }, _this.renderNextButton = function (currentIndex, children) { if (currentIndex + 1 < React.Children.count(children)) { return React.createElement( 'button', { type: 'button', onClick: _this.selectSlide(currentIndex + 1) }, 'Weiter' ); } return React.createElement( 'button', { type: 'button', onClick: _this.close }, 'Zu deiner Seite' ); }, _temp), _possibleConstructorReturn(_this, _ret); } Slider.prototype.render = function render() { return React.createElement( 'div', { className: 'slider' }, React.createElement( 'div', { className: 'content-wrapper' }, React.createElement( 'div', { className: 'content' }, React.createElement( React.addons.CSSTransitionGroup, { transitionName: 'slide', transitionEnterTimeout: 500, transitionLeaveTimeout: 500 }, this.renderChildSlides(this.state.index, this.props.children) ) ), React.createElement( 'div', { className: 'indicators' }, this.renderDotIndicators(this.state.index, this.props.children) ), React.createElement( 'div', { className: 'indicators' }, this.renderNextButton(this.state.index, this.props.children) ) ) ); }; return Slider;
}(React.Component), _class.propTypes = { children: React.PropTypes.node.isRequired
}, _temp2);
function App(props) { return React.createElement( Slider, null, React.createElement( 'div', null, 'Content 1' ), React.createElement( 'div', null, 'Content 2' ), React.createElement( 'div', null, 'Content 3' ), React.createElement( 'div', null, 'Content 4' ), React.createElement( 'div', null, 'Content 5' ), React.createElement( 'div', null, 'Content 6' ), React.createElement( 'div', null, 'Content 7' ) );
}
ReactDOM.render(React.createElement(App, null), document.querySelector('#root'));
Developer | Karsten Buckstegge |
Username | MrBambule |
Uploaded | September 10, 2022 |
Rating | 3 |
Size | 4,975 Kb |
Views | 74,888 |
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!
Name | Size |
CSS3 Hover Button | 3,717 Kb |
Sliding Skill-Diagramm | 2,466 Kb |
A Pen by Karsten Buckstegge | 3,521 Kb |
SeXy buttons | 4,447 Kb |
The wheel of social fortune | 6,570 Kb |
Freddy the Fly | 4,238 Kb |
Base64 SVG Me | 44,786 Kb |
Broken TV | 2,456 Kb |
Responsive CSS arrow bar with transparent borders | 2,798 Kb |
The wheel of social | 4,072 Kb |
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!
Name | Username | Size |
JQuery AJAX reddit Exercise | Btholt | 1,777 Kb |
RSW | JordanC | 3,726 Kb |
Foundation 5 Menu - Accessibility | Xporter | 1,999 Kb |
Right Click Menu | Anodpixels | 2,252 Kb |
Revolving Text Landing Page Trial | TimRuby | 2,976 Kb |
Sass random color animation | Jotavejv | 4,827 Kb |
Materializecss input form | Jasonchan | 1,443 Kb |
Speech bubbles | Something | 1,547 Kb |
Base-Style | Daniel_gooss | 2,614 Kb |
Click handler test | Snapson | 2,329 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!