Created
July 28, 2019 22:31
-
-
Save pbuzdin/bb57a108f060d18bf887cda81774b6f4 to your computer and use it in GitHub Desktop.
regularElements loadjs swiper demo // source https://jsbin.com/loriyuz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
| <title>regularElements loadjs swiper demo</title> | |
| <script>this.Promise||document.write('<script src="https://unpkg.com/es6-promise@4.2.5/dist/es6-promise.auto.min.js"><\x2fscript>')</script> | |
| <script>this.WeakMap||document.write('<script src="https://unpkg.com/@ungap/weakmap@0.1.4/min.js"><\x2fscript>')</script> | |
| <script defer src="https://unpkg.com/regular-elements@0.5.0/min.js"></script> | |
| <script defer src="https://unpkg.com/load-js@3.0.3/index.js"></script> | |
| </head> | |
| <body> | |
| <div class="swiper-c">click me</div> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function (){ | |
| document.querySelector('.swiper-c').dataset.attr = '9980' | |
| regularElements.define('.swiper-c', { | |
| onconnected: function () { | |
| console.log('swiper-c connected') | |
| document.querySelector('.swiper-c').dataset.attr++; | |
| document.querySelector('.swiper-c').insertAdjacentHTML('afterbegin', //beforeend | |
| ` | |
| <link rel="stylesheet" href="https://idangero.us/swiper/dist/css/swiper.min.css"> | |
| <style> | |
| body { padding: 10% } | |
| .swiper-container { | |
| width: 100%; | |
| height: 100%; | |
| } | |
| .swiper-slide { | |
| text-align: center; | |
| font-size: 18px; | |
| background: lime; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| min-height: 200px; | |
| } | |
| </style> | |
| <div class="swiper-container"> | |
| <div class="swiper-wrapper"> | |
| <div class="swiper-slide">Slide 1</div> | |
| <div class="swiper-slide">${document.querySelector('.swiper-c').dataset.attr}</div> | |
| <div class="swiper-slide">Slide 3</div> | |
| <div class="swiper-slide">Slide 4</div> | |
| <div class="swiper-slide">Slide 5</div> | |
| <div class="swiper-slide">Slide 6</div> | |
| <div class="swiper-slide">Slide 7</div> | |
| <div class="swiper-slide">Slide 8</div> | |
| <div class="swiper-slide">Slide 9</div> | |
| <div class="swiper-slide">Slide 10</div> | |
| </div> | |
| <div class="swiper-pagination"></div> | |
| <div class="swiper-button-next"></div> | |
| <div class="swiper-button-prev"></div> | |
| </div> | |
| `); | |
| }, | |
| onattributechanged: function (event) { | |
| var {attributeName, oldValue, newValue} = event; | |
| console.log(attributeName, oldValue, newValue, 'хуй'); | |
| function loadSwiper() { | |
| var swiper = new Swiper('.swiper-container', { | |
| pagination: { | |
| el: '.swiper-pagination', | |
| type: 'fraction', | |
| }, | |
| navigation: { | |
| nextEl: '.swiper-button-next', | |
| prevEl: '.swiper-button-prev', | |
| }, | |
| }) | |
| } | |
| if(typeof(Swiper) != "function") { | |
| loadJS(["https://unpkg.com/swiper@4.5.0/dist/js/swiper.js"]) | |
| .then(function() { | |
| loadSwiper() | |
| }) | |
| } else { | |
| loadSwiper() | |
| } | |
| } | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment