Minimit Gallery 2.0 è uscito con tante nuove funzionalità. Visita il nuovo articolo. Se ti serve la vecchia versione di Minimit Gallery c’è la versione 1.05.
In questo articolo spiego passo passo come iniziare a usarlo, scaricando il codice sorgente puoi anche vedere il codice dela pagina demo e lo snippet, non è complicato ma bisogna imparare prima alcuni codici che il plugin usa.
In questo momento il plugin Minimit Gallery usa Jquery, inoltre incorporo i javascript delle funzioni custom easing delle trasformazioni css per le animazioni, dato che probabilmente serviranno se si usa Jquery per animare la galleria.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> <!-- or <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script> --> <script src="jquery.easing.min.js" type="text/javascript"></script> <!-- custom easing functions not needed for the plugin but you probably need for animations --> <script src="jquery.transform.light.js" type="text/javascript"></script> <!-- does css transformations like scale and rotate https://github.com/louisremi/jquery.transform.js --> <script src="mg.min.js" type="text/javascript"></script>
Il plugin usa una stringa di referenza per registrare la galleria. Puoi assegnare oggetti alla galleria dandogli l’id “reference-X” dove X è il numero dell’oggetto. Puoi anche assegnare pulsanti per previous, next, first e last usando l’id come nel codice qua sotto.
Ecco un esempio di Html della galleria.
<div id="example1b"> <!-- reference id here, not required but useful for css --> <div> <div id="example1b-prev">Prev</div> <!-- reference-prev --> <div id="example1b-0">0</div> <!-- reference-0 to reference-x --> <div id="example1b-1">1</div> <div id="example1b-2">2</div> <div id="example1b-3">3</div> <div id="example1b-4">4</div> <div id="example1b-5">5</div> <div id="example1b-next">Next</div> <!-- reference-next --> </div> </div>
È importante che non usi id con lo stesso nome “reference-” della galleria nell’html eccetto quelle mostrate prima.
Con le funzioni di callback tu costruisci le animazioni per init e per interazioni (click, mouse hover, mouse out) basandoti sugli argomenti delle funzioni. Le funzioni di callback saranno chiamate automaticamente dal plugin in caso di interazione o di cambio di stato della galleria, è questo codice aperto che rende Minimit Gallery estremamente flessibile.
Ecco un esempio di funzione di callback.
var reference = "example1b"; this[reference+"_click"] = this[reference+"_click_init"] = function(reference, activated, deactivated, prevsteps, nextsteps, multiple, cycle){ $("#"+reference+"-"+deactivated).removeClass("active"); $("#"+reference+"-"+activated).addClass("active"); }
Chiama la funzione mg_init con l’id di referenza del codice html e i parametri desiderati.
Ecco un esempio di inizializzazione della galleria.
mg_init({ reference:"example1b", click:{ activated:[0], interactive:true, max_activated:1, automatic:1000, automaticpause:5000 }, interaction:{ cycle:true } });
Dovete costruire il css custom degli oggetti della galleria, se non lo avete ancora fatto. Ed ecco la galleria è pronta!
Ecco il codice snippet documentato per costruire le funzioni di callback.
/* * Custom functions callbacks for managing gallery graphical behaviour * @function this[reference+append](reference, activated, deactivated, steps, multiple, cycle) * @param reference:string - gallery string reference * @param activated:array - array of activated items * @param deactivated:array - array of deactivated items * @param prevsteps:number - how many to jump on prev * @param nextsteps:number - how many to jump on next * @param multiple:object - object with data for managing multiple sequential states on the same interaction, based on less and plus defined on init * multiple.plus:number - the multiple_plus setted * multiple.less:number - the multiple_less setted * multiple.activated:array - multiple items from -less activated to +plus activated * multiple.deactivated:array - multiple items deactivated * multiple.old_activated:array - multiple items from -less old_activated to +plus old_activated * multiple.distance:number - distance between activated and old_activated * multiple.jumped:number - items jumped from activated to old_activated, varies between -less and +plus * multiple.direction:bool - false equals left, true equals right * multiple.before_in:array - the items before multiple that comes in * multiple.before_out:array - the items before multiple that goes out * multiple.after_in:array - the items after multiple that comes in * multiple.after_out:array - the items after multiple that goes out * @param cycle:boolean - if the items cycle */ var reference = "reference"; this[reference+"_click"] = function(reference, activated, deactivated, prevsteps, nextsteps, multiple, cycle){} // click function this[reference+"_over"] = function(reference, activated, deactivated, prevsteps, nextsteps, multiple, cycle){} // hover function this[reference+"_out"] = function(reference, activated, deactivated, prevsteps, nextsteps, multiple, cycle){} // out function this[reference+"_click_init"] = function(reference, activated, deactivated, prevsteps, nextsteps, multiple, cycle){} // click init function this[reference+"_hover_init"] = function(reference, activated, deactivated, prevsteps, nextsteps, multiple, cycle){} // click init function this[reference+"_out_init"] = function(reference, activated, deactivated, prevsteps, nextsteps, multiple, cycle){} // click init function this[reference+"_prevclick"] = function(reference, prevsteps){} // function executed when prev is clicked this[reference+"_prevhide"] = function(reference, prevsteps){} // function executed when prev is hide this[reference+"_prevshow"] = function(reference, prevsteps){} // function executed when prev is shown this[reference+"_nextclick"] = function(reference, nextsteps){} // function when next is clicked this[reference+"_nexthide"] = function(reference, nextsteps){} // function executed when next is hide this[reference+"_nextshow"] = function(reference, nextsteps){} // function executed when next is shown
Ecco il codice snippet documentato per costruire la funzione di inizializzazione.
/* * Initialize the Minimit Gallery (feel free to SKIP ARGUMENTS if optionals or if you are using defaults) * @function mg_init(options:object) * @param options.reference:string [Required] - gallery string reference * @param options.click:object [Optional] - arguments for click interactions as follows * @param options.click.activated:array [Optional] - array of numbers for activated items on init * @param options.click.interactive:boolean [Default:false] - if the items are interactive on click * @param options.click.anchorize:boolean [Default:false] - if you want to implement url anchors to remember position * @param options.click.linked:array [Optional] - array of reference strings for linked galleries * @param options.click.linkedmultiply:number [Optional] - number to multiply the activation of linked galleries * @param options.click.max_activated:number [Default:Infinity] - maximum amount of activated items - unlimited if undefined * @param options.click.deactivable:boolean [Default:false] - if the click activated items can be deactivated on click * @param options.click.less:number [Optional] - how many you want before activated in the multiple data - nothing if undefined * @param options.click.plus:number [Optional] - how many you want after activated in the multiple data - nothing if undefined * @param options.click.automatic:number [Optional] - milliseconds for automatic gallery * @param options.click.automaticpause:number [Optional] - milliseconds for automatic gallery pause when user interacts * @param options.click.automaticinverse:boolean [Default:false] - false for automatic to next, true for automatic to prev * @param options.hover:object [Optional] - same as options.click but for mouse hover interactions * @param options.out:object [Optional] - same as options.click but for mouse out interactions * @param options.interaction.prevsteps:number [Default:1] - how many to jump on prev * @param options.interaction.nextsteps:number [Default:1] - how many to jump on next * @param options.interaction.prevtosteps:boolean [Default:false] - for prev, true if the items scrolls all the way, false if the items scrolls only to show first and last * @param options.interaction.nexttosteps:boolean [Default:false] - for next, true if the items scrolls all the way, false if the items scrolls only to show first and last * @param options.interaction.cycle:boolean [Default:false] - if the items cycle */ mg_init({ reference:"reference", click:{ activated:[], interactive:false, anchorize:false, linked:[], linkedmultiply:1, max_activated:1, deactivable:false, less:1, plus:1, automatic:1000, automaticpause:5000, automaticinverse:false }, hover:{ activated:[], interactive:false, anchorize:false, linked:[], linkedmultiply:1, max_activated:1, deactivable:false, less:1, plus:1, automatic:1000, automaticpause:5000, automaticinverse:false }, out:{ activated:[], interactive:false, anchorize:false, linked:[], linkedmultiply:1, max_activated:1, deactivable:false, less:1, plus:1, automatic:1000, automaticpause:5000, automaticinverse:false }, interaction:{ prevsteps:1, nextsteps:1, prevtosteps:false, nexttosteps:false, cycle:false } }); /* API */ mg_setState("reference", 3, "_click", true, true); // mg_setState(reference, num, append, alsolinked, pauseautomatic); mg_pauseautomatic("reference", "_click",); // mg_pauseautomatic(reference, append) mg_resumeautomatic("reference", "_click",); // mg_resumeautomatic(reference, append)
Siete liberi di commentare qua sotto con commenti, bugs e feature request, inoltre commentate con il link alla vostra implementazione di Minimit Gallery!
Great work!! is this site using minimit galery too? i see when it’s loaded it’s animated… awesome.. :)
Thanks, no this site doesn’t use minimit gallery, I’m starting using it on my projects only until recently.
This cool plugin, i will use this for my next project….
Excellent work Riccardo. You guys that build and share these javascript plugins deserve more credit.
Your work is very good, but I don´t get it´s working with Explorer.
Is there any solution for this?
Best regards
The demo works on Ie7+ https://minimit.com/mg/mg-demo.html
It can be a Css or Javascript IE bug on your code.
Excellent travail.
Même si on n’en a pas l’utilité tout de suite, on a envie de s’en servir !
Magnifique, bravo.
“Chapeau bas” comme on dit en France.
Congrats its a Great Plugin.
I like to use this.
As in example9
if i place any images in each div to have a slide show… all the images are getting displayed. Actually it should display one by one – right.
example:
6
Prev
Next
Hope you understand better once you copy the above example code.
Please suggest me: how can i display one image/video at a time.
Expecting your valuable reply.
Regards,
Thiru
I mean if we place images or video (iframe) inside DIV — all the images/videos are getting displayed. I like to show only one at a time.
How to do ?
You should give display:none to the stuff you don’t want displayed, and give display:block to the one you want to display.
For example give display:none to all items, display:block to the activated one, and display:none to the deactivated one.
Thanks for the awesome plugin!! I have one problem though.. in IE 8 and under, using example 3a, only one block shows up. when I click on it, the rest of them appear as they should. Could someone help me with this please? Thank you
Just fixed.
https://minimit.com/mg/mg-demo.html
It was a bug with ie8- and a zIndex animation.
Thank you!
Sorry for this off-topic question. I’m new to javascript and jQuery, and I thought it would be a good idea to ask someone like you… what would you recommend for newcomers to this language? Where should I start? Are there any good books or site that you can recommend? I’ve gone through some of the site you’ve built.. they are quite impressive.
Well, always learn by trial and error, try to build something your own. If you are new to programming get a good javascript programming book.
Thanks for the advice
Hey, the effects you do with this plugin are really amazing, I just wish I understood it a little better, and maybe at some point when you have time you could do a brief tutorial on one of the examples.
for example, example 11 from the demo:
I see you take in a reference to the id of the div, then the syntax in the following line:
“this[reference+"_init"] = function(reference, activated, deactivated, prevsteps, nextsteps, multiple, cycle){ // on init”
I haven’t seen the brackets before next to “this:” (this[reference+"_init"]) I see it grabs a reference to this and ties it to the init function, but what kind of syntax is that? the [] part..
the other thing I don’t understand is what the for loop is being used for specifically within the function:
“for(var i=0;i<arr.length;i++){
var mypath = $("#"+reference+"-"+i);
mypath.css("left",(i*60));
}"
what is this doing? thanks.
this[reference+"_init"] is to address a “object” or “function” using a variable.
Suppose that reference=”sometext” then this[reference+"_init"] is equal to write this.sometext_init
The loop you wrote just loops an array of values and apply a css on the IDs