Code Monkey home page Code Monkey logo

flux-slider's Introduction

Flux Slider

Flux slider is a CSS3 animation based image transition framework, inspired in part by the fantastic Nivo Slider jQuery plugin.

Instead of the traditional Javascript timer based animations used by jQuery, Flux utilises the newer, more powerful CSS3 animation technology. Its in a fairly early/rough state at the moment but testing on the iPhone/iPad does appear to produce much smoother animations. Desktop performance (as with Nivo) is very smooth but the use of CSS3 enables us to produce some new effects that Nivo can’t, e.g. rotations.

The aim is to use hardware acceleration where possible to improve performance on less powerful devices, such as mobiles & tablets.

Known to work with

  • Safari
  • Chrome
  • iOS
  • Blackberry Playbook
  • Firefox 4
  • Opera 11

May/should also work for

  • Android (Known to be jerky due to lack of hardware acceleration)

Requirements

Flux requires a browser which supports CSS3 transformations and has been built to use either jQuery or Zepto.js as they share the same API. For mobile deployment Zepto is recommended due to its <5k deployment footprint.

Usage

Create HTML markup with the images you wish to use. You can also wrap images in a link if you need them to be clickable. For example:

<div id="slider">
	<img src="img/avatar.jpg" alt="" />
	<img src="img/ironman.jpg" alt="" title="Ironman Screenshot" />
	<a href=""><img src="img/imagewithlink.jpg" alt="" /></a>
	<img src="img/tron.jpg" alt="" />
</div>

Next instantiate Flux Slider:

$(function(){
	window.myFlux = new flux.slider('#slider');
});

Or, if you're using the provided jQuery widget then you can also do the following:

$(function(){
	window.myFlux = $('#slider').flux();
});

Note: If you plan to use the Zepto framework then the widget method won't work

A note on feature detection

Flux now makes use of Modernizr when available for feature detection. Flux does not require Modernizr but it will use it instead of the inbuilt code if it's loaded.

Note: If you have a need to initialise Flux before the $.ready() event (not recommended!) then you will need to use Modernizr for feature detection as the inbuilt code does not play well with an uninitialised DOM.

Configuration options

The <flux.slider> constructor can also take an optional second parameter which is an object of key/value configuration options.

  • autoplay Boolean (default: true)

    Whether or not the slider should start to play automatically

  • pagination Boolean (default: false)

    Whether or not to show a pagination control for manually selecting the image to show

  • controls Boolean (default: false)

    Whether or not to show a next/prev controls

  • captions Boolean (default: false)

    Whether or not to show a caption bar. Captions are read from the title attribute of loaded img elements

  • transitions Array (default: all available transitions)

    An array with the names of the transitions to use, available options are:

    • 2D
      • bars
      • blinds
      • blocks
      • blocks2
      • concentric
      • dissolve requires mask support
      • slide
      • warp
      • zip
    • 3D
      • bars3d
      • blinds3d
      • cube
      • tiles3d
      • turn
  • delay Integer (default: 4000)

    The number of milliseconds to wait between image transitions

For example, to prevent autoplay and show a pagination control you would do the following:

$(function(){
	window.myFlux = new flux.slider('#slider', {
		autoplay: false,
		pagination: true
	});
});

Or with the jQuery widget:

$(function(){
	window.myFlux = $('#slider').flux({
		autoplay: false,
		pagination: true
	});
});

flux.slider API

The API functions work with both the native Javascript object and the jQuery widget. For example:

// Show next image using the bars3d transition (native Javascript object)
window.myFlux.next('bars3d');

or

// Show next image using the bars3d transition (jQuery widget)
window.myFlux.flux('next', 'bars3d');

Note: All the jQuery widget functions are chainable except those that return something specific, such as isPlaying() & getImage().

For more information on using jQuery widgets see the jQuery Doc's;

Play controls

  • start() Enable autoplay
  • stop() Disable autoplay
  • isPlaying() Returns a boolean as to whether autoplay is currently enabled

Transport controls

  • next([transition [, options]])

    Show the next image.

    transition (optional) The name of the transition to use, otherwise one picked at random

    options (optional) Transition specific options for this transition only

  • prev([transition [, options]])

    Show the previous image.

    transition (optional) The name of the transition to use, otherwise one picked at random

    options (optional) Transition specific options for this transition only

  • showImage(index [, transition [, options]])

    Show the image at index.

    transition (optional) The name of the transition to use, otherwise one picked at random

    options (optional) Transition specific options for this transition only

Misc

  • getImage(index) Returns the image with the provided index

Receiving notification when a transition completes

There are occasions where you may wish to know when a transition has completed, or that the currently displayed image has changed.

Flux provides a couple of mechanisms for this:

fluxTransitionEnd Javascript Event

After each transition, Flux dispatches a fluxTransitionEnd event. To listen for these events you can do the following:

$('#slider').bind('fluxTransitionEnd', function(event) {
	var img = event.data.currentImage;
	// Do something with img...
});

onTransitionEnd callback function

You can alternatively pass in a callback function as part of the configuration options when you instantiate Flux, e.g.

window.myFlux = $('#slider').flux({
	autoplay: false,
	pagination: true,
	onTransitionEnd: function(data) {
		var img = data.currentImage;
		// Do something with img...
	}
});

Writing custom transitions

Writing your own custom transitions is easy, you just need to create an instance of a flux.transition object and pass in some callback functions to provide the custom behaviour you're looking for.

Lets look at the built in bars transition as an example. The barebones definition of the transition looks like:

flux.transitions.bars = function(fluxslider, opts) {
	return new flux.transition(fluxslider, $.extend({
		barWidth: 60,
		setup: function() {
			
		},
		execute: function() {
			
		}
	}, opts));	
}

Here we add a new function to the flux.transitions namespace called bars. This function takes two parameters, a flux.slider object and an options key/value object.

Note: Its currently not possible to pass options into transitions from the core flux.slider code but as this is on the list of things to add its a good idea to make sure the transitions can handle this when its implemented!

The function we create should return a new flux.transition object, passing in the flux.slider parameter along with a set of options.

All transition objects automatically have access to the following:

  • this.slider

    The flux.slider object passed into the constructor. From this object you can access the current image this.slider.image1 and the next image this.slider.image2.

  • this.options

    The options passed in as the 2nd parameter to the flux.transition constructor call.

setup()

Two functions are needed for the transition to operate, first is setup. This function is responsible for initialising the DOM before the transition runs. In the case of the bars transition this function creates a div for each bar and set the background image so that adjacent bars appear as a single image.

The setup function should also initialise the CSS3 properties needed to enable a CSS transition.

setup: function() {
	var barCount = Math.floor(this.slider.image1.width() / this.options.barWidth) + 1

	var delayBetweenBars = 40;

	for(var i=0; i<barCount; i++) {
		var bar = $('<div></div>').attr('class', 'bar bar-'+i).css({
			width: this.options.barWidth+'px',
			height: '100%',
			position: 'absolute',
			top: '0',
			left: (i*this.options.barWidth)+'px',
		
			'background-image': this.slider.image1.css('background-image'),
			'background-position': '-'+(i*this.options.barWidth)+'px 0px'
		}).css3({
			'transition-duration': '400ms',
			'transition-timing-function': 'ease-in',
			'transition-property': 'all',
			'transition-delay': (i*delayBetweenBars)+'ms'
		});
		this.slider.image1.append(bar);
	}
}

A helper function called .css3() has been created for convenience to automatically add vendor prefixes to CSS3 properties. Any properties that require prefixes should be added via this function rather than .css() as this ensures that transitions are cross-browser compatible.

execute()

The execute function is where the CSS changes should be made, as transitions have already been initialised in setup() applying the end CSS property state should be all thats required:

execute: function() {
	var _this = this;

	var height = this.slider.image1.height();

	var bars = this.slider.image1.find('div.bar');

	// Get notified when the last transition has completed
	$(bars[bars.length-1]).transitionEnd(function(){
		_this.finished();
	});

	bars.css({
		'opacity': '0.5'
	}).css3({
		'transform': flux.browser.translate(0, height)
	});
}

Two further convenience functions have been used in this example. The first .transitionEnd() is a cross-browser event function to catch the 'transition end' event. In this example we want to be notified when the final bar as finished animating, this is how we know the transition is complete. We can then perform some custom code but its important to remember to call the transitions finished() function to ensure that the DOM is reset for the next transition.

Transition writing guidelines

Here are some guidelines for writing transitions if you'd like to have them considered for inclusion into the main distribution:

  • If the transition requires 3D transforms you must set the requires3d property to true. e.g.

    flux.transitions.bars3d = function(fluxslider, opts) {
    	return new flux.transition(fluxslider, $.extend({
    		requires3d: true,
    		setup: function() {
    			...
    		}
    	}
    };
    
  • For delaying animations to specific bars/blocks/tiles use -[webkit/moz/o]-transition-delay rather than setTimeout()/setInterval(). This enables the GPU to handle the timing and makes for smoother transitions.

  • When using many new bars/blocks/tiles, add them to a container element off DOM and then add the container in one go, e.g.

    var container = $('<div></div>');
    
    for(var i=0; i<10; i++) {
    	var elem = $('<div></div');
    	container.append(elem);
    }
    
    this.image.slider1.append(container);
    

flux.browser

flux.browser is an object designed to help determine browser support for CSS3 transitions.

  • supportsTransitions Boolean

    Does the current browser support CSS3 transitions?

  • supports3d Boolean

    Does the current browser support 3D CSS3 transitions?

  • translate(x, y, z)

    Returns a CSS translate string most suitable for the current browser, for example under iOS where 3D transformations are supported flux.browser.translate(10, 20) would return translate3d(10, 20, 0) so as to trigger hardware acceleration.

  • rotate(axis, deg)

    Operates the same as the above translate function and returns the most suitable CSS for the current browser.

  • rotateX(deg)

    Returns the result of calling flux.browser.rotate('x', deg) Requires 3D transformation support

  • rotateY(deg)

    Returns the result of calling flux.browser.rotate('y', deg) Requires 3D transformation support

  • rotateZ(deg)

    Returns the result of calling flux.browser.rotate('z', deg)

License

Flux is Copyright Β© 2011 Joe Lambert and is licensed under the terms of the MIT License.

flux-slider's People

Contributors

joelambert 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flux-slider's Issues

Manual Navigation

Hello...can u show me how to make manual navigation with this slider?
I want to make the main menu of the website that I make with this slider, just like amazon...but this time using your awesome flux slider. So I want to give 4 menu (wtih text or image), and when someone click the navigation, it will show the slider with the effect.

Thank you

choose transitions

Can you post an example code for how to select transitions effect with array sintax?

delete

delete me i have written an error issue

Backface visibility(?) flaky after focusing form elements in Safari

I'm experiencing the issue with Safari 5.1.7 on Windows 7 x64 using the latest Flux-Slider revision from github.

You can reproduce it by simply adding a form element to the demo page, for example a text input, or a select element. Click in, or just focus the form element (note that buttons won't cause the behaviour when clicked), and then start the Bars 3D transition. You should now see that the bars are flickering as if the backface visibility goes on/off/on/off/on/off in some areas.

I haven't found a workaround or fix yet, but i'll let you know in case you're not beating me to it :)

Regards
Timo

bar 3D bug

Try with 1024 x 768 sized images for instance.

preload images

I think that preload images is a good configuration option for new release.
Can you add it please?

Fallback mode for older browsers?

Is there a plan to add some sort of graceful degradation for older browsers? As it is now it just stops working with an alert message, would be nice that it'd still work at least with a simple fade transition

Implement a "feature testing" and not a browser testing.

As soon as firefox 4, ie10 and others start supporting css animations/transitions, the code that checks only for webkit engine will start to fail.
Instead can check for the specific set of functions modernizr style and if all checks pass, let users see the flux.

Doesn`t work in IE

Hello,
I tested http://www.joelambert.co.uk/flux/ .

I get an Error that my browser does not support css3 transitions and i get a error that the browser also isn`t able to use 3d transform!
Tested in IE 10 and 11 on windows 8.1 as operating system.

In Mozilla are the images sometimes only half shown. Briefly the images get halved!

Transition suggestions

Awesome slider!

Would be even cooler if there were additional options to control...

  1. the direction of the transitions (e.g. to allow selection of any possible directions for each one)
  2. the number of tiles/slices used in a given transition (throttling this automagically would be fantastic but probably not doable)
  3. the duration of each transition (currently hardcoded to 400ms?)

And simple vertical and horizontal 3d flip (i.e. rotation about the central axis) transitions would be great too.

RTL support

Hey and thanks for the great works , is RTL in the project roadmap ?

Move the CSS styles out of JS

The CSS styles for the helper elements (pagination, caption, next/previous links) should be moved to an external CSS file, to allow easy overriding and customization. Otherwise, we have to use the !important flag to override the inline styles set by the JS code.

The next/previous buttons don't even have a class name set, so customizing them without CSS3 selectors is very difficult.

pagination

Hi Joe, thanks for the great slider. Love it so much!
But I have some problems about the pagination. I want to make the pagination from image that can be changed when the current page is active. So the image is different between the non-active image with the current image. I've successfully change the pagination number become image but can't make it change with the image transition. How can i do that?

Big thanks!

Fast consecutive transitions not handled ideally

I'm not sure what an image gallery should do when I flick through images fast, but Flux Slider's implementation feels less than ideal.

Clicking any button on http://www.joelambert.co.uk/flux/transgallery.html several times results in any previous transitions being skipped, so that the one triggered by the very last click can start straightaway. To get a more smooth experience, personally, I'd rather create a chain or queue of transitions, so that transitions have to wait for previous ones to complete.

Of course, many clicks would introduce a potentially annoying delay. Perhaps transitions could be sped up or skipped when the queue size reaches a certain threshold? Just an idea.

Also, the current implementation isn't necessarily bad, so there should probably be a toggle parameter in the API.

Regardless, keep up the good work!

jQuery noConflict

Hi,

please wrap your code inside a closure so jQuery.noConflict works as expected.

This worked for me:

(function ($) {
//..
window.flux = flux;
} )( jQuery );

Can't open a pull request from here as I am in customers buro atm. If you want me to fork and pull that let me know.

best regards and nice work

Sebastian

Concentric and Warp cause image's position shift before transition.

I forced the the slider's size to 800x600 during initialization:

window.myFlux = new flux.slider('#slider', {
autoplay: false,
captions: true,
controls: true,
width: 800,
height: 600
});

Each image in the slide has different size. For both Concentric and Warp transitions, the image's position is shifted before the animation start (usually about 50~100 pixels toward the top left but it varies)

Timer not reset when user changes slides manually

When using automatic transitions, the timer should be reset when the user changes slides on their own. Currently, the timer keeps going, leading to unexpected behavior if a user changes slides near the automatic transition time (ie, they choose the slide, and then very shortly after, it transitions again)

How can we fit retina image within slider boundaries?

Hi,
First off I wanted to thank you for this very fine piece of software.
Now my request: is there a way you can use images twice as big as the slider size without cropping them?
I tried to experiment a bit with jQuery but I couldn't come up with anything.
Do you have a clue?
Thank you very much and keep up the good work.
Yannick

Flash of black

I have the wp-plugin version running here: http://shandobilcommunications.com/about/ and if I click away from the page and click back, sometimes the whole window flashes black when the slideshow transitions. I'm working on pinpointing the problem, but I thought I'd post just in case this was a known issue.

Callback after imageanimation ends.

It it possible to set a callback that is called if the imageanimation ends? I would like to use flux as clickable slider.

 <a href="#dynamicUrlChangedByFluxl">
 <div id="slider">
     <img><img><img>
</div>
</a>

Thx.

Blinds3D number of blinds?

Hi,

Sorry if this is not the place to post such a question - can you specify the number of columns that make up the Blinds3D transition?

Thanks,
Steven

CSS 3D Transforms not detected on Firefox 10

Now that Firefox 10 has CSS 3D transforms, the Flux Slider should use them but it still complains that the browser does not support 3D transforms.

Seems to me the detection code is wrong.

Hope you can fix it Joe!

Greetings,
George Petrov

Help, please

Hi, I'm extremely new to html, css, jquery etc. I have a class assignment to build a website in dreamweaver, coz we just learnt how (yay!). and I really want to impress my lecturers and classmates during my presentation, could you please help me and tell me what to do if I want to take out the transition list from the side and just use the 'bars 3d' transition whenever an image is clicked on? I should mention that my assignment is due in 2 days... any help would be appreciated πŸ˜ƒ

Tag A for Link

Hi,
I have some problem to catch link in:

Example:

  <a href="#link1"><img src="a.png" /></a>
  <a href="#link2"><img src="a.png" /></a>
  <a href="#link3"><img src="a.png" /></a>
</div>

Is link unsupported? Or I wrong something in CSS?

regards
GF

Flash of next image during transition to previous

I'm using the 'slide' transition. It looks great sliding left with .next() but when sliding right with .prev() the image revealed during the slide is the next one rather than the previous one. When the transition is complete, the image switches to the correct (previous) one.

Any idea what's causing this? Thanks!

onTransitionStart event

I think it would be great if there is an onTransitionEnd event so that I can manipulate the blocks when a transition occur. Thanks, Great work by the way :)

Possible memory leak on Safari

I am using Flux together with Zepto showing 1080p images on big television screen. Flux is used as kind of a screensaver. There is also an information box over the image. This is just some HTML. Code is the following.

var screensaver = new flux.slider("#screensaver", {
    autoplay: true,
    delay: 12000,
    pagination: false,
    transitions: ["dissolve"],
    onTransitionEnd: function(data) {
        /* Show correct information box,*/
        var index = screensaver.currentImageIndex;
        $(".box").addClass("hidden");
        var box = "#box-" + index;
        $(box).removeClass("hidden");
    }
});

However I noticed that something leaks memory. When slideshow starts Safari Web Content uses 150MB memory.

screenshot_353

After 20 minutes it already uses around 400MB

screenshot_354

Eventually it fill the memory and computers will grind to halt

Can't get transitions to work?

Ok, so before anyone else says. I'm more or less a noob when it comes to certain things!

I have been able to implement the slider, however i cannot specify a transition? Am i calling it in the wrong place?

 window.f = new flux.slider('#slider',  {
            autoplay: true,
                pagination: false,
                transitions: bars3d

});

});

Prevent running on FF<4

Is there any way not to display it on any versions of FF < 4?

What is your usecase for this? Is is that you don't want it to run in FF<4 because it doesn't support transitions? If so then a better solution is to only show Flux when CSS transitions are supported by the browser.

To do this you can do something like

if(flux.browser.supportsTransitions) {
    window.f = new flux.slider('#slider');
}
else {
    // Do something else
}

If instead you have some genuine need to do browser sniffing then I suggest you search for regex expressions for filtering FF<4

Hope that helps?

Image slide with different size

Hi,
thiere is a way to use this amazing slider with a list of images with different size?

Example:

  <img src="a.png" /> <!-- 320x256 -->
  <img src="b.png" /> <!-- 640x640 -->
  <img src="c.png" /> <!-- 512x300 -->
</div>

Thanks, regard
GF

fullscreen image support

Cool component!
is it possible to support image displayed in full screen and can resize if the browser window resized?

Captions with HTML formatting

I think it will be much better if we could be able to use HTML formatted text in captions. For example i want that my captions contain some heading, some small description and hyper link. But if the Flux read the caption's content from the img title attribute it is almost impossible. Of course we can use something like that : <img src="..." title="<h1>Some Heading</h1>.." but it is not really comfortable ;)

Browser Issues

I got the flux slider working generally fine. However im having problems with the way some browsers display the transitions. Im using autoplay and caption = true and bars3d transition effect.

  1. Firefox and Safari work fine
  2. Opera just does a normal switch from one image to the next. No transition.
  3. Chrome seems to work fine. However there is a random flickering. The image appears and dissapears for a split second.
  4. IE seems to not be supported at all however can flux be used for a standard image swap in this case?

http://www.brutal.yoursitedesigned.com/ - website

Any help you could give me for solving any of my issues would be really great.

Thanks

Jon

IE 2D transitions Support

Hi Joe,

Yes I know this awesome slider is all about CSS 3D, but can you make it at least look good with 2D transitions in IE?

Nivo Slider has a pretty good old browser compatibility support... so it can still look pretty in IE.

At least use the 2D transforms from IE9 and do some basic transitions for older browsers.

That will be really cool and people can still see the slider even if they have an older browser.

Thanks your work is greatly appreciated!

-George

Choose Only One Transition

How to Choose Only One Transition?
Thiw code does't work:
window.myFlux = new flux.slider('#slider', { transitions: [ 'turn', 'bars3d' ] });

random images and external data file

Love the script and would like to use it.
I have a lot of images so is it possible to have a random image sequence and als load from an external data file

Thanks for your efforts.

Steve

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.