Coder Social home page Coder Social logo

codeinwp / ideal-image-slider-js Goto Github PK

View Code? Open in Web Editor NEW
1.6K 69.0 160.0 6.42 MB

Quite simply the ideal Image Slider in vanilla JS.

Home Page: http://idealimageslider.com

License: GNU General Public License v3.0

JavaScript 72.27% CSS 19.19% HTML 8.54%

ideal-image-slider-js's Introduction

Ideal Image Slider

The aim behind the Ideal Image Slider is to create a slider which has just the right amount of features, with no bloat and be easy to extend so that more features can be added as "extensions". Here are the ideals and core features I wanted to include:

  • HTML5 (SEO optimised)
  • CSS3 transitions (a few simple transitions like slide/fade)
  • Left/Right navigation (including touch/swipe support)
  • Responsive
  • HiDPI (retina) support
  • ARIA support
  • Extremely simple to setup (no dependencies)
  • Very extensible
  • Uses progressive enhancement
  • Open source (goes without saying)

And, as an example, here are some features that should not be in the core and could be optional extensions:

  • Themes or skins
  • More transitions
  • Bullet navigation
  • Thumbnail navigation
  • Full screen slider
  • Video/Audio support
  • etc...

Read the original blog post โ†’

Demos

Extensions

Requirements

  • None

Ideal Image Slider is written in vanilla JS and has no dependancies.

Getting Started

To install the slider you can either manually download this repository or you can use Bower and run the following command:

bower install ideal-image-slider --save

Next you need to include the CSS file in the <head> section of your HTML and you need to include the script before the </body> tag in your HTML. Note you can optionally include a theme CSS file in the <head> too.

<html>
<head>
	...
	<link rel="stylesheet" href="/path/to/ideal-image-slider.css">
	<link rel="stylesheet" href="/path/to/themes/default/default.css">
	...
</head>
<body>
	...
	<script src="/path/to/ideal-image-slider.js"></script>
</body>
</html>

Next you need to set up your slider HTML where you want it to appear in your page. It should look something like this:

<div id="slider">
	<img src="img/1.jpg" alt="Minimum required attributes">
	<img data-src="img/2.jpg" src="" alt="Use data-src for on-demand loading">
	<img data-src="img/3.jpg" data-src-2x="img/[email protected]" src="" alt="Use data-src-2x for HiDPI devices">
	<a href="http://example.com"><img data-src="img/4.jpg" src="" alt="Links work too"></a>
	...
</div>

There a few things to note about the structure of the images in your slider:

  • This is an image slider, so only images are supported. Any other content will be removed.
  • You can use the data-src attribute to load your images "on-demand" (i.e. images are not loaded until they are required).
  • The first image should not use data-src so it is loaded if no JS is detected.
  • If you specify a data-src-2x image, it will be used on devices that support HiDPI (such as Apple's retina devices).

Finally you can create your slider by using the following Javascript:

new IdealImageSlider.Slider('#slider');

If you want to tweak the settings or use the slider API it would look more like:

var slider = new IdealImageSlider.Slider({
	selector: '#slider',
	height: 400, // Required but can be set by CSS
	interval: 4000
});
slider.start();

Note: If you don't pass a height to the Javascript constructor you must set it in your CSS.

Settings

Setting Default Value Description
selector '' CSS selector for the slider
height 'auto' Height of the slider. Can be 'auto' (height changes depending on the height of the slide), a fixed px value (e.g. 400) or an aspect ratio (e.g. '16:9')
initialHeight 400 If height is 'auto' or an aspect ratio this is the height of the slider while the first image is loading
maxHeight null If height is 'auto' or an aspect ratio this is an optional max height in px for the slider (e.g. 800)
interval 4000 Time (in ms) to wait before changing to the next slide
transitionDuration 700 Duration (in ms) of animated transition
effect 'slide' Transition effect (slide/fade by default)
disableNav false Toggle the previous/next navigation (also disables touch and keyboard navigation)
keyboardNav true Toggle keyboard navigation
previousNavSelector '' Selector for custom previous nav element
nextNavSelector '' Selector for custom next nav element
classes {...} List of classes to be used by slider. Probably shouldn't be changed

Events

Event callback functions can be passed in with the settings. For example:

new IdealImageSlider.Slider({
	selector: '#slider',
	onStart: function(){
		console.log('onStart');
	}
});
Event Description
onInit Callback that fires when slider and first image have loaded
onStart Callback that fires when slider has started playing
onStop Callback that fires when slider has stopped playing
onDestroy Callback that fires when slider is destroyed
beforeChange Callback that fires before a slide has changed
afterChange Callback that fires after a slide has changed

API

To use the API methods you must store the slider object. For example:

var slider = new IdealImageSlider.Slider('#slider');
slider.start();
Method Description
start() Start the slider. Note the slider will automatically be stopped when navigation is used
stop() Stop the slider
previousSlide() Change to the previous slide
nextSlide() Change to the next slide
gotoSlide(index) Change to a specific slide (1 indexed)
destroy() Destroy the slider
get(attribute) Get an attribute value (attributes are mostly used internally)
set(attribute, value) Set an attribute. Can be useful for storing custom data

Browsers

Ideal Image Slider has been tested on:

  • Chrome
  • Firefox
  • Safari (Desktop + Mobile)
  • Opera
  • IE9+

Contribute

So you want to help out? That's awesome. Here is how you can do it:

If you are submitting a pull request please adhere to the existing coding standards used throughout the code and only submit 1 feature/fix per pull request. Pull requests containing multiple changes will be rejected.

Note that if you submit a pull request you are aware that you are contributing to both the free (open source) version and the proprietary (commercial) version of the codebase and that your work may make money for Dev7studios.

Credits

Ideal Image Slider was created by Gilbert Pellegrom from Dev7studios. Released under the GPL license.

Other Projects

Check-out other stuff that we are working on :

ideal-image-slider-js's People

Contributors

7yl4r avatar acechase avatar gilbitron avatar ineagu avatar navstyachka avatar quasipickle avatar tombyrer 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ideal-image-slider-js's Issues

targeting model window

I think there is a javascript hack/workaround ...but I have not been able to natively use data-links on the images to launch modal windows (instead of standard page links). Is there a jquery/js function that I could use?

Scroll Prevention for touch devices

Most users to not swipe on a perfectly straight X axis, which makes the swiping on this app inconsistent.

Most of the time the slider just skips to the next slide rather than transitioning.

Check this video for an example: http://wes.io/XNBa - every single time I intend to swipe, but the page scrolls up and down and skips the slide to the next.

Swipe.js has a fantastic implementation of this: http://swipejs.com/ - the project is dead but I still use this slider in every project because of the scroll prevention and the "scroll as you touch" effect as pointed out in #13

height didn't set properly

As suggest, i didn't pass a height value to object constructor in order to let CSS handle the style. But it doesn't work, Ideal-Image-Slider override the slider style directly to the element.
Any help will be appreciated.
js:

<script>
    var slider = new IdealImageSlider.Slider({
        selector: '#slider',
        interval: 3500,
        keyboardNav: true,
    });
    slider.addBulletNav();
    slider.start();
</script>

css:

 #slider {
    height: 90%;
 }

Error when trying to get this work

Uncaught TypeError: Property 'hasOwnProperty' of object object is not a function at file:///android_asset/www/js/ideal-image-slider.min.js:2

Swipe is not direction aware

IIS 1.4.0, iOS 8:
Holding phone in left hand. Swipe from left to right with the thumb. Image enters the viewport from the right and slides towards left. Feels very counterintuitive.

Would feel much better if the swipe direction influenced the transition direction.

I suppose the same applies to the Next/Prev clicky buttons too.

How can I set the height of the div slider to be the same as the content?

I'm using bootstrap on my site and I need the height of the div slider to be the same as the content. How can I do this?

I did this so the image is shown but the height of the div slider is always the same.

slider a {

background-size: contain;

}

If I apply <div id="slider" style="overflow: hidden;"> it wont work either.

Partially broken in Firefox

I just tried the slider in FireFox 32 and it does not quite work. It shows and swaps the images, but there is no transition and no navigation arrows.

deepExtend typo

Hi,
I was looking over the code and I noticed a typo deepExtend is not defined here

    var _deepExtend = function(out) {
        out = out || {};
        for(var i = 1; i < arguments.length; i++){
            var obj = arguments[i];
            if(!obj)
                continue;
            for(var key in obj){
                if(obj.hasOwnProperty(key)){
                    if(typeof obj[key] === 'object')
                        deepExtend(out[key], obj[key]); // should be _deepExtend
                    else
                        out[key] = obj[key];
                }
            }
        }
        return out;
    };

HTML 5

The slider must use HTML5 and be SEO friendly.

Linking Slides in IE11

Turning the slides to links:

<a href="http://google.com"><img src="/Ideal-Image-Slider/public/img/1.jpg" alt="Slide 1"></a>

Works in Firefox/Chrome, however in IE11 it creates a white space where the slide should be.

Aspect Ratio / Cropping on Resize

Hello!

First of all, love the plugin!

The fixed height of the slider means that the image doesn't respond with the correct proportions: you end up with a totally different aspect ratio and the image is cropped.

Do you have any plans to address this?

Cheers,
Dave

Perhaps a bug

File ideal-image-slider.js
Line 115
slide.style.removeProperty('-0-transform');

Image goes black when I hover over it with mouse

Environment: rails 3.2.12

I am trying to create a view on my home page, with a "slide show" effect. Here's what I did:

I placed the images in the following folder:

assets/slider-images/

I added the following to the gemfile:

gem 'rambling-slider-rails'

Here's what I have in my app/assets/javascripts/application.js

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery-ui-timepicker-addon
//= require_tree .
//= require bootstrap
//= require bootstrap-datepicker
//= require tinymce
//= require jquery.rambling.slider

I added the following to app/assets/stylesheets/application.css.erb

*= require jquery.rambling.slider

I added the following to the head section of app/views/layouts/application.html.erb:

<head>
  <%= stylesheet_link_tag 'jquery.rambling.slider' %>
  <%= javascript_include_tag 'jquery.rambling.slider' %>
</head>

And in my app/views/pages/home.html.erb

<div id="wrapper">
  <div class="slider-wrapper theme-default">
    <div class="ribbon"></div>
    <div id="slider" class="ramblingSlider">
      <%= link_to(image_tag('slider-images/sample1.jpg'), conference_path) %>
      <%= link_to(image_tag('slider-images/sample3.jpg'), conference_path) %>
      <%= link_to(image_tag('slider-images/sample4.jpg'), conference_path) %>
    </div>
  </div>
</div>


$(window).load(function(){
   $('#slider').ramblingSlider();
});

After I updated the server, I issued the following command:

RAILS_ENV=test bundle exec rake assets:precompile

and restarted the apache server.

Everything is working fine, with the exception of the following: when I hover the mouse over the image, it turns black. Any ideas?

Height not changeable by media queries

If I do not include height: in the new IdealImageSlider() options, but I DO include height in my CSS, the CSS height is not used, and the slider box defaults to 400px.

I have included media queries to change the overall size of the slider. Width is working, but height is not because the IIS appears to be inject a style="" to force the height to whatever I included at the time of creation. It appears to be not editable after that.

Multiple sliders from class

Hello,

First of all, great job, I totally love your hard work !

Would it be feasible to use QuerySelectorAll instead of QuerySelectorin order to declare the slider with a class selector so the slider is applied on each item ?

Cheers

Vertical slide transition

Would be nice to have a vertical slide animation too:

var slider = new IdealImageSlider.Slider({
    selector: '#slider',
    'effect': 'slide-vertical'
});

Single Slide Issue

It appears that if you have only one slide, instead of showing the slide it just shows a blank white space the size the slide would be.

iOS 8 Next & Prev Controls Don't Display

IIS 1.4.0, iOS 8, Safari

Next and Prev controls (< >) don't display on iOS Safari. I'm using SVG images, but otherwise using your default theme for testing. Works fine on desktop browsers, and responds correctly to all my media queries on the desktop based on changing the window width. The dots show up fine (but they don't work correctly -- I suspect related to the tap bug report just filed).

Web component?

This project would be perfectly suited to be a packages as a web component.

Slider stopped

Probably this is intended, but:
When I open another window or tab, the slider is stopped.
Same happens if I blur the slider window (for instance, if I cmd + tab in the OS)

Tested in latest Chrome and Safari 8.

Is there a workaround for this?

iOS 8 Tap Slider Viewport Render Error

IIS 1.4.0, iOS 8, Safari

Not sure if this is an IIS thing, or an iOS 8 Safari thing, but if I tap the slider viewport instead of swiping, the second image slides in all the way to the left of the first image. Both images stay visible. Further taps do nothing, but swipes will still work.

In fact, I see several rendering errors with multiple images being visible based on where I tap in the slider (I'm testing with only two).

No Fade Transition on iOS 8

IIS 1.4.0, iOS 8, Safari

Not sure if this is an IIS thing, or an iOS 8 Safari thing, but with IIS set up to use a fade transition, on iOS 8, it still shows the sliding transition.

Better touch navigation

Current touch nav is sluggish and unresponsive. Would like to see "move as you swipe" behaviour.

persistent loading icon over first slide

On my slideshow the loading icon on the first slide never goes away.

html:

<div id="gallery-slider">
  <img src="img/gallery/original1989.png" alt="Original 14 pulsars recomputed.">
  <img data-src="img/gallery/tooMany.png" alt="ALL THE PULSARS! ">
</div>

I'm loading the slider inside a vex modal which is inserting an iframe, so perhaps that is why I am encountering this issue. Likely not worth fixing, but I wanted to document it nonetheless.

loading spinner

is there a way to disable the loading spinner? it appears after each slide, would be nice to remove it entirely

Stock Droid Browser Nonfunctional

This might be related to #31 : on the Android stock browser ("Internet") on my Galaxy S3 (Droid version 4.4.2) the 'new IdealImageSlider.Slider' call crashes with:

Uncaught TypeError: Property 'hasOwnProperty' of object object is not a function

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.