Create a Multi-Album CSS3 Image Flow
Join the DZone community and get the full member experience.
Join For Freetoday’s result:
here are our demo and source package:
live demo
download in package
ok, download the source files and let's start coding !
step 1. html
in the beginning, let's prepare the markup for our albums (the pure css3 accordion):
index.html
<div class="accordion"> <span id="tab1"></span> <span id="tab2"></span> <span id="tab3"></span> <div class="tabs"> <dl class="tab1"> <dd> <a href="#tab1">album1</a> <div id="1" class="sets"><img src="photos/1.jpg" alt="" /></div> </dd> </dl> <dl class="tab2"> <dd> <a href="#tab2">album2</a> <div id="2" class="sets"><img src="photos/5.jpg" alt="" /></div> </dd> </dl> <dl class="tab3"> <dd> <a href="#tab3">album3</a> <div id="3" class="sets"><img src="photos/9.jpg" alt="" /></div> </dd> </dl> </div> </div>
this is an easy definition list with album names and little thumbnails of the albums. and now, let's prepare a markup for our image flow object.
<div id="imageflow"> <div class="text"> <div class="title">loading</div> <div class="legend">please wait...</div> </div> <div class="scrollbar"> <img class="track" src="images/sb.gif" alt=""> <img class="arrow-left" src="images/sl.gif" alt=""> <img class="arrow-right" src="images/sr.gif" alt=""> <img class="bar" src="images/sc.gif" alt=""> </div> </div>
step 2. css
now – it’s time to turn our definition list of the albums into a great css3 switcher:
css/accordion.css
.accordion { background-color: #444; margin: 15px auto; padding: 5px; position: relative; width: 480px; box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5) inset; -moz-box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5) inset; -webkit-box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5) inset; } .accordion span { display: none } .tabs { background-color: #ffffff; overflow: hidden; } .tabs dl { float: left; overflow: hidden; width: 100px; -webkit-transition: all 0.3s ease-in-out; -moz-transition: all 0.3s ease-in-out; -o-transition: all 0.3s ease-in-out; -ms-transition: all 0.3s ease-in-out; transition: all 0.3s ease-in-out; } .tabs dl dd { overflow: hidden; width: 280px; } .tabs dl dd a { background-color: #c8ceff; border: 1px solid; border-color:#ccc;border-bottom-color:#aaa; display: block; float: left; font-size: 18px; line-height: 126px; padding: 0 20px; text-decoration: none; filter:progid:dximagetransform.microsoft.gradient(gradienttype=0,startcolorstr=#ffffffff,endcolorstr=#ffe0e0e0); background-image: -moz-linear-gradient(top,#fff 0,#e0e0e0 100%); background-image: -ms-linear-gradient(top,#fff 0,#e0e0e0 100%); background-image:-o-linear-gradient(top,#fff 0,#e0e0e0 100%); background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0,#fff),color-stop(100%,#e0e0e0)); background-image: -webkit-linear-gradient(top,#fff 0,#e0e0e0 100%); background-image: linear-gradient(to bottom,#fff 0,#e0e0e0 100%); -moz-transition: 0.3s; -ms-transition: 0.3s; -o-transition: 0.3s; -webkit-transition: 0.3s; transition: 0.3s; } .tabs dl dd div { float: left; height: 128px; } .tabs dl dd div img { height: 128px; padding: 0 3px; } .tabs dl dd a:hover { box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5) inset; -moz-box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5) inset; -webkit-box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5) inset; } .tabs dl dd a:active { filter:progid:dximagetransform.microsoft.gradient(gradienttype=0,startcolorstr=#e6e6e6,endcolorstr=#dcdcdc); background-image: -moz-linear-gradient(top,#e6e6e6 0,#dcdcdc 100%); background-image: -ms-linear-gradient(top,#e6e6e6 0,#dcdcdc 100%); background-image: -o-linear-gradient(top,#e6e6e6 0,#dcdcdc 100%); background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0,#e6e6e6),color-stop(100%,#dcdcdc)); background-image: -webkit-linear-gradient(top,#e6e6e6 0,#dcdcdc 100%); background-image: linear-gradient(to bottom,#e6e6e6 0,#dcdcdc 100%); } #tab1:target ~ .tabs .tab1, #tab2:target ~ .tabs .tab2, #tab3:target ~ .tabs .tab3 { width: 280px; } #tab1:target ~ .tabs .tab1 dd a, #tab2:target ~ .tabs .tab2 dd a, #tab3:target ~ .tabs .tab3 dd a { filter:progid:dximagetransform.microsoft.gradient(gradienttype=0,startcolorstr=#e6e6e6,endcolorstr=#dcdcdc); background-image: -moz-linear-gradient(top,#e6e6e6 0,#dcdcdc 100%); background-image: -ms-linear-gradient(top,#e6e6e6 0,#dcdcdc 100%); background-image: -o-linear-gradient(top,#e6e6e6 0,#dcdcdc 100%); background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0,#e6e6e6),color-stop(100%,#dcdcdc)); background-image: -webkit-linear-gradient(top,#e6e6e6 0,#dcdcdc 100%); background-image: linear-gradient(to bottom,#e6e6e6 0,#dcdcdc 100%); }
step 3. js
now, let’s review our javascript codes. the first one file is our gallery script:
js/image-flow.js
this file is available in our package. our next file:
js/script.js
// set another album function setalbum(i) { imf.create('imageflow', 'xml/set'+i+'.xml', 0.85, 0.20, 1.5, 10, 5, 7); } // main initialization document.addeventlistener('domcontentloaded', function() { // set first album setalbum(1); // attaching 'click' event listener to '.sets' [].foreach.call( document.queryselectorall('.sets'), function(el) { el.addeventlistener('click', function(e) { imf.reinit(); setalbum(e.currenttarget.id); }, false); }); });
as you can see – this is a very small and easy script. the main idea: to attach the ‘click’ event listener to our albums (in our accordion). and, when the visitor clicks a certain album, we will load the predefined xml file with a list of images (of the selected album).
step 4. xml
finally, we should prepare three xml files: predefined lists of our albums.
xml/set1.xml
<?xml version="1.0" ?> <bank> <img> <src>photos/1.jpg</src> <title>image 1</title> <caption>thailand #1</caption> </img> <img> <src>photos/2.jpg</src> <title>image 2</title> <caption>thailand #1</caption> </img> <img> <src>photos/3.jpg</src> <title>image 3</title> <caption>thailand #1</caption> </img> <img> <src>photos/4.jpg</src> <title>image 4</title> <caption>thailand #1</caption> </img> </bank>
xml/set2.xml
<?xml version="1.0" ?> <bank> <img> <src>photos/5.jpg</src> <title>image 5</title> <caption>thailand #2</caption> </img> <img> <src>photos/6.jpg</src> <title>image 6</title> <caption>thailand #2</caption> </img> <img> <src>photos/7.jpg</src> <title>image 7</title> <caption>thailand #2</caption> </img> <img> <src>photos/8.jpg</src> <title>image 8</title> <caption>thailand #2</caption> </img> </bank>
xml/set3.xml
<?xml version="1.0" ?> <bank> <img> <src>photos/9.jpg</src> <title>image 9</title> <caption>thailand #3</caption> </img> <img> <src>photos/10.jpg</src> <title>image 10</title> <caption>thailand #3</caption> </img> <img> <src>photos/11.jpg</src> <title>image 11</title> <caption>thailand #3</caption> </img> <img> <src>photos/12.jpg</src> <title>image 12</title> <caption>thailand #3</caption> </img> </bank>
that’s all!
live demo
download in package
conclusion
now you have it – cool animated image gallery with multiple albums support. we even haven’t used jquery today. it was pure css3 and javascript. i will be glad to see your thanks and comments. good luck!
Published at DZone with permission of Andrey Prikaznov, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments