Giter Club home page Giter Club logo

siema's Introduction

Hi. I will be discontinuing active maintenance of Siema. I built it by myself to use on one of my projects. Two years later I consider carousels as an anti-pattern and I would suggest you to find a better UI pattern than carousel for your current project. If you really want to use it, feel free. If you have any questions, please look for the answer in closed issues section. Would you like to contribute or coutinue maintenance of Siema? Fantastic!


Siema - Lightweight and simple carousel with no dependencies

Full docs with examples: https://pawelgrzybek.github.io/siema/.

Siema is a lightweight (only 3kb gzipped) carousel plugin with no dependencies and no styling. As Brad Frost once said "do that shit yourself". It is 100% open source and available on Github. It is free to use on personal and commercial projects. Use it with your favourite module bundler or by manually injecting the script into your project.

Installation

Setup is trivially easy. A little bit of markup...

<div class="siema">
  <div>Hi, I'm slide 1</div>
  <div>Hi, I'm slide 2</div>
  <div>Hi, I'm slide 3</div>
  <div>Hi, I'm slide 4</div>
</div>

If you are using a module bundler like Webpack or Browserify...

yarn add siema
import Siema from 'siema';
new Siema();

...or manually inject the minified script into your website.

<script src="siema.min.js"></script>
<script>
  new Siema();
</script>

Options

Siema comes with a few (optional) settings that you can change by passing an object as an argument. Default values are presented below.

new Siema({
  selector: '.siema',
  duration: 200,
  easing: 'ease-out',
  perPage: 1,
  startIndex: 0,
  draggable: true,
  multipleDrag: true,
  threshold: 20,
  loop: false,
  rtl: false,
  onInit: () => {},
  onChange: () => {},
});

selector (string or DOM element)
The selector to use as a carousel. Siema will use all immediate children of this selector as a slider items. It can be a query string (example) or DOM element (example).

duration (number)
Slide transition duration in milliseconds (example).

easing (string)
It is like a CSS transition-timing-function — describes acceleration curve (example).

perPage (number or object)
The number of slides to be shown. It accepts a number (example) or an object (example) for complex responsive layouts.

startIndex (number)
Index (zero-based) of the starting slide (example).

draggable (boolean)
Use dragging and touch swiping (example).

multipleDrag (boolean)
Allow dragging to move multiple slides.

threshold (number)
Touch and mouse dragging threshold (in px) (example).

loop (boolean)
Loop the slides around (example).

rtl (boolean)
Enables layout for languages written from right to left (like Hebrew or Arabic) (example).

onInit (function)
Runs immediately after initialization (example).

onChange (function)
Runs after slide change (example).

API

As mentioned above, Siema doesn't come with many options - just a few useful methods. Combine it with some very basic JavaScript and voila!

prev(howManySlides = 1, callback)
Go to previous item (example). Optionally slide few items backward by passing howManySlides (number) argument (example). Optional callback (function) available as a third argument (example).

next(howManySlides = 1, callback)
Go to next item (example). Optionally slide few items forward by passing howManySlides (number) argument (example). Optional callback (function) available as a third argument (example).

goTo(index, callback)
Go to item at particular index (number) (example). Optional callback (function) available as a second argument (example).

remove(index, callback)
Remove item at particular index (number) (example). Optional callback (function) available as a second argument (example).

insert(item, index, callback)
Insert new item (DOM element) at specific index (number) (example). Optional callback (function) available as a third argument (example).

prepend(item, callback)
Prepend new item (DOM element) (example). Optional callback (function) available as a second argument (example).

append(item, callback)
Append new item (DOM element) (example). Optional callback (function) available as a second argument (example).

destroy(restoreMarkup = false, callback)
Remove all event listeners on instance (example). Use restoreMarkup to restore the initial markup inside selector (example). Optional callback (function) available as a third argument (example).

currentSlide
Prints current slide index (example).

Browser support

  • IE10
  • Chrome 12
  • Firefox 16
  • Opera 15
  • Safari 5.1
  • Android Browser 4.0
  • iOS Safari 6.0

Extra & Thanks

Siema means 'hello' in Polish. When I play around with some code, I always use random names. That's the whole story behind the name of this one :)

Huge thanks to Jarkko Sibenberg for the cute logo design! I can't thank BrowserStack enough for giving me a free access to their testing amazing service.

siema's People

Contributors

aapokiiso avatar brandon-pereira avatar codyogden avatar dan-gamble avatar danielsamuels avatar hsnaydd avatar ink8bit avatar kimruddock avatar mahmoudmy avatar naggi-goishi avatar pawelgrzybek avatar vinkla avatar znk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

siema's Issues

Infinite loop

Hi, Siema is a great tool. But is it possible to add a infinite loop of elements , and not (as it is now) rewinding back loop ? Thanks. :)

Uncaught TypeError: Cannot read property 'offsetWidth' of null

I have a problem with class .siema where I don't have declaration on the page. I use wordpess and I had declaration only in page front-page.php and I when go to any other website for examaple search.php I have error in my console.

My errror:
main.js?ver=4.7.5:1901 Uncaught TypeError: Cannot read property 'offsetWidth' of null

var mySiema = new Siema({ perPage: { 480: 2, 1024: 3, 1200: 4, }, loop: true, }); document.querySelector('.prev').addEventListener('click', function() { return mySiema.prev(); }); document.querySelector('.next').addEventListener('click', function() { return mySiema.next(); });

Maybe you have any solve my problem.

Move Multiple Slides on Swipe

When swiping multiple slides, slider jumps back, incrementing by a single slide. Would it be possible to have the slider stop on the closest slide after the swipe, rather than incrementing by one?

Responsive breakpoints not working as expected

I would expect the perPage setting to work the same way media queries do, where it takes effect at that pixel dimension, but instead with Siema it seems to take effect at one pixel greater than the number I set.

With my following code, the slider breaks to 2 slides at 481px wide viewport and it should break at 480px:

const mySiema = new Siema({ selector: '#siema', perPage: { 480: 2, 768: 3, 993: 5, 1600: 6, }, loop: true });

Margins between elements

Hi Pawel, do you have an example on how to give some margins between the items?
Thank you!
Mauricio

Unnecessary item wrapping?

A wrapping <div> is added to each item in the carousel, so:

<div style="float: left; width: 16.6667%;">
  <div class="carousel-item">
    carousel item
  </div>
</div>
<div style="float: left; width: 16.6667%;">
  <div class="carousel-item">
    carousel item
  </div>
</div>

Instead of adding the inline styles to the existing children:

<div class="carousel-item" style="float: left; width: 16.6667%;">
  carousel item
</div>
<div class="carousel-item" style="float: left; width: 16.6667%;">
  carousel item
</div>

As far as I can tell, this means equal margins around items (#19) can't be achieved with CSS. I was going to do something like this:

.carousel-item:nth-child(odd) {
  padding-right: 5px;
}

.carousel-item:nth-child(even) {
  padding-left: 5px;
}

To achieve this:

screenshot

Are these wrappers necessary i.e. could the inline styles be added to the existing children instead to ease styling?

And/or maybe siema could add a class to the current far right carousel item so the excess padding could be removed with CSS. The :nth-child approach I mention above can get out of hand quickly, especially with a responsive slider.

Fixed width slides?

Hi, nice and light just the way I like it. Good work dude.

Is it possible to somehow have fixed width slides and align centre?
So a portion of the previous and next slide is also displayed.
The wider the viewport, the more slides displayed.
Like this: https://www.tesco.com/mothers-day/#carousel-personal
The UX fellahs say seeing a partial encourages interaction more so than just buttons.

Auto-Start / Rotate

Hello..
I like how your slider works, but is there an option for it to do an auto-rotate?

I would like it to continue rotating without needing the prev/next buttons.

Thank you for your time and attention..

E2E tests

Siema is a end-user visual component.
So, I propose to add e2e tests and setup CI on travis or appveyor.
It is very simple and I can do this using TestCafe.
What do you think about it?

Events memory leak

The component subscribes to many events behind the scene, and does not seem to unsubscribe later on. The events on the carousel element itself, should be taken care of in modern browser, when they are discarded, but there is a resize event on the window element, and it is an anonymous function, so I don't see any way to unsubscribe the event later. Any advice ?

Carousel with next/prev images in bleed

Hey Pawel, I love the simplicity of the carousel you coded. But I have one question/feature request:

Is it possible to use your carousel to create a view, where I see the next/prev images left and right in bleed and the active image always in center. I think it's a variation of showing 3 images per page but only showing the image in the middle in full.

I have an example attached to show you better what I mean:
screen shot 2016-12-20 at 18 29 11

Thank you very much for your answer in advance.

Best reagards
Chris

Gulp Webapp and Siema is not defined ESLint

Hey, I tried to find any solution but no luck...
While using Yo Gulp Webapp generator I'm trying to build my static website but I got the errors

  45:2   error  Do not use 'new' for side effects  no-new
  45:6   error  "Siema" is not defined             no-undef

It's compiling plugins.js with bootstrap's plugins and Siema.js at the end of the file (so it's ok).
But I have new Siema() included under main.js file which is below everything else and it still can't recognise it.

Any advice?

this.goTo(i) is not a function

Dzień dobry!

I have an error (Uncaught TypeError: this.goTo is not a function
at HTMLAnchorElement.) when adding pagination. What is the problem? Also a question: Should buttons be in .case-slider div?

$(function() {
    var caseSlider = new Siema({
        selector: '.case-slider',
        perPage: 1,
        startIndex: 0,
        draggable: false,
    });
    $('.case-slider-prev').click(function() {
        caseSlider.prev();
    });
    $('.case-slider-next').click(function() {
        caseSlider.next();
    });

    Siema.prototype.addPagination = function() {
        var buttons = $('#similar-projects a');
        for (var i = 0; i < this.innerElements.length; i++) {
            var btn = buttons[i];
            btn.addEventListener('click', function() {
                this.goTo(i);
            });
        }
    }

    // Trigger pagination creator
    caseSlider.addPagination();
});

Extra column of pixels from previous slide is showing in Safari with even-numbered window width

The example slider on the home page for the project shows a single column of pixels from the previous slide when going to the next slide. This is only happening for me in Safari, and only when the window is an even number of pixels wide. This doesn't happen at all, for instance, in Chrome.

I don't think it's a bug with this library, I think Safari must just be doing the translate3d math not quite precisely, but I wanted to record the problem here in case others are having it.

Screencast here: http://d.pr/v/DhOT

One solution I've found is to add left and right padding to each slide, which prevents this "bleeding".

Blurry slides

Sometimes the slides a blurry, because the widths and transforms are a bit too precise. I suggest to round them.
It is the div created by Siema.

width: 455.188px;
transform: translate3d(-227.594px, 0px, 0px);

I'm using Chrome 56 on macOS

Batch updates

Hi thanks for developing this.

I noticed that you call the UpdateFrame function whenever the collection of slides is changed. There must be a significant performance hit associated with this. I wondered if you would consider altering the api to allow batch updates. e.g. append([slide1, slide2], callback). with UpdateFrame being called only once.

Thanks,
Stuart

Do not work in IE11 and Firefox

I'm always more than happy to help you...


Before asking about XYZ, please make sure that the solution ready to copy / paste is not provided on a Siema's CodePen collection: http://codepen.io/collection/Adpkkd/


If you found a bug, there is nothing better for me to understand an issue than quick CodePen / JsBin / JsFiddle example. Please, please, please...


goTo throws an error

When calling goTo on an instantiated carousel, the method errors because this.innerElements is undefined (as is this). This is because of the lambda that is used as shown here:

Siema.prototype.goTo = (index) => {

Happy to fix and PR if you want?

Create tags for recent releases

Thank you for this awesome package, it's a real pleasure to work with!

I see in npm the latest release is marked as 1.4.6, but the JS package manager I'm using relies on the tags in GitHub and currently the latest there is 1.4.2. Please would you be able to create tags for the most recent versions in Git?

Fraction pagination

Is there an easy way to achieve fraction pagination indicators in Siema?

screenshot

If there were 2 slides visible, it would say 2/10.

rtl support

I think its must have today for modern carousel.

cant find

Hi. The site cant find the plugin. Here that writes in console
Uncaught ReferenceError: Siema is not defined

Can plugins conflict with siema?

    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script src="main.js"></script>
    <script src="https://cdn.rawgit.com/asvd/dragscroll/master/dragscroll.js"></script>
    <script src="siema.min.js"></script>

My js code

new Siema({
  selector: '.OS_home__pages',
  duration: 200,
  easing: 'ease-out',
  perPage: 1,
  startIndex: 0,
  draggable: true,
  threshold: 20,
  loop: false,
  onInit: () => {},
  onChange: () => {},
});

My html code

                    <div class="OS_home__pages">
                        <div class="OS__home__1page OS__home__page">
                        </div>
                        <div class="OS__home__2page OS__home__page">
                        </div>
                        <div class="OS__home__3page OS__home__page">
                        </div>
                    </div>

I tried to connect in a huge number of ways but it cant. I tried to download all versions but it doesnt help. Help me please. I really need your plug-in because a slick slider is so bad but it is very popular.

Scrollbar indicator

Last one :) if you've got this I don't have to use a different library!

Is a scrollbar indicator possible with Siema to show progress?

screenshot

Listen for event

I would like to use things like on slide event or init event for an action and also pagination?

Consider a separate file for some inline CSS

I love your implementation to keep the library lean. Thank you.

I have a small feature request, hopefully this is not against your direction. ;)
The request is to agree on Brad Frost's ;)

IMHO, the library can move some non-critical inline CSS rules out into either a separate CSS file, or some recommended CSS rules via prerequisite CSS rules, similar to how you recommended the HTML structures.

For better wordings and example, please see lory.

The following I noticed can be moved out:
Siema selector: overflow: hidden;
Slide item: float: left;
And also cursor stuffs.

This is just an idea, the actual implementation is up to your preference.

.siema {
  overflow: hidden;
  position: relative;
}

.siema .siema__slide {
  float: left;
}

/** Draggable. */
/** is-draggable can be either set by library, or left to users. */
.siema.is-draggable > div {
  cursor: -webkit-grab;
  cursor: grab;
}

/** > DIV is targetting sliderFrame when being pressed down and dragged/swiped. */
.siema.is-draggable > div:active {
  cursor: -webkit-grabbing;
  cursor: grabbing;
}

Hopefully it helps trim out some lines, if not adding more ;)
What do you think? Thanks.

UPDATED: To not add new class "is-pointerdown".

Add TypeScript definitions

I'd like to add TypeScript definitions for Siema, is this something you would be happy to accept as a PR? I have this already written and it would help users that are importing Siema in TypeScript files / users of VS Code.

2 Features/PRs propositions : slideshow & bullets

Hi there, I'm planing to use siema and I will add for my project 2 capabilities to it :

  1. Slideshow feature. It could be a slideshowDelay in the config, expressed in milliseconds, defaulting to 0 (disabled). When enabled it would just go through the slides automatically.

  2. Bullets indicators à la Apple : bulletMarks in the config, default to false, would display a bullet ASCII character for each slide. If true, default colors would apply, With providing an object as the value instead, with active and inactive props, for example, with RGBA values, those customs colors would apply.

I can either add these features in my app, or add one or both to your component and propose a PR.

Tell me if it's something you're interested in !

BTW Thanks for this OSS component :-)

Fade animation and free mode

I don't found solution for fade animation, for example on desktop fade animation and mobile swipe animation.
About Free mode, on swipe mobile free mode like scroll.

perPage: 'auto' possible?

Update package.json main entry

Siema's package.json file specifies src/siema.js as the main entry point. I am excluding transpilation of code in the node_modules folder and so src/siema.js is not being transpiled to ES*. This means that when I import Siema, the code that is written in ES6 is not transpiled down and the plugin fails in IE and Firefox.

The package.json main entry point should be changed to dist/siema.min.js.

Happy to PR.

How to implement for multiple sliders on the same page?

I have a grid of products, trying to have Siema load on each card. How would you recommend I init Siema for each of the elements with the 'siema' class on a page? Or do I have to set it up to init Siema per parent object, on the div.siema inside each div.product-container ?

Feedback

YOU ARE FOCKING AWESOME. THANK YOU FOR SHARING IT, SAVED A LOT OF TIME.

Next() is not working when perPage option is larger than the number of slides available

What is happening

Hi! The carousel drag is becoming unresponsive when you use the next() method. This is only happening if the number of slides to be shown is larger than number the slides available. Here an example with 4 slides and 5 perPage slides showing this behaviour.

More info that may help

  • This seems to affect only next().
  • The carousel will work as expected when passing a number with the goTo() method.
  • currentSlide is returning -1 when next() is used.

Options for disabling prev and next buttons

Thanks for the work on Siema!! Really enjoying the lightweight, no dependency solution.

I like the solution for infinite looping submitted in #58. While that's still in the works I wanted to disable and enable previous or next buttons (or hide and remove arrows) if it's the first or last slide. In the pen below you can see I target the siema element and count it's children and subtract by 1 to get the number of slides in the carousel. From there, if the currentSlide equals the modified number I just grabbed right before matches and then disable the "next" option in this case. In production I might use an arrow or some other indicator but either way I want to dynamically know when I'm on the last slide.

https://codepen.io/matt_jared/pen/proYVr

My question: Is there a better way to do this? There will have to be even more conditional logic if the number of slides visible changes at multiple viewports. If #58 is going to be merged in somewhat soon this might not be necessary but I feel like being able to disable / enable the last element a little more elegantly than what I'm capable of might be a nice option as a Codepen example even for folks in the future. Thanks for your time! =]

Infinite loop

First of all, the plugin is great, very lightweight with friendly API. I had to resign from using it in my company project, because of missing infinite loop mode. Back to the begin of items list is very ugly. I think that many users could have similar fellings.

Update / Re-render slides method

Hi! I've been using Siema for a Vue.js project and I have to say it's pretty useful. Recently I ran into a problem when trying to load the slides dynamically. I managed to fix the issues, but my solution is far from elegant.
See example

My problem
Slides are loaded asynchronously, so the Siema object is already rendered when the slides arrive.

My solution
Render an empty Siema object and when the async slides arrive, destroy the object and create it again.

Proposal
It would be useful to have a method to recalculate the slides instead of deleting and creating.

Thanks in advance!

[Question] Responsive per page

Love the simplicity of this after finding out about it today, however I was wondering how you'd recommend making it responsive? e.g

perPage 1

> 768px
perPage: 3

Additionally, if there is any scope for adding event listeners? e.g. changed, init etc?

Prevent vertical scrolling while touch swiping

Hey,

I've implemented Siema and have got it working how I want, but while swiping on mobile, the page slides up and down at the same time as the gallery moving left (or right).

It'd be great to be able to lock down the vertical scrolling while horizontal movement is happening. I've had a play around and can't yet find a reliable mechanism for doing this, any suggestions?

Thanks a lot!

Custom settings via data attributes

This is only an idea, something as follow

<div class="siema" data-loop="true" data-duration="500">
  <div>Hi, I'm slide 1</div>
  <div>Hi, I'm slide 2</div>
  <div>Hi, I'm slide 3</div>
  <div>Hi, I'm slide 4</div>
</div>

Normally, this is how works a good jQuery plugin by using $.extend() but it's good also for a pure Javascript as Siema is 😄

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.