Direction.js

The carousel that doesn't do anything!

View the Project on GitHub

direction.js

MicroLib Canvas Carousel built for comix-ngn as a smaller, canvas only alternative to Swipe, Slick, Bootstrap Carousel, and other carousels. < 5 KB minified or your money back!

Since its Canvas only, it doesn’t require any CSS

Images Source

Installation

<script src="http://ogewan.github.io/direction.js/direction.min.js"></script>

Usage

var input = ["0.png","1.png","2.png","3.png"];
var config = {
	color: "#373737",
	anchor = document.body,
	overwrite = 1
}
var foo = new direction(input, config);

//jQuery
$("#myCarousel").direction(input, config);
//*If using jQuery, import it before direction
//**Element specified in the selector overrides config.anchor

*Not supported by swap

**Because it attaches to an element in the DOM, please make sure that the DOM is loaded/ready before you call direction(). If you don’t , you will immediately get a “cannot call method ‘appendChild’ of null” error._

Now at this point, you’d probably be wondering why it isn’t doing anything. All the other carousels, you’ve tried moved around fancily flipping through images and stuff. You might even be prompted to ask, “Ogewan, why isn’t it doing anything?”. And to that I answer, that’s what it’s supposed to do.

This carousel is pretty barebones. If you want it to do something, you’ll probably have to write a little script to do it for you. But fear not, it’s easy peasy, in theory.

Example:

window.setInterval(foo.next,1000);//Auto scrolls from first to last image

API

go(index) - go to the slide at index, goes to first slide by default

frst() - go to the first slide

prev() - go back a slide

next() - go forward a slide

last() - go to the last slide

rand() - go to a random slide

current() - gets the current slide

count() - gets the total amount of slides

data(index) - gets information about the slide at index, such as name and url, defaults to current page.

scroll() - gets/sets the status of the auto scroll. To auto scroll to the top of the page on slide change, set to true. To disable, set it to false. It is true by default

scrollTo(place, time) - scroll to place in given time (milliseconds)

I.E scrollTo({-1, -1}); will scroll to the bottom right in default time

swap(input, config, start) - changes the input array and config options at runtime.

callback(type, function, index, remove) - gets/sets slide transition callbacks.

```

I.E callback(-1, foo, 1); will set the second callback of slidestart to foo

Browser Support

requestAnimationFrame has replaced setTimeout, so this is now the major limiting factor.

See https://caniuse.com/#feat=requestanimationframe/.

TODO