3 Star 1 Fork 0

mirrors_loryjs/lory

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.html 36.76 KB
一键复制 编辑 原始数据 按行查看 历史
Maximilian Heinz 提交于 2018-05-30 11:41 . fix: path to tests screenshot
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>lory</title>
<meta name="description" content="Touch enabled minimalistic slider written in vanilla JavaScript">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/ico" href="./static/favicon.ico" />
<link rel="stylesheet" type="text/css" href="./static/app.css" />
<link rel="stylesheet" type="text/css" href="./static/vendor/railscasts.css" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700' rel='stylesheet' type='text/css'>
</head>
<body>
<header>
<div class="ribbon">
<a href="https://github.com/meandmax/lory">Fork me on GitHub</a>
</div>
<img class="logo" src="./static/lory.png" />
</header>
<p class="description">Touch enabled minimalistic slider written in vanilla JavaScript</p>
<p class="description">Hardware accelerated transitions</p>
<p class="description">Usable as a jQuery plugin</p>
<p class="description">Options for custom easing effects</p>
<p class="description">infinite looping ~ carousel</p>
<p class="description">No compromises for fallbacks</p>
<p class="description">Written in ecmascript 6</p>
<p class="description">Using webpack, babel & eslint for development</p>
<a class="dist" href="./dist/lory.min.js" download>Download Here</a>
<p class="description">or via cdn from <a href="https://cdnjs.com/libraries/lory.js/" target="_blank">cdnjs</a></p>
<section class="prerequisited">
<div class="examplecode">
<h2>Prerequisited Html structure<br><small><em>Class names can be changed through options</em></small></h2>
<pre><code class="html">
&lt;div class=&quot;slider js_slider&quot;&gt;
&lt;div class=&quot;frame js_frame&quot;&gt;
&lt;ul class=&quot;slides js_slides&quot;&gt;
&lt;li class=&quot;js_slide&quot;&gt;1&lt;/li&gt;
&lt;li class=&quot;js_slide&quot;&gt;2&lt;/li&gt;
&lt;li class=&quot;js_slide&quot;&gt;3&lt;/li&gt;
&lt;li class=&quot;js_slide&quot;&gt;4&lt;/li&gt;
&lt;li class=&quot;js_slide&quot;&gt;5&lt;/li&gt;
&lt;li class=&quot;js_slide&quot;&gt;6&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;span class=&quot;js_prev prev&quot;&gt;
&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;50&quot; height=&quot;50&quot; viewBox=&quot;0 0 501.5 501.5&quot;&gt;&lt;g&gt;&lt;path fill=&quot;#2E435A&quot; d=&quot;M302.67 90.877l55.77 55.508L254.575 250.75 358.44 355.116l-55.77 55.506L143.56 250.75z&quot;/&gt;&lt;/g&gt;&lt;/svg&gt;
&lt;/span&gt;
&lt;span class=&quot;js_next next&quot;&gt;
&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;50&quot; height=&quot;50&quot; viewBox=&quot;0 0 501.5 501.5&quot;&gt;&lt;g&gt;&lt;path fill=&quot;#2E435A&quot; d=&quot;M199.33 410.622l-55.77-55.508L247.425 250.75 143.56 146.384l55.77-55.507L358.44 250.75z&quot;/&gt;&lt;/g&gt;&lt;/svg&gt;
&lt;/span&gt;
&lt;/div&gt;
</code></pre></div>
<div class="examplecode">
<h2>Prerequisited CSS styles</h2>
<pre><code class="css">
/**
* (optional) define here the style definitions which should be applied on the slider container
* e.g. width including further controls like arrows etc.
*/
.slider {}
.frame {
/**
* (optional) wrapper width, specifies width of the slider frame.
*/
width: 880px;
position: relative;
font-size: 0;
line-height: 0;
overflow: hidden;
white-space: nowrap;
}
.slides {
display: inline-block;
}
li {
position: relative;
display: inline-block;
/**
* (optional) if the content inside the slide element has a defined size.
*/
width: 880px;
}
.prev, .next {
position: absolute;
top: 50%;
margin-top: -25px;
display: block;
cursor: pointer;
}
.next {
right: 0;
}
.prev {
left: 0;
}
.next svg, .prev svg {
width: 25px;
}
</code></pre></div>
</section>
<section class="examples">
<h2>Single element - Fixed width [infinite]</h2>
<div class="slider js_simple simple">
<div class="frame js_frame">
<ul class="slides js_slides">
<li class="js_slide">1</li>
<li class="js_slide">2</li>
<li class="js_slide">3</li>
<li class="js_slide">4</li>
<li class="js_slide">5</li>
<li class="js_slide">6</li>
</ul>
</div>
<span class="js_prev prev">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M302.67 90.877l55.77 55.508L254.575 250.75 358.44 355.116l-55.77 55.506L143.56 250.75z"/></g></svg>
</span>
<span class="js_next next">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M199.33 410.622l-55.77-55.508L247.425 250.75 143.56 146.384l55.77-55.507L358.44 250.75z"/></g></svg>
</span>
</div>
<div class="examplecode"><pre><code class="javascript">
document.addEventListener('DOMContentLoaded', function () {
var simple = document.querySelector('.js_simple');
lory(simple, {
infinite: 1
});
});
</code></pre></div>
<h2>Single element - dot navigation</h2>
<div class="slider js_simple_dots simple">
<div class="frame js_frame">
<ul class="slides js_slides">
<li class="js_slide">1</li>
<li class="js_slide">2</li>
<li class="js_slide">3</li>
<li class="js_slide">4</li>
<li class="js_slide">5</li>
<li class="js_slide">6</li>
</ul>
</div>
<span class="js_prev prev">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M302.67 90.877l55.77 55.508L254.575 250.75 358.44 355.116l-55.77 55.506L143.56 250.75z"/></g></svg>
</span>
<span class="js_next next">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M199.33 410.622l-55.77-55.508L247.425 250.75 143.56 146.384l55.77-55.507L358.44 250.75z"/></g></svg>
</span>
<ul class="js_dots dots"></ul>
</div>
<div class="examplecode"><pre><code class="javascript">
document.addEventListener('DOMContentLoaded', function () {
var simple_dots = document.querySelector('.js_simple_dots');
var dot_count = simple_dots.querySelectorAll('.js_slide').length;
var dot_container = simple_dots.querySelector('.js_dots');
var dot_list_item = document.createElement('li');
function handleDotEvent(e) {
if (e.type === 'before.lory.init') {
for (var i = 0, len = dot_count; i < len; i++) {
var clone = dot_list_item.cloneNode();
dot_container.appendChild(clone);
}
dot_container.childNodes[0].classList.add('active');
}
if (e.type === 'after.lory.init') {
for (var i = 0, len = dot_count; i < len; i++) {
dot_container.childNodes[i].addEventListener('click', function(e) {
dot_navigation_slider.slideTo(Array.prototype.indexOf.call(dot_container.childNodes, e.target));
});
}
}
if (e.type === 'after.lory.slide') {
for (var i = 0, len = dot_container.childNodes.length; i < len; i++) {
dot_container.childNodes[i].classList.remove('active');
}
dot_container.childNodes[e.detail.currentSlide - 1].classList.add('active');
}
if (e.type === 'on.lory.resize') {
for (var i = 0, len = dot_container.childNodes.length; i < len; i++) {
dot_container.childNodes[i].classList.remove('active');
}
dot_container.childNodes[0].classList.add('active');
}
}
simple_dots.addEventListener('before.lory.init', handleDotEvent);
simple_dots.addEventListener('after.lory.init', handleDotEvent);
simple_dots.addEventListener('after.lory.slide', handleDotEvent);
simple_dots.addEventListener('on.lory.resize', handleDotEvent);
var dot_navigation_slider = lory(simple_dots, {
infinite: 1,
enableMouseEvents: true
});
});
</code></pre></div>
<h2>Single element - Percentage width [infinite]</h2>
<div class="slider js_percentage percentage">
<div class="frame js_frame">
<ul class="slides js_slides">
<li class="js_slide">1</li>
<li class="js_slide">2</li>
<li class="js_slide">3</li>
<li class="js_slide">4</li>
<li class="js_slide">5</li>
<li class="js_slide">6</li>
</ul>
</div>
<span class="js_prev prev">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M302.67 90.877l55.77 55.508L254.575 250.75 358.44 355.116l-55.77 55.506L143.56 250.75z"/></g></svg>
</span>
<span class="js_next next">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M199.33 410.622l-55.77-55.508L247.425 250.75 143.56 146.384l55.77-55.507L358.44 250.75z"/></g></svg>
</span>
</div>
<div class="examplecode"><pre><code class="javascript">
document.addEventListener('DOMContentLoaded', function () {
var percentage = document.querySelector('.js_percentage');
lory(percentage, {
infinite: 1
});
});
</code></pre></div>
<h2>Single element - Fixed width [rewind]</h2>
<div class="slider js_rewind rewind">
<div class="frame js_frame">
<ul class="slides js_slides">
<li class="js_slide">1</li>
<li class="js_slide">2</li>
<li class="js_slide">3</li>
<li class="js_slide">4</li>
<li class="js_slide">5</li>
<li class="js_slide">6</li>
</ul>
</div>
<span class="js_prev prev">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M302.67 90.877l55.77 55.508L254.575 250.75 358.44 355.116l-55.77 55.506L143.56 250.75z"/></g></svg>
</span>
<span class="js_next next">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M199.33 410.622l-55.77-55.508L247.425 250.75 143.56 146.384l55.77-55.507L358.44 250.75z"/></g></svg>
</span>
</div>
<div class="examplecode"><pre><code class="javascript">
document.addEventListener('DOMContentLoaded', function () {
var rewind = document.querySelector('.js_rewind');
lory(rewind, {
rewind: true
});
});
</code></pre></div>
<h2>Single element - Percentage width [rewind]</h2>
<div class="slider js_rewind_percentage percentage">
<div class="frame js_frame">
<ul class="slides js_slides">
<li class="js_slide">1</li>
<li class="js_slide">2</li>
<li class="js_slide">3</li>
<li class="js_slide">4</li>
<li class="js_slide">5</li>
<li class="js_slide">6</li>
</ul>
</div>
<span class="js_prev prev">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M302.67 90.877l55.77 55.508L254.575 250.75 358.44 355.116l-55.77 55.506L143.56 250.75z"/></g></svg>
</span>
<span class="js_next next">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M199.33 410.622l-55.77-55.508L247.425 250.75 143.56 146.384l55.77-55.507L358.44 250.75z"/></g></svg>
</span>
</div>
<div class="examplecode"><pre><code class="javascript">
document.addEventListener('DOMContentLoaded', function () {
var rewind_percentage = document.querySelector('.js_rewind_percentage');
lory(rewind_percentage, {
rewind: true
});
});
</code></pre></div>
<h2>Variable width</h2>
<div class="slider js_variablewidth variablewidth">
<div class="frame js_frame">
<ul class="slides js_slides">
<li class="js_slide" style="width: 220px;">220</li>
<li class="js_slide" style="width: 190px;">190</li>
<li class="js_slide" style="width: 150px;">150</li>
<li class="js_slide" style="width: 130px;">130</li>
<li class="js_slide" style="width: 250px;">250</li>
<li class="js_slide" style="width: 180px;">180</li>
<li class="js_slide" style="width: 200px;">200</li>
<li class="js_slide" style="width: 140px;">140</li>
<li class="js_slide" style="width: 120px;">120</li>
<li class="js_slide" style="width: 240px;">240</li>
</ul>
</div>
<span class="js_prev prev">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M302.67 90.877l55.77 55.508L254.575 250.75 358.44 355.116l-55.77 55.506L143.56 250.75z"/></g></svg>
</span>
<span class="js_next next">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M199.33 410.622l-55.77-55.508L247.425 250.75 143.56 146.384l55.77-55.507L358.44 250.75z"/></g></svg>
</span>
</div>
<div class="examplecode"><pre><code class="javascript">
document.addEventListener('DOMContentLoaded', function () {
var variableWidth = document.querySelector('.js_variablewlidth');
lory(variableWidth, {
rewind: true
});
});
</code></pre></div>
<h2>Multiple slides to scroll</h2>
<div class="slider js_multislides multislides">
<div class="frame js_frame">
<ul class="slides js_slides">
<li class="js_slide">1</li>
<li class="js_slide">2</li>
<li class="js_slide">3</li>
<li class="js_slide">4</li>
<li class="js_slide">5</li>
<li class="js_slide">6</li>
<li class="js_slide">7</li>
<li class="js_slide">8</li>
<li class="js_slide">9</li>
<li class="js_slide">10</li>
<li class="js_slide">11</li>
<li class="js_slide">12</li>
</ul>
</div>
<span class="js_prev prev">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M302.67 90.877l55.77 55.508L254.575 250.75 358.44 355.116l-55.77 55.506L143.56 250.75z"/></g></svg>
</span>
<span class="js_next next">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M199.33 410.622l-55.77-55.508L247.425 250.75 143.56 146.384l55.77-55.507L358.44 250.75z"/></g></svg>
</span>
</div>
<div class="examplecode"><pre><code class="javascript">
document.addEventListener('DOMContentLoaded', function () {
var multiSlides = document.querySelector('.js_multislides');
lory(multiSlides, {
infinite: 4,
slidesToScroll: 4
});
});
</code></pre></div>
<h2>Custom easings</h2>
<div class="slider js_ease ease">
<div class="frame js_frame">
<ul class="slides js_slides">
<li class="js_slide">1</li>
<li class="js_slide">2</li>
<li class="js_slide">3</li>
<li class="js_slide">4</li>
<li class="js_slide">5</li>
<li class="js_slide">6</li>
<li class="js_slide">7</li>
<li class="js_slide">8</li>
<li class="js_slide">9</li>
<li class="js_slide">10</li>
<li class="js_slide">11</li>
<li class="js_slide">12</li>
</ul>
</div>
<span class="js_prev prev">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M302.67 90.877l55.77 55.508L254.575 250.75 358.44 355.116l-55.77 55.506L143.56 250.75z"/></g></svg>
</span>
<span class="js_next next">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M199.33 410.622l-55.77-55.508L247.425 250.75 143.56 146.384l55.77-55.507L358.44 250.75z"/></g></svg>
</span>
</div>
<div class="examplecode"><pre><code class="javascript">
document.addEventListener('DOMContentLoaded', function () {
var ease = document.querySelector('.js_ease');
// http://easings.net/
lory(ease, {
infinite: 4,
slidesToScroll: 4,
slideSpeed: 1000,
ease: 'cubic-bezier(0.455, 0.03, 0.515, 0.955)'
});
});
</code></pre></div>
<h2>Showing events</h2>
<div class="slider js_events events">
<div class="frame js_frame">
<ul class="slides js_slides">
<li class="js_slide">1</li>
<li class="js_slide">2</li>
<li class="js_slide">3</li>
<li class="js_slide">4</li>
<li class="js_slide">5</li>
<li class="js_slide">6</li>
</ul>
</div>
<span class="js_prev prev">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M302.67 90.877l55.77 55.508L254.575 250.75 358.44 355.116l-55.77 55.506L143.56 250.75z"/></g></svg>
</span>
<span class="js_next next">
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 501.5 501.5"><g><path fill="#2E435A" d="M199.33 410.622l-55.77-55.508L247.425 250.75 143.56 146.384l55.77-55.507L358.44 250.75z"/></g></svg>
</span>
</div>
<code class="events_log"></code>
<div class="examplecode"><pre><code class="javascript">
document.addEventListener('DOMContentLoaded', function () {
var events = document.querySelector('.js_events');
function handleEvent(e) {
var newSpan = document.createElement('span');
var time = new Date();
time = time.getHours() + ':' + time.getMinutes() + ':' + time.getSeconds() + ',' + time.getMilliseconds();
var newContent = document.createTextNode('[' + time + '] Event dispatched: "' + e.type + '"');
newSpan.appendChild(newContent);
e.target.nextElementSibling.appendChild(newSpan);
}
events.addEventListener('before.lory.init', handleEvent);
events.addEventListener('after.lory.init', handleEvent);
events.addEventListener('before.lory.slide', handleEvent);
events.addEventListener('after.lory.slide', handleEvent);
events.addEventListener('before.lory.destroy', handleEvent);
events.addEventListener('after.lory.destroy', handleEvent);
events.addEventListener('on.lory.resize', handleEvent);
events.addEventListener('on.lory.touchend', handleEvent);
events.addEventListener('on.lory.touchmove', handleEvent);
events.addEventListener('on.lory.touchstart', handleEvent);
lory(events, {
infinite: 1
});
});
</code></pre></div>
</section>
<section class="multiplesliders">
<h2>initialize multiple similiar sliders</h2>
<div class="examplecode"><pre><code class="javascript">
'use strict';
document.addEventListener('DOMContentLoaded', function () {
Array.prototype.slice.call(document.querySelectorAll('.js_slider')).forEach(function (element, index) {
lory(element, {});
});
});
</code></pre></div>
</section>
<section class="commonJS">
<h2>Consume it as a commonJS module</h2>
<div class="examplecode"><pre><code class="javascript">
"use strict";
var lory = require('lory.js').lory;
document.addEventListener('DOMContentLoaded', function() {
var slider = document.querySelector('.js_slider');
lory(slider, {
// options going here
});
});
</code></pre></div>
</section>
<section class="ES2015">
<h2>Consume it as an ES2015 module</h2>
<div class="examplecode"><pre><code class="javascript">
import {lory} from 'lory.js';
document.addEventListener('DOMContentLoaded', () => {
const slider = document.querySelector('.js_slider');
lory(slider, {
// options going here
});
});
</code></pre></div>
<section class="jquery">
<h2>Use it as a jQuery Plugin</h2>
<div class="examplecode"><pre><code class="html">
&lt;script src=&quot;js/jquery.lory.min.js&quot;&gt;&lt;/script&gt;
</code></pre></div>
<div class="examplecode"><pre><code class="javascript">
'use strict';
var $elements = $('.js_simple');
$(function() {
$elements.lory({
infinite: 1
});
$elements.data().lory.slideTo(4);
// $elements.data().lory.prev();
// $elements.data().lory.next();
});
</code></pre></div>
</section>
<section class="development">
<h2>Local development</h2>
<div class="examplecode"><pre><code class="shell">
// To install dev dependencies run:
yarn install
// To start the development server run:
yarn run dev
// To lint your code run:
yarn run lint
// To make a full new build run:
yarn run build
</code></pre></div>
</section>
<section class="tests">
<h2>Run tests</h2>
<div class="examplecode"><pre><code class="shell">
// To install dev dependencies run:
yarn install
// To start the karma tests locally run:
yarn run karma-local
</code></pre></div>
<img class="testscreen" src="./static/tests.png" />
</section>
<section class="api">
<h2>Public API</h2>
<table>
<tr>
<th>prev:</th>
<td>slides to the previous slide</td>
</tr>
<tr>
<th>next:</th>
<td>slides to the next slide</td>
</tr>
<tr>
<th>slideTo:</th>
<td>slides to the index given as an argument: (arguments: index {number})</td>
</tr>
<tr>
<th>returnIndex:</th>
<td>returns the index of the current slide element</td>
</tr>
<tr>
<th>setup:</th>
<td>binds eventlisteners, merging default and user options, setup the slides based on DOM (called once during initialisation)</td>
<td>Call setup if DOM or user options have changed or eventlisteners needs to be rebinded.</td>
</tr>
<tr>
<th>reset:</th>
<td>sets the slider back to the starting position and resets the current index (called on Resize event)</td>
</tr>
<tr>
<th>destroy:</th>
<td>unmount/destroy the instance of lory</td>
</tr>
</table>
</section>
<section class="options">
<h2>Options</h2>
<table>
<tr>
<th>slidesToScroll</th>
<td>slides scrolled at once</td>
<td>default: 1</td>
</tr>
<tr>
<th>enableMouseEvents</th>
<td>enabled mouse events</td>
<td>default: false</td>
</tr>
<tr>
<th>infinite</th>
<td>like carousel, works with multiple slides. (do not combine with rewind)</td>
<td>default: false (number of visible slides)</td>
</tr>
<tr>
<th>rewind</th>
<td>if slider reached the last slide, with next click the slider goes back to the startindex. (do not combine with infinite)</td>
<td>default: false</td>
</tr>
<tr>
<th>slideSpeed</th>
<td>time in milliseconds for the animation of a valid slide attempt</td>
<td>default: 300</td>
</tr>
<tr>
<th>rewindSpeed</th>
<td>time in milliseconds for the animation of the rewind after the last slide</td>
<td>default: 600</td>
</tr>
<tr>
<th>snapBackSpeed</th>
<td>time for the snapBack of the slider if the slide attempt was not valid</td>
<td>default: 200</td>
</tr>
<tr>
<td>initialIndex</td>
<td>the slide index to show when the slider is initialized</td>
<td>default: 0</td>
</tr>
<tr>
<th>ease</th>
<td>cubic bezier easing functions: http://easings.net/de</td>
<td>default: 'ease'</td>
</tr>
<tr>
<th>classNameFrame</th>
<td>class name for slider frame</td>
<td>default: 'js_frame'</td>
</tr>
<tr>
<th>classNameSlideContainer</th>
<td>class name for slides container</td>
<td>default: 'js_slides'</td>
</tr>
<tr>
<th>classNamePrevCtrl</th>
<td>class name for slider previous control</td>
<td>default: 'js_prev'</td>
</tr>
<tr>
<th>classNameNextCtrl</th>
<td>class name for slider next control</td>
<td>default: 'js_next'</td>
</tr>
</table>
</section>
<section class="hooks">
<h2>Events</h2>
<table>
<tr>
<th>before.lory.init</th>
<td>fires before initialisation (first in setup function)</td>
</tr>
<tr>
<th>after.lory.init</th>
<td>fires after initialisation (end of setup function)</td>
</tr>
<tr>
<th>before.lory.slide</th>
<td><strong>arguments:</strong> currentSlide, nextSlide</td>
<td>fires before slide change</td>
</tr>
<tr>
<th>after.lory.slide</th>
<td><strong>arguments:</strong> currentSlide</td>
<td>fires after slide change</td>
</tr>
<tr>
<th>before.lory.destroy</th>
<td>fires before the slider instance gets destroyed</td>
</tr>
<tr>
<th>after.lory.destroy</th>
<td>fires after the slider instance gets destroyed</td>
</tr>
<tr>
<th>on.lory.resize</th>
<td>fires on every resize event</td>
</tr>
<tr>
<th>on.lory.touchstart</th>
<td>fires on every slider touchstart event</td>
</tr>
<tr>
<th>on.lory.touchmove</th>
<td>fires on every slider touchmove event</td>
</tr>
<tr>
<th>on.lory.touchend</th>
<td>fires on every slider touchend event</td>
</tr>
</table>
</section>
<footer>
Copyright &copy; 2015 Maximilian Heinz, contributors. Released under the MIT license
</footer>
</body>
<script src="./static/vendor/highlight.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="./dist/lory.min.js"></script>
<script>
'use strict';
document.addEventListener('DOMContentLoaded', function () {
var simple = document.querySelector('.js_simple');
var simple_dots = document.querySelector('.js_simple_dots');
var dot_count = simple_dots.querySelectorAll('.js_slide').length;
var dot_container = simple_dots.querySelector('.js_dots');
var dot_list_item = document.createElement('li');
var percentage = document.querySelector('.js_percentage');
var rewind = document.querySelector('.js_rewind');
var rewind_percentage = document.querySelector('.js_rewind_percentage');
var variableWidth = document.querySelector('.js_variablewidth');
var multiSlides = document.querySelector('.js_multislides');
var ease = document.querySelector('.js_ease');
var events = document.querySelector('.js_events');
lory(simple, {
infinite: 1,
enableMouseEvents: true
});
function handleDotEvent(e) {
if (e.type === 'before.lory.init') {
for (var i = 0, len = dot_count; i < len; i++) {
var clone = dot_list_item.cloneNode();
dot_container.appendChild(clone);
}
dot_container.childNodes[0].classList.add('active');
}
if (e.type === 'after.lory.init') {
for (var i = 0, len = dot_count; i < len; i++) {
dot_container.childNodes[i].addEventListener('click', function(e) {
dot_navigation_slider.slideTo(Array.prototype.indexOf.call(dot_container.childNodes, e.target));
});
}
}
if (e.type === 'after.lory.slide') {
for (var i = 0, len = dot_container.childNodes.length; i < len; i++) {
dot_container.childNodes[i].classList.remove('active');
}
dot_container.childNodes[e.detail.currentSlide - 1].classList.add('active');
}
if (e.type === 'on.lory.resize') {
for (var i = 0, len = dot_container.childNodes.length; i < len; i++) {
dot_container.childNodes[i].classList.remove('active');
}
dot_container.childNodes[0].classList.add('active');
}
}
simple_dots.addEventListener('before.lory.init', handleDotEvent);
simple_dots.addEventListener('after.lory.init', handleDotEvent);
simple_dots.addEventListener('after.lory.slide', handleDotEvent);
simple_dots.addEventListener('on.lory.resize', handleDotEvent);
var dot_navigation_slider = lory(simple_dots, {
infinite: 1,
enableMouseEvents: true
});
lory(percentage, {
infinite: 1,
enableMouseEvents: true
});
lory(rewind, {
rewind: true,
enableMouseEvents: true
});
lory(rewind_percentage, {
rewind: true,
enableMouseEvents: true
});
lory(variableWidth, {
rewind: true,
enableMouseEvents: true
});
lory(multiSlides, {
infinite: 4,
slidesToScroll: 4,
enableMouseEvents: true
});
lory(ease, {
infinite: 4,
slidesToScroll: 4,
slideSpeed: 300,
ease: 'cubic-bezier(0.455, 0.03, 0.515, 0.955)',
enableMouseEvents: true
});
function handleEvent(e) {
var newSpan = document.createElement('span');
var time = new Date();
time = time.getHours() + ':' + time.getMinutes() + ':' + time.getSeconds() + ',' + time.getMilliseconds();
var newContent = document.createTextNode('[' + time + '] Event dispatched: "' + e.type + '"');
newSpan.appendChild(newContent);
e.target.nextElementSibling.appendChild(newSpan);
}
events.addEventListener('before.lory.init', handleEvent);
events.addEventListener('after.lory.init', handleEvent);
events.addEventListener('before.lory.slide', handleEvent);
events.addEventListener('after.lory.slide', handleEvent);
events.addEventListener('before.lory.destroy', handleEvent);
events.addEventListener('after.lory.destroy', handleEvent);
events.addEventListener('on.lory.resize', handleEvent);
events.addEventListener('on.lory.touchend', handleEvent);
events.addEventListener('on.lory.touchmove', handleEvent);
events.addEventListener('on.lory.touchstart', handleEvent);
lory(events, {
infinite: 1
});
});
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-61053578-1', 'auto');
ga('send', 'pageview');
</script>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_loryjs/lory.git
git@gitee.com:mirrors_loryjs/lory.git
mirrors_loryjs
lory
lory
master

搜索帮助