Ti site is automaatix iwersetst këp. Wën etwas nët klaar is, tan kuke ti ënglixe tokumënte.
Basis Nutsung
Tuu ti Gridzy-file uf tayn serwer xtele un tuu se in tayn weepe lose (normaalwayse in te khop sektsioon):
<link rel="stylesheet" href="gridzy/gridzy.min.css" />
<script src="gridzy/gridzy.min.js"></script>Tuu te HTML-Kode hiner lose (iwer yeete plats in te khërper sektsioon):
<div class="gridzy">
<img src="https://loremflickr.com/640/480?random=1" alt="a random image" />
<img src="https://loremflickr.com/480/640?random=2" alt="another random image" />
<img src="https://loremflickr.com/640/640?random=3" alt="yet another random image" />
<img src="https://loremflickr.com/640/480?random=4" alt="a random image again" />
<img src="https://loremflickr.com/640/480?random=5" alt="one last random image" />
</div>Tas is tas! Tas is een fol funktsioons payxpiil. Keen ekstra initialisierung is neetich.
Konfiguratsioon
Ti laychste aat fer Gridzy se konfituere is, ploos HTML-Atrës penutse. Tuu prauchst ploos ti opjetiiwe naame mit data-gridzy- . Soo, fer ti optsioon spaceBetween se xtele, tuu ploos te atrës data-gridzy-spaceBetween tswixe .
<div class="gridzy" data-gridzy-spaceBetween="20" data-gridzy-desiredHeight="400">
<img src="https://loremflickr.com/640/480?random=1" alt="a random image" />
<img src="https://loremflickr.com/480/640?random=2" alt="another random image" />
<img src="https://loremflickr.com/640/640?random=3" alt="yet another random image" />
<img src="https://loremflickr.com/640/480?random=4" alt="a random image again" />
<img src="https://loremflickr.com/640/480?random=5" alt="one last random image" />
</div>Haupste optsioone
Justified Optsioone fer tas Layout
Waterfall Layout Opções
Mee fortere optsioone
Fer mee fortere optsioone, kuk ti API .
HTML
Ti eensichste HTML-xtruktur fon Gridzy is tas:
<div class="gridzy">
<img src="https://loremflickr.com/640/480?random=1" alt="a random image" />
<img src="https://loremflickr.com/480/640?random=2" alt="another random image" />
<img src="https://loremflickr.com/640/640?random=3" alt="yet another random image" />
<img src="https://loremflickr.com/640/480?random=4" alt="a random image again" />
<img src="https://loremflickr.com/640/480?random=5" alt="one last random image" />
</div>Awer, Gridzy is aarich fleksipel un tuu khanst neekst yeete aner HTML-xtruktur penutse. Es kept ploos phaar phunkte woo mer mise noo kuke:
- Yeete khint fon tëm kontener elemënt representiirt een itee im raster.
- Soo kaar te kontener elemënt un sayn khiner khëne yeete sort xprooch sin, wii
ulunli(ti xprooch fon te browser reseteere ploos). - Wën een
imgelemënt nët een direkte khint selepst is, praucht es ti klasgridzyImage.
Soo, is tas aach een aarwayts HTML-struktuur:
<ul class="gridzy">
<li>
<span>
<img class="gridzyImage" src="https://loremflickr.com/640/480?random=1" alt="a random image" />
</span>
</li>
<li>
<span>
<img class="gridzyImage" src="https://loremflickr.com/480/640?random=2" alt="another random image" />
</span>
</li>
<li>
<span>
<img class="gridzyImage" src="https://loremflickr.com/640/640?random=3" alt="yet another random image" />
</span>
</li>
<li>
<span>
<img class="gridzyImage" src="https://loremflickr.com/640/480?random=4" alt="a random image again" />
</span>
</li>
<li>
<span>
<img class="gridzyImage" src="https://loremflickr.com/640/480?random=5" alt="one last random image" />
</span>
</li>
</ul>Xpetsiaal wëns tuu ti xrifte fine wilst, prauchst tuu een fortere HTML-xtruktur hon. Fer mee iwer tas se lërne, kuk ti apsetse fon te Piipel .
Titektsioone un Skins
Wëns tuu ti xrifte in tayn galerii fine wilst, must tuu tas aus siin definiire. Tës weeche, sin welche foer kextëlte skins tepay. Yeete haut is fon een CSS-taate. Tuu prauchst tiise file neewich te haupste Gridzy file (normaal in te khop sektsioon) hiner lose:
<link rel="stylesheet" href="gridzy/skins/gridzySkinClassic/style.min.css" />Fer tas, prauchst tuu een fortere HTML-struktuur:
<div class="gridzy gridzySkinClassic">
<figure>
<img class="gridzyImage" src="https://loremflickr.com/640/480?random=1" alt="a random image" />
<figcaption class="gridzyCaption">a caption text</figcaption>
</figure>
<figure>
<img class="gridzyImage" src="https://loremflickr.com/480/640?random=2" alt="another random image" />
<figcaption class="gridzyCaption">another caption text</figcaption>
</figure>
<figure>
<img class="gridzyImage" src="https://loremflickr.com/640/640?random=3" alt="yet another random image" />
<figcaption class="gridzyCaption">yet another caption text</figcaption>
</figure>
<figure>
<img class="gridzyImage" src="https://loremflickr.com/640/480?random=4" alt="a random image again" />
<figcaption class="gridzyCaption">a caption text again</figcaption>
</figure>
<figure>
<img class="gridzyImage" src="https://loremflickr.com/640/480?random=5" alt="one last random image" />
<figcaption class="gridzyCaption">one last caption text</figcaption>
</figure>
</div>Wën teyer sich iwer ti HTML-xtruktur frooe tuut, kukt teyer Semantik HTML .
Fer ti xrift khanst tuu yeete sort xrift penutse, ploos phast uf tas se ti xprooch gridzyCaption hot . Tas img elemënt praucht ti klasse gridzyImage .
Tas payxpiil woo too trin xteet tsaycht tas ti haut gridzySkinClassic . Fer een aner penutse, tuu ploos te haut naame mit een fon tiise ersetse:
Inklusive Skins
| Erhältliche Klasse | |
|---|---|
| gridzyHautLeese een kuut aanfangs phunkt fer een aychne haut se mache . live foerxtëlung | gridzySkinBlank |
| gridzySkinClassic live foerxtëlung | gridzySkinClassic(ES TI wersioon 2.6.0 is xon ferkhaaft kep) |
| gridzySkinFullOverlay live foerxtëlung | gridzySkinFullOverlay(ES TI wersioon 2.6.0 is xon ferkhaaft kep) |
| gridzySkinLift live foerxtëlung | gridzySkinLift(ES TI wersioon 2.6.0 is xon ferkhaaft kep) |
| gridzySkinMagnifier zoom funktsioon nët tepay live foerxtëlung | gridzySkinMagnifier(ES TI wersioon 2.6.0 is xon ferkhaaft kep) |
Al ti skins woo too trin sin prauche ploos en CSS-file, awer es kept noch anere skins woo aach en JavaScript-file prauche:
<link rel="stylesheet" href="gridzy/skins/gridzySkinBlur/style.min.css" />
<script src="gridzy/skins/gridzySkinBlur/script.min.js"></script>| Erhältliche Klasse | |
|---|---|
| gridzySkinBlur funktioniert net in IE live foerxtëlung | gridzySkinBlur(ES TI wersioon 2.6.0 is xon ferkhaaft kep) |
| gridzySkinCard live foerxtëlung | gridzySkinCard(ES TI wersioon 2.6.0 is xon ferkhaaft kep) |
Haut optsioone
Siit ti wersioon 2.6.0 këpts Optsioone fer ti intekrierte xpiichle se konfituere. Je nach der spetsiifixe haut khanst tuu ti hinergrund farwe, te tëkst farwe un te tëkst xtraus fest xtele. Tuu must ploos CSS penutse wii tuu hier siist:
<div class="gridzy gridzySkinClassic" style="--background: rgba(0, 80, 117, .8); --color: rgb(238, 238, 238); ">
<figure>
<img class="gridzyImage" src="https://loremflickr.com/640/480?random=1" alt="a random image" />
<figcaption class="gridzyCaption">a caption text</figcaption>
</figure>
<figure>
<img class="gridzyImage" src="https://loremflickr.com/480/640?random=2" alt="another random image" />
<figcaption class="gridzyCaption">another caption text</figcaption>
</figure>
...
</div>Kuk ti unerxtitsungs variaable un ti xprooch wërter fer yeete skin hier:
gridzySkinClassic
| Variabel | Standardwert | Informatsyoon |
|---|---|---|
--background | rgba(0, 0, 0, .7) | erlaubt yeete CSS-hintergrundwert |
--color | rgb(255, 255, 255) | erlaubt yeete CSS-farbewert . |
--text-shadow | none | erlaubt yeete CSS-tekst-xtraal-wert |
gridzySkinFullOverlay
| Variabel | Standardwert | Informatsyoon |
|---|---|---|
--background | rgba(0, 0, 0, .7) | erlaubt yeete CSS-hintergrundwert |
--color | rgb(255, 255, 255) | erlaubt yeete CSS-farbewert . |
--text-shadow | none | erlaubt yeete CSS-tekst-xtraal-wert |
gridzySkinLift
| Variabel | Standardwert | Informatsyoon |
|---|---|---|
--background | rgba(0, 0, 0, .7) | erlaubt yeete CSS-hintergrundwert |
--color | rgb(255, 255, 255) | erlaubt yeete CSS-farbewert . |
--text-shadow | 0 0 10px rgb(0, 0, 0), 0 0 20px rgb(0, 0, 0), 0 0 30px rgb(0, 0, 0) | erlaubt yeete CSS-tekst-xtraal-wert |
gridzySkinMagnifier
| Variabel | Standardwert | Informatsyoon |
|---|---|---|
--background | rgba(0, 0, 0, .7) | erlaubt yeete CSS-hintergrundwert |
--color | rgb(255, 255, 255) | erlaubt yeete CSS-farbewert . |
Tiise haut unerxtitst nët --text-shadow
gridzySkinBlur
| Variabel | Standardwert | Informatsyoon |
|---|---|---|
--background | rgba(0, 0, 0, .7) | erlaubt yeete CSS-hintergrundwert |
--color | rgb(255, 255, 255) | erlaubt yeete CSS-farbewert . |
--text-shadow | 0 0 10px rgb(0, 0, 0) | erlaubt yeete CSS-tekst-xtraal-wert |
gridzySkinCard
| Variabel | Standardwert | Informatsyoon |
|---|---|---|
--background | rgba(0, 0, 0, 1) | erlaubt yeete CSS-hintergrundwert |
--color | rgb(255, 255, 255) | erlaubt yeete CSS-farbewert . |
--text-shadow | none | erlaubt yeete CSS-tekst-xtraal-wert |
Al ti foer kextëlte skins unerxtitse ploos eenfache tëkste. Tuu khanst tayn aychne un komplët skins mache. Bitte mach een kijk op Stijl Gridzy .
Stiil Gridzy
Wën khee foer kextëltne haut tayn neetichkheete erfiilt, khanst tuu tayn aychne stil mache.
Ti laychste aat is ëyerst een eksistiirente haut kopiire un tas fer tayn aychne neetichkheete aanpase. Ti foer kexprochne haut gridzySkinBlank teet normalerwayse en kuut funtamënt sin soo wii en kuut dokumentatsioon in te CSS-taate:
/** SKIN Blank **/
/* all gallery items (direct children of the main container element) */
.gridzySkinBlank > .gridzyItem {
overflow: hidden;
}
/* all gallery images (predefined in Gridzy's main CSS file, but can be overridden) */
.gridzySkinBlank .gridzyImage {
}
/* all gallery captions (just create your very own style) */
.gridzySkinBlank .gridzyCaption {
margin: 0;
padding: .5em;
opacity: 0;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: absolute;
z-index: 1;
top: 0;
left: 0;
width: 100%;
height: 100%;
box-sizing: border-box;
transition: opacity .5s;
overflow: auto;
background: rgba(0, 0, 0, .7);
color: rgb(255, 255, 255);
}
.gridzySkinBlank > .gridzyItem:hover .gridzyCaption {
opacity: 1;
}In te CSS-taate fine se ti xprooch fon te xtet gridzySkinBlank , gridzyImage un gridzyCaption . Gridzy selepst praucht net tiise klase. Tii sin ploos penutst fer stiile mache un soo, khanst tuu se wëch xafe orer ënere wëns tuu wilst.
Ausserdem fine se ti CSS-klasse gridzyItem . Gridzy setst tiise xprooch automaatix fer ale direkte khiner fom haupste kontener elemënt. Soo, khanst tuu tiise xprooch penutse fer ti itee fon tayn galerii stiile.
Mind Wichtich Sache
- Ti inhalte fon te itee solte fol mit antwort sin. Tenk aan tas ti elemënt sayn kroosheet sich sicher ënere tuut. Tuu prosent wërter penutse anxtat ti pixel wërter. Un kuk ti optsioon fon Gridzy-Layout
autoFontSize, woo ti xrift-kroosheet uf te itee-kaste-kroosheet xraypt. - Yeete itee sol een kuut pextimt aspekt hon. Ti aspekt fon tëm itee tuut sich nii mee ënere un is neetich fer tas raster se rechne. Soo, wën een itee nët automaatix een kuut pextimt aspekt hot, tuu tee manueel foer xtele (p.ex. torich css).
In etliche situatsioone, khan es sin tas es laychter is te inhalt fon te itee stiile eep Gridzy initialiseyert. Eenfach ti klase gridzy orer ti Gridzy javascript-file tsayt tsu tsayt fer tas wech xafe.
Tas is tas! Tas is ales was tuu prauchst fer tayn aychne haut uf paue. Ti meyerxte fon te pre-definierte skins penutse net mee wii tas.
Awer es khënt mee sin wëns tuu wilst ...
Fortgeschrittene Skins
Gridzy penutst mee CSS-klasse wii ploos gridzyItem . Ti meyerste fon tëne wëre automaatix in kextelt un tuu khanst se aach fer stiile penutse.
Haupste Kontener Klasse
| Klaas Naam | Pexraypung |
|---|---|
gridzyfer manueel se xtele | Gridzy fine automaatix elemënte mit tiise xprooch un initialiseere se. |
gridzyAnimated | Wërt automaatix in kextelt wëre wën ti optsioon animate true is . Wën tiise xprooch manueel in kextelt wërt, tuut ti optsioon animate automaatix aach true sin (ausser wën se eksplisiit uf false in kextelt kept ). |
Item klasse
| Klaas Naam | Pexraypung |
|---|---|
gridzyItem | Wërt setst soo klaych wii te itee te initialisierung protses aan fangt. Wird nii wëch ketuun këpe. |
gridzyItemInitializing | Wërt setst soo klaych wii te itee te initialisierung protses aan fangt. Wërt ersetzt mit gridzyItemReady soo lang wii tas itee kans initialiseyert is. Meecht net tas ti pilter kans layt sin (siit gridzyItemLoading ), awer itee is fërtich fer sichtbar se kriin. |
gridzyItemReady | Will gridzyItemInitializing ersetzt soo klaych wii tas itee kans initialiseyert is. Wird nii wëch ketuun këpe. Meecht net tas ti pilter kans layt sin (siit gridzyItemComplete ), awer itee is fërtich fer sichtbar se kriin. |
gridzyItemLoading | Wërt setst soo klaych wii te itee te initialisierung protses aan fangt. Wërt ersat fon gridzyItemComplete soo klaych wii ti enthalungs pilter (normaal ploos een) fol kelaat sin. |
gridzyItemComplete | Wil gridzyItemLoading ersetse soo klaych wii ti enthalungs pilter (normaal ploos een) sin fol kelaat. Wird nii wëch ketuun këpe. |
gridzyItemInitialToVisible | Wërt kextëlt wëre soo klaych wii tas itee tas eyerste mool aan fangt se xteen. Wërt wech ketuun këpe soo klaych wii tas itee komplet sichtbar is. |
gridzyItemVisible | Wird setst soo klaych wii tas itee kans sichtbar is. Wërt raus kehool këpe soo klaych wii tas itee aan fangt se ferxwine. |
gridzyItemVisibleToHidden | Wird sets soo klaych wii tas itee aanfangt se ferxwine. Wërt wech ketuun këpe soo klaych wii tas itee komplet ferxtekelt is. |
gridzyItemHidden | Wird sets soo klaych wii tas itee komplett ferxtekelt is. Wërt raus kehool këpe soo klaych wii tas itee aan fangt se xteen. |
gridzyItemHiddenToVisible | Wërt kextëlt wëre soo klaych wii tas itee aan fangt se xteen (ausser wën tas eyerste mool khomt – siit ti klas gridzyItemInitialToVisible ). Wërt wech ketuun këpe soo klaych wii tas itee komplet sichtbar is. |
gridzyItemVisibleToVisible | Wërt setst soo klaych wii etwas im raster sich ferënert hot, awer te itee selepst waar un playpt sichtbar. Wërt raus kehool këpe soo klaych wii ti ënerung animatsioon fërtich is. |
Im xtant, sin te protses indikatoor un ti animatsioone fer ti pilter woo uf xtaye un ferxwine, foer kextëlt kep fon te Gridzy haupste CSS-taate.
Mit tëne foer kexprochne CSS-Klasse khanst tuu tayn aychne protses indikatoor un animatsioone stiile. Waar en kuke in te Gridzy haupste CSS-file, fer se ferxteen was tuu iwer xraywe teest. Keen pang, ales is kuut dokumenteyert tat.
Optimiiseere ti laate
Wën mer fiile pilter penutse, khan es sin tas mer Gridzy helfe tas raster xnël uf paue.
Ferhëngert xpringe pilter
Gridzy praucht apsolut ti aspekt fon ale pilter fer tas raster se berechne. Tiise fakte pringt xpringe elemënte wën etliche pilter fërtich sin un anere net. Wii mee pilter es kept, soo fiil mee ërnst khan tiise efekt sin.
Fer tas ferxtëntnis se ferhëngeren, mise mer ploos ti atrës width un height atrës fer ale img elemënte setse. Es is wichtich ti richtiche wërter fer yeete eensich pilt fine, wayl wën net, teete ti pilter ferxtëkelt wëre. Ti richtiche wërter sin ti orikinaal xprooch un ti heechst fon te respektiiwe pilter:
<div class="gridzy">
<img src="https://loremflickr.com/640/480?random=1" width="640" height="480" alt="a random image" />
<img src="https://loremflickr.com/480/640?random=2" width="480" height="640" alt="another random image" />
<img src="https://loremflickr.com/640/640?random=3" width="640" height="640" alt="yet another random image" />
<img src="https://loremflickr.com/640/480?random=4" width="640" height="480" alt="a random image again" />
<img src="https://loremflickr.com/640/480?random=5" width="640" height="480" alt="one last random image" />
</div>Too tefoer khan Gridzy tas raster klaych rechne oone ti aktuaale kroose numer fon te pilter se wise.
Faul laden
Fer ploos pilter woo in te sicherheet sin, laate, tuu ploos tiise xrite noo keen:
- Insëtsung fon
widthunheightatrës wii es foer heyer pexrip is (sicher tas tuu ti richtiche wërter penutst) - Ersets ale
srcatrës mitdata-gridzylazysrcwii uner ketsaycht kept (wëns tuusrcsetatrës aach host, ersets se mitdata-gridzylazysrcset).
<div class="gridzy">
<img data-gridzylazysrc="https://loremflickr.com/640/480?random=1" width="640" height="480" alt="a random image" />
<img data-gridzylazysrc="https://loremflickr.com/480/640?random=2" width="480" height="640" alt="another random image" />
<img data-gridzylazysrc="https://loremflickr.com/640/640?random=3" width="640" height="640" alt="yet another random image" />
<img data-gridzylazysrc="https://loremflickr.com/640/480?random=4" width="640" height="480" alt="a random image again" />
<img data-gridzylazysrc="https://loremflickr.com/640/480?random=5" width="640" height="480" alt="one last random image" />
</div>Noo tiise xrite, tuun ti pilter layt soo klaych wii se ticht orer in te siit sin.
Protses Indikator
Te protses indikatoor is tas kleene animoose pilt woo khomt wën tas pilt layt. Wëns tuu ti xrifte & ti xrifte penutst , wërt te protses indikatoor automaatix ketsaycht. Awer, tuu prauchst welche ënerunge mache:
- Tuu yeete
imgelemënt in eendiv-elemënt xtele .
(orer in en anere elemënt – siit semantik HTML fer mee) - Tuu ti klasse
gridzyImagetsu yeeteimgelemënt hiner lose
<div class="gridzy">
<div><img src="https://loremflickr.com/640/480?random=1" class="gridzyImage" alt="a random image" /></div>
<div><img src="https://loremflickr.com/480/640?random=2" class="gridzyImage" alt="another random image" /></div>
<div><img src="https://loremflickr.com/640/640?random=3" class="gridzyImage" alt="yet another random image" /></div>
<div><img src="https://loremflickr.com/640/480?random=4" class="gridzyImage" alt="a random image again" /></div>
<div><img src="https://loremflickr.com/640/480?random=5" class="gridzyImage" alt="one last random image" /></div>
</div>Nochter, solst tuu ti protses indikatoore siin wën ti pilter tsayt nëme fer se laate.
Filter
Filter in Gridzy sin ziemlich eenfach awer kraftich. Egal was fer sort filter tuu prauchst, es is kans sicher tas es realiseyert wërt. Tas ales was tuu prauchst is, een pisye CSS un phaar HTML-form elemënte ...
Hier is een funktsioons voorbeeld:
<div id="myFilterControls">
<button value="*">All</button>
<button value=".animals">Animals</button>
<button value=".architecture">Architecture</button>
<button value=".people">People</button>
</div>
<div class="gridzy" data-gridzy-filterControls="#myFilterControls button">
<img class="animals" src="https://loremflickr.com/640/480/animals?random=1" alt="a random animal image" />
<img class="architecture" src="https://loremflickr.com/640/480/arch?random=1" alt="a random architecture image" />
<img class="people" src="https://loremflickr.com/640/480/people?random=1" alt="a random people image" />
<img class="animals" src="https://loremflickr.com/640/480/animals?random=2" alt="another random animal image" />
<img class="architecture" src="https://loremflickr.com/640/480/arch?random=2" alt="another random architecture image" />
<img class="people" src="https://loremflickr.com/640/480/people?random=2" alt="another random people image" />
<img class="animals" src="https://loremflickr.com/640/480/animals?random=3" alt="yet another random animal image" />
</div>Los uns tas xrit noo xrit paue
1. Eyerxt prauche mer ti kewoonlich HTML-xtruktur fon Gridzy un setst klase naame fer ale itee fon te galerii tas mer se noo heyer filtere khëne .
<div class="gridzy">
<img class="animals" src="https://loremflickr.com/640/480/animals?random=1" alt="a random animal image" />
<img class="architecture" src="https://loremflickr.com/640/480/arch?random=1" alt="a random architecture image" />
<img class="people" src="https://loremflickr.com/640/480/people?random=1" alt="a random people image" />
<img class="animals" src="https://loremflickr.com/640/480/animals?random=2" alt="another random animal image" />
<img class="architecture" src="https://loremflickr.com/640/480/arch?random=2" alt="another random architecture image" />
<img class="people" src="https://loremflickr.com/640/480/people?random=2" alt="another random people image" />
<img class="animals" src="https://loremflickr.com/640/480/animals?random=3" alt="yet another random animal image" />
</div>In tiise payxpiil penutse mer ploos een xprooch fer yeete elemënt. Awer tuu khanst aach mee wii een xprooch fer een eensich elemënt in richte, wën tas elemënt torich mee wii een filter kefun wëre sol.
2. Tan tuun mer welche knoope hiner lose, torich was mer ti filter ënere khëne tan .
<button value="*">All</button>
<button value=".animals">Animals</button>
<button value=".architecture">Architecture</button>
<button value=".people">People</button>
<div class="gridzy">
<img class="animals" src="https://loremflickr.com/640/480/animals?random=1" alt="a random animal image" />
<img class="architecture" src="https://loremflickr.com/640/480/arch?random=1" alt="a random architecture image" />
<img class="people" src="https://loremflickr.com/640/480/people?random=1" alt="a random people image" />
<img class="animals" src="https://loremflickr.com/640/480/animals?random=2" alt="another random animal image" />
<img class="architecture" src="https://loremflickr.com/640/480/arch?random=2" alt="another random architecture image" />
<img class="people" src="https://loremflickr.com/640/480/people?random=2" alt="another random people image" />
<img class="animals" src="https://loremflickr.com/640/480/animals?random=3" alt="yet another random animal image" />
</div>Anxtat ti knoope, khënst tuu aach anere formulaare elemënte penutse wii ti xteke, ti raatio knoope, ti raus suuche fon te fële un soo wayter.
Soo wii mer siin khëne, ti wërter fon te knoope sin keweenliche CSS-selektore. Soo klaych wii mer fërtich sin, een klik uf soo een knoop tuut ti pilter tsayche woo mit tëm CSS-selektor xtime. Teknisch setst es eenfach ti filter optsioon uf tiise weyert.
Tuu khanst aach fiil komplëxe selektsioone penutse. Tsum payxpiil :not(.animals) teet aach xafe, soo wii .animals.people un .animals, .people .
3. Am ën, tuun mer ti knoop in en div -kontener enkapsuliire un in te Gridzy-Galerie xraywe, torich ti optsioon filterControls :
<div id="myFilterControls">
<button value="*">All</button>
<button value=".animals">Animals</button>
<button value=".architecture">Architecture</button>
<button value=".people">People</button>
</div>
<div class="gridzy" data-gridzy-filterControls="#myFilterControls button">
<img class="animals" src="https://loremflickr.com/640/480/animals?random=1" alt="a random animal image" />
<img class="architecture" src="https://loremflickr.com/640/480/arch?random=1" alt="a random architecture image" />
<img class="people" src="https://loremflickr.com/640/480/people?random=1" alt="a random people image" />
<img class="animals" src="https://loremflickr.com/640/480/animals?random=2" alt="another random animal image" />
<img class="architecture" src="https://loremflickr.com/640/480/arch?random=2" alt="another random architecture image" />
<img class="people" src="https://loremflickr.com/640/480/people?random=2" alt="another random people image" />
<img class="animals" src="https://loremflickr.com/640/480/animals?random=3" alt="yet another random animal image" />
</div>Soo wii teyer siit, tuun mer aach en CSS-Selektor penutse fer ti optsioon filterControls . Te div kontener mit tëm id atrës tiinst ploos fer ti knoope laychter se raus suuche torich tas CSS selektor.
Tas is tas!
Wëns tuu een JavaScript-Lösung kërn host, kuk ti API .
API
Opwool Gridzy sayn aychne API hot, khëne ti meyerxte tinge oone tëm kemacht wëre, ploos torich ti DOM manipuliire. Gridzy tuut tas merke un tas raster aanpase. Awer es kept aach een aarich kraftiche API ...
Te DOM manipuleere
Fer ale manipulatsioone fon te Dokumënt Objeto Model (DOM) mise mer eyerxt te kontener elemënt:
// get the container element
var gridzyElement = document.querySelector('.gridzy');Tuu pilter hiner lose
Es is important tas te nay khiner elemënt kans uf paue un fërtich kept, eep mer tee in te kontener elemënt rin tuun. Awer, Gridzy khan net ti richtiche dimënsioone fine.
// create a new img element
var newImage = document.createElement('img');
// add src attribute (!! before you add it to the container element !!)
newImage.src = 'https://loremflickr.com/640/480';
// add it as last element to the container element
gridzyElement.appendChild(newImage);
// or as first element (or anywhere in between)
gridzyElement.insertBefore(newImage, gridzyElement.firstChild);Pilter wëch xafe
// remove the first image
gridzyElement.removeChild(gridzyElement.firstElementChild);Optsioone ënere
// change the spaceBetween option to a specific value
gridzyElement.setAttribute('data-gridzy-spaceBetween', '10');
// change the layout option to a specific value
gridzyElement.setAttribute('data-gridzy-layout', 'waterfall');
// reset the spaceBetween option to its default value
gridzyElement.removeAttribute('data-gridzy-spaceBetween');Mee iwer ti manipulatsioon fon te DOM khanst tuu in MDN web docs fine . Es kept aach een Introtutsioon fer te DOM .
Proprietät API
Fer ti API penutse, mise mer eyerxt ti Gridzy instans, woo an te Gridzy kontener elemënt ferpun kept:
// get the Gridzy instance
var gridzyInstance = document.querySelector('.gridzy').gridzy;Optsioon kriin
// get the value of a single option
var currentLayout = gridzyInstance.getOption('layout');Kriin ale optsioone
// get all option values as an object
var currentOptions = gridzyInstance.getOptions();Sets optsioone
// set specific option values
gridzyInstance.setOptions({
spaceBetween: 10,
layout: 'waterfall'
});
// or reset options to their default values
gridzyInstance.setOptions({
spaceBetween: null,
layout: null
});Filter aan wëne
En filter aan wëne is ploos ti optsioon filter in richte woo yeete valide CSS-selektor sin khan:
// set the filter to match items with class "animals"
gridzyInstance.setOptions({
filter: '.animals'
});
// reset the filter to match all items again
gridzyInstance.setOptions({
filter: '*'
});
// set the filter to match items without class "animals"
gridzyInstance.setOptions({
filter: ':not(.animals)'
});
// set the filter to match items with class "animals" or "people"
gridzyInstance.setOptions({
filter: '.animals, .people'
});
// set the filter to match items that have both classes, "animals" and "people"
gridzyInstance.setOptions({
filter: '.animals.people'
});Ruffunktsioone hinzufügen
TI WERSIOON pis ti wersioon 2.4.0
Tuu ti moderne un mee fleksiiple Ewënte penutse. Kuk te neekste apsetse fer mee informatsioone.
Gridzy.js 2 unerxtitst welche optsioone fer ti funktsioone fon te ruf. Tii khëne ploos torich ti proprietaar API in kextelt wëre, awer soo wii anere optsioone:
// same as set other options
gridzyInstance.setOptions({
onOptionsChanged: function() {
// will be executed each time the options have changed.
},
onBeforeOptionsChanged: function() {
// will be executed, before new options take effect.
}
});Tuu ti ewënte penutse
pis ti wersioon 2.4.0.
Tuu khanst Gridzy-Ewënte penutse kraat soo wii ti kewoonliche JavaScript-Ewënte:
document.addEventListener('gridzyOptionsChanged', function(event) {
// will be executed each time the options have changed.
});
document.addEventListener('gridzyBeforeOptionsChanged', function(event) {
// will be executed, before new options take effect.
});Welche ewënte sin uf em Gridzy Kontener Elemënt kexmis kep un anere ewënte sin uf te intiwituaale itee elemënte iwer te Kontener Elemënt kexmis kep.
Erepxafte uf em Gridzy kontener elemënt:
event.target macht tas Gridzy-Kontainer-Element.
event.detail.instance macht ti Gridzy instans.
Erepxafte uf itee elemënte:
event.target macht tas respektiiwe itee elemënt.
event.detail.instance macht ti Gridzy instans.
API – Welt
Es kept welche funktsioone woo fon Gridzy instanse unaafhängich sin. Soo, prauche mer net een instans foer heyer kriin.
Standart optsioon kriin
// get the default value of a single option
var defaultLayout = Gridzy.getDefaultOption('layout');Kriin ale standard optsioone
// get all default option values as an object, including the default layout options of the default layout
var defaultOptions = Gridzy.getDefaultOptions();
// or get all default option values, including the default layout options of a specific layout
var defaultOptions = Gridzy.getDefaultOptions('waterfall');Set Standart Optsioone .
Tas macht net ti optsioone fon ale xon initiaale Gridzy instanse, awer ti basis fer naye instanse definiert. Awer, wën een optsioon fon een eksistiirente instans reset wërt torich te weyert null , teet se te nay xtel wërt penutse.
// set default option values
Gridzy.setDefaultOptions({
spaceBetween: 10,
layout: 'waterfall'
});Tuu khanst tas penutse fer optsioone welt weech se xtele, wëns tuu tas ruufe tuust eep DOM fërtich is. Soo, teest tuu net mee optsioone wii atrës penutse.
Automatismus
Soo lang wii ale automatixe fon Gridzy.js 2 aktiif sin, kepts khee prays fer ti unerxiitliche methoote. Awer ti automatismus khan aus kexproch wëre fer Gridzy in en mee traditsiooneel aat penutse:
// disable automatic initializations
Gridzy.setDefaultOptions({
autoInitOnDomReady: false,
autoInitOnDomMutation: false
});
// or switch off all mutation observers
Gridzy.setDefaultOptions({
autoInitOnDomMutation: false,
autoSyncChildListMutation: false,
autoSyncAttributesMutation: false,
autoSyncChildClassMutation: false,
autoSyncImageMutation: false
});Etliche fon tiise optsioone khëne net torich data-gridzy- atrës orer torich setOptions() , weeche logixe uersache:
Manueel initialiseere
// initialize a new Gridzy instance
var gridzyInstance = new Gridzy(document.querySelector('.gridzy'), {
spaceBetween: 10,
layout: 'waterfall'
});Fernich ti Instans .
Ruich kesaat, tas keeche teel fon te initialiseerung fon Gridzy.
gridzyInstance.destroy();
gridzyInstance = null;Sinkroniseere ti khiner list manueel
// after child elements (images) are added to or removed from the DOM.
gridzyInstance.syncChildList();Sinkroniseere een eensichste khint elemënt manueel
Normaalwayse nët neetich, ausser in kans seltne kefale.
// after child elements (images) are added to the DOM and only one of them should be synced to Gridzy.
gridzyInstance.syncChild(childElement);Sinkroniseere ti atrës manueel
Noch, ti optsioon useOptionAttributes mus fer tas true sin.
// after data-gridzy- attributes have changed
gridzyInstance.syncAttributes();Kraft Rendering
Normaalwayse nët neetich, soo kaar wën ale automatixe aus kexproch wëre .
gridzyInstance.render();