Sitwèb la te tradui otomatikman. Si yon bagay pa klè, tanpri gade dokiman an angle.
Itilizasyon debaz
Voye dosye Gridzy yo sou sèvè ou a epi ajoute yo sou sit entènèt ou a (anjeneral nan seksyon tèt la):
<link rel="stylesheet" href="gridzy/gridzy.min.css" />
<script src="gridzy/gridzy.min.js"></script>Ajoute kòd HTML la (nenpòt kote nan seksyon kò a):
<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>Se sa! Sa a se yon egzanp konplètman fonksyonèl. Pa gen okenn inisyalizasyon siplemantè ki nesesè.
Konfigirasyon
Fason ki pi fasil pou konfigirasyon Gridzy se jis itilize atribi HTML. Ou sèlman bezwen prefix non opsyon yo ak data-gridzy- . Se konsa, pou mete opsyon spaceBetween , jis ajoute atribi data-gridzy-spaceBetween .
<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>Opsyon prensipal yo
Justified Opsyon Layout
Waterfall Opsyon Layout
Plis Opsyon Avanse
Pou plis opsyon avanse, tcheke API a.
HTML semantik
Estrikti HTML ki pi senp nan Gridzy se sa a:
<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>Sepandan, Gridzy trè fleksib epi ou ka itilize prèske nenpòt lòt estrikti HTML. Gen sèlman kèk pwen yo konsidere:
- Chak pitit eleman veso a reprezante yon atik nan kadriyaj la.
- Tou de eleman veso a ak pitit li yo ka nenpòt kalite tag, tankou
ulakli(jis konsidere reset navigatè default). - Si yon eleman
imgse pa yon timoun dirèk tèt li, li bezwen klasgridzyImage.
Se konsa, sa a se tou yon estrikti HTML k ap travay:
<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>Espesyalman si ou vle ajoute tit, ou bezwen yon estrikti HTML avanse. Pou aprann plis sou li, gade nan Captions & Skins .
Légendes & Po
Si ou vle ajoute tit nan galri ou a, ou bezwen defini aparans la. Se poutèt sa, gen kèk po predefini ki disponib. Chak po ki fòme ak yon dosye CSS. Ou bezwen ajoute dosye sa a anplis dosye prensipal Gridzy yo (anjeneral nan seksyon tèt la):
<link rel="stylesheet" href="gridzy/skins/gridzySkinClassic/style.min.css" />Anplis de sa, ou bezwen yon estrikti HTML avanse:
<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>Si w ap mande sou estrikti HTML la, gade nan HTML Semantik .
Pou tit la ou ka itilize nenpòt kalite tag, jis asire li gen klas gridzyCaption la. Eleman img la bezwen klas gridzyImage .
Egzanp ki anwo a montre w po gridzySkinClassic . Pou itilize yon lòt, jis ranplase non po a ak youn nan sa yo:
Po enkli
| Klas ki disponib | |
|---|---|
| gridzySkinBlank yon bon pwen depa pou kreye yon pwòp po aperçu live | gridzySkinBlank |
| gridzySkinClassic aperçu live | gridzySkinClassic(DEPREKATE depi vèsyon 2.6.0) |
| gridzySkinFullOverlay aperçu live | gridzySkinFullOverlay(DEPREKATE depi vèsyon 2.6.0) |
| gridzySkinLift aperçu live | gridzySkinLift(DEPREKATE depi vèsyon 2.6.0) |
| gridzySkinMagnifier Fonksyonalite zoom pa enkli aperçu live | gridzySkinMagnifier(DEPREKATE depi vèsyon 2.6.0) |
Tout po ki anwo yo sèlman bezwen yon dosye CSS, men gen po anplis ki mande tou yon dosye JavaScript:
<link rel="stylesheet" href="gridzy/skins/gridzySkinBlur/style.min.css" />
<script src="gridzy/skins/gridzySkinBlur/script.min.js"></script>| Klas ki disponib | |
|---|---|
| gridzySkinBlur pa travay nan IE aperçu live | gridzySkinBlur(DEPREKATE depi vèsyon 2.6.0) |
| gridzySkinCard aperçu live | gridzySkinCard(DEPREKATE depi vèsyon 2.6.0) |
Opsyon po
Depi vèsyon 2.6.0 gen Opsyon pou konfigirasyon po yo entegre. Tou depan de po a espesifik ou ka mete koulè background, koulè tèks ak lonbraj tèks la. Ou jis bezwen sèvi ak pwopriyete CSS koutim jan ou ka wè isit la:
<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>Tcheke varyab yo sipòte ak valè default pou chak po isit la:
gridzySkinClassic
| Varyab | Valè Default | Enfòmasyon |
|---|---|---|
--background | rgba(0, 0, 0, .7) | pèmèt nenpòt valè background CSS |
--color | rgb(255, 255, 255) | pèmèt nenpòt valè koulè CSS |
--text-shadow | none | pèmèt nenpòt valè tèks-lonbraj CSS |
gridzySkinFullOverlay
| Varyab | Valè Default | Enfòmasyon |
|---|---|---|
--background | rgba(0, 0, 0, .7) | pèmèt nenpòt valè background CSS |
--color | rgb(255, 255, 255) | pèmèt nenpòt valè koulè CSS |
--text-shadow | none | pèmèt nenpòt valè tèks-lonbraj CSS |
gridzySkinLift
| Varyab | Valè Default | Enfòmasyon |
|---|---|---|
--background | rgba(0, 0, 0, .7) | pèmèt nenpòt valè background CSS |
--color | rgb(255, 255, 255) | pèmèt nenpòt valè koulè CSS |
--text-shadow | 0 0 10px rgb(0, 0, 0), 0 0 20px rgb(0, 0, 0), 0 0 30px rgb(0, 0, 0) | pèmèt nenpòt valè tèks-lonbraj CSS |
gridzySkinMagnifier
| Varyab | Valè Default | Enfòmasyon |
|---|---|---|
--background | rgba(0, 0, 0, .7) | pèmèt nenpòt valè background CSS |
--color | rgb(255, 255, 255) | pèmèt nenpòt valè koulè CSS |
Po sa a pa sipòte --text-shadow
gridzySkinBlur
| Varyab | Valè Default | Enfòmasyon |
|---|---|---|
--background | rgba(0, 0, 0, .7) | pèmèt nenpòt valè background CSS |
--color | rgb(255, 255, 255) | pèmèt nenpòt valè koulè CSS |
--text-shadow | 0 0 10px rgb(0, 0, 0) | pèmèt nenpòt valè tèks-lonbraj CSS |
gridzySkinCard
| Varyab | Valè Default | Enfòmasyon |
|---|---|---|
--background | rgba(0, 0, 0, 1) | pèmèt nenpòt valè background CSS |
--color | rgb(255, 255, 255) | pèmèt nenpòt valè koulè CSS |
--text-shadow | none | pèmèt nenpòt valè tèks-lonbraj CSS |
Tout po predefini sèlman sipòte senp tit tèks. Ou ka kreye po pwòp ou yo ak pi konplèks. Tanpri gade nan Style Gridzy .
Style Gridzy
Si pa gen okenn po predefini adapte bezwen ou yo, ou ka style pwòp ou a.
Fason ki pi fasil la se premye kopye yon po ki deja egziste epi adapte li a pwòp bezwen ou yo. gridzySkinBlank nan po predefini ta anjeneral bay yon bon fondasyon kòm byen ke yon bon dokiman nan dosye CSS la:
/** 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;
}Nan dosye CSS la w ap jwenn klas gridzySkinBlank , gridzyImage ak gridzyCaption . Gridzy li menm pa bezwen klas sa yo. Yo sèlman itilize pou manier e konsa ou ka retire oswa chanje non yo si ou renmen.
Anplis de sa w ap jwenn klas CSS gridzyItem . Gridzy mete klas sa a otomatikman pou tout timoun dirèk nan eleman prensipal veso a. Se konsa, ou ka sèvi ak klas sa a style atik yo nan galri ou a.
Lide Bagay Enpòtan yo
- Kontni atik yo ta dwe konplètman reponn. Konsidere ke gwosè a eleman pral definitivman chanje. Sèvi ak pousantaj valè olye de valè pixel. Epi pran yon gade nan opsyon nan Layout Gridzy
autoFontSize, ki mare font-size a sou gwosè bwat atik la. - Chak atik ta dwe gen yon rapò aspè ki byen defini. Rapò aspè atik la pap janm chanje epi li nesesè pou kalkile kadriyaj la. Se konsa, si yon atik pa otomatikman gen yon rapò aspè byen defini, predefini li manyèlman (egzanp via css).
Nan kèk ka, li ka pi fasil pou style kontni atik yo anvan Gridzy inisyalize. Senpleman retire gridzy klas la oswa dosye javascript Gridzy pou yon ti tan pou sa.
Se sa! Se tout sa ou bezwen pou konstwi pwòp po ou. Pifò nan po yo predefini pa sèvi ak plis ke sa a.
Men, ta ka gen plis si ou renmen ...
Po avanse
Gridzy itilize plis klas CSS pase gridzyItem sèlman. Pifò nan yo pral mete otomatikman epi ou ka itilize yo pou manier tou.
Klas veso prensipal yo
| Non klas la | Deskripsyon |
|---|---|
gridzyyo mete manyèlman | Gridzy otomatikman jwenn eleman ak klas sa a epi li inisyalize yo. |
gridzyAnimated | Yo pral mete otomatikman si opsyon animate se true . Si yo mete klas sa a manyèlman, opsyon animate a pral otomatikman vin true tou (eksepte si li klèman mete sou false ). |
Klas atik yo
| Non klas la | Deskripsyon |
|---|---|
gridzyItem | Yo pral mete le pli vit ke atik la kòmanse pwosesis la inisyalize. Yo pap janm retire. |
gridzyItemInitializing | Yo pral mete le pli vit ke atik la kòmanse pwosesis la inisyalize. Yo pral ranplase pa gridzyItemReady le pli vit ke atik la konplètman inisyalize. Vle di pa ke imaj yo konplètman chaje (gade gridzyItemLoading ), men atik la pare yo vin vizib. |
gridzyItemReady | Pral ranplase gridzyItemInitializing le pli vit ke atik la konplètman inisyalize. Yo pap janm retire. Vle di pa ke imaj yo konplètman chaje (gade gridzyItemComplete ), men atik la pare yo vin vizib. |
gridzyItemLoading | Yo pral mete le pli vit ke atik la kòmanse pwosesis la inisyalize. Yo pral ranplase pa gridzyItemComplete le pli vit ke imaj ki genyen yo (anjeneral yon sèl) yo konplètman chaje. |
gridzyItemComplete | Pral ranplase gridzyItemLoading le pli vit ke imaj ki genyen yo (anjeneral yon sèl) yo konplètman chaje. Yo pap janm retire. |
gridzyItemInitialToVisible | Yo pral mete le pli vit ke atik la kòmanse parèt premye fwa a. Yo pral retire le pli vit ke atik la konplètman vizib. |
gridzyItemVisible | Yo pral mete le pli vit ke atik la se konplètman vizib. Yo pral retire le pli vit ke atik la kòmanse disparèt. |
gridzyItemVisibleToHidden | Yo pral mete le pli vit ke atik la kòmanse disparèt. Yo pral retire le pli vit ke atik la konplètman kache. |
gridzyItemHidden | Yo pral mete le pli vit ke atik la konplètman kache. Yo pral retire le pli vit ke atik la kòmanse parèt. |
gridzyItemHiddenToVisible | Yo pral mete le pli vit ke atik la kòmanse parèt (eksepte parèt premye fwa a - gade klas gridzyItemInitialToVisible ). Yo pral retire le pli vit ke atik la konplètman vizib. |
gridzyItemVisibleToVisible | Yo pral mete le pli vit ke yon bagay nan kadriyaj la chanje, men atik nan tèt li te epi rete vizib. Yo pral retire le pli vit ke animasyon chanjman an fini. |
Pa default endikatè pwosesis la ak animasyon yo pou parèt ak disparèt imaj yo predefini pa Gridzy prensipal dosye CSS la.
Avèk klas CSS sa yo mansyone pi wo a ou ka style pwòp endikatè pwosesis ou ak animasyon. Oze yon gade nan Gridzy prensipal dosye CSS la, pou w konprann sa ou ta gen pou pase sou plas. Pa pè, tout bagay byen dokimante la.
Optimize chajman
Si w itilize anpil imaj, li ta ka yon bon lide pou ede Gridzy bati kadriyaj la pi vit.
Anpeche imaj sote
Gridzy absoliman bezwen rapò aspè tout imaj pou kalkile kadriyaj la. Reyalite sa yo rezilta nan eleman sote si kèk imaj yo pare ak lòt moun yo pa. Plis imaj gen, plis anmèdan ka efè sa a.
Pou anpeche konpòtman sa a, jis mete atribi width ak height pou tout eleman img . Li enpòtan pou mete valè yo kòrèk pou chak imaj endividyèl, otreman imaj yo ta defòme. Valè ki kòrèk yo se lajè orijinal ak wotè imaj respektif la:
<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>Apre sa, Gridzy ka kalkile griy la imedyatman san yo pa bezwen konnen gwosè imaj yo aktyèlman.
Lazy Loading
Pou chaje sèlman imaj ki nan fenèt vizib la, jis swiv etap sa yo:
- Mete atribi
widthakheightjan sa dekri pi wo a (asire w ou sèvi ak valè kòrèk yo) - Ranplase tout atribi
srcakdata-gridzylazysrcjan yo montre anba a (si ou gen atribisrcsettou, ranplase yo akdata-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>Apre etap sa yo imaj yo pral chaje le pli vit ke yo toupre oswa andedan pòtay la.
Endikatè Pwosesis
Endikatè pwosesis la se ti ikòn anime ki parèt pandan imaj la ap chaje. Si ou itilize tit ak po yo , endikatè pwosesis la ap parèt otomatikman. Sinon ou bezwen kèk ajisteman:
- Mete chak eleman
imgnan yon elemandiv
(oswa nan nenpòt lòt eleman - gade HTML semantik pou plis) - Ajoute klas
gridzyImagenan chak elemanimg
<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>Apre sa ou ta dwe wè endikatè pwosesis yo si imaj yo pran tan pou chaje.
Filtè
Filtè nan Gridzy yo trè senp men pwisan. Kèlkeswa kalite filtè ou bezwen, li trè posib ke li reyalize. Tout sa ou bezwen se, yon ti jan CSS ak kèk eleman fòm HTML ...
Men yon egzanp fonksyonèl:
<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>Ann Bati Li Etap pa Etap
1. Premye nou bezwen estrikti HTML abityèl Gridzy epi mete non klas pou tout atik galri pou nou ka filtre yo apre sa.
<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>Nan egzanp sa a nou itilize sèlman yon klas pou chak eleman. Men, ou ka tou mete plizyè klas pou yon sèl eleman, si eleman sa a ta dwe jwenn atravè filtè miltip.
2. Lè sa a, nou ajoute kèk bouton nan ki nou ka chanje filtè yo lè sa a
<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>Olye de bouton yo, ou ta ka tou itilize lòt eleman fòm tankou kaz, bouton radyo, chwazi jaden ak sou sa.
Kòm ou ka wè, valè bouton yo se seleksyon CSS nòmal. Le pli vit ke nou fini, yon klike sou yon bouton konsa pral montre imaj yo ki matche ak seleksyon CSS sa a. Teknikman li tou senpleman mete opsyon nan filter nan valè sa a.
Ou kapab tou itilize seleksyon ki pi konplèks. Pa egzanp :not(.animals) ta travay tou, osi byen ke .animals.people ak .animals, .people .
3. Anfen, nou ankapsile bouton yo nan yon veso div epi mare yo nan galri Gridzy la, lè nou mete opsyon filterControls la:
<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>Kòm ou ka wè, nou menm tou nou itilize yon seleksyon CSS pou opsyon filterControls la. Veso div la ak atribi id la sèlman sèvi pou fè bouton yo pi fasil pou chwazi atravè seleksyon CSS sa a.
Se sa!
Si w prefere yon solisyon JavaScript, tcheke API a.
API
Malgre ke Gridzy gen pwòp API li, pifò bagay yo ka fè san li, tou senpleman pa manipile DOM la. Gridzy pral remake li epi ajiste griy la. Men, gen tou yon API trè pwisan ...
Manipile DOM la
Pou tout manipilasyon Modèl Objè Dokiman (DOM) nou bezwen premye eleman veso a:
// get the container element
var gridzyElement = document.querySelector('.gridzy');Ajoute imaj
Li enpòtan pou konplètman bati ak ranpli nouvo eleman pitit la anvan ou ajoute li nan eleman veso a. Sinon Gridzy pa ka detekte dimansyon kòrèk yo.
// 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);Retire imaj yo
// remove the first image
gridzyElement.removeChild(gridzyElement.firstElementChild);Chanje Opsyon yo
// 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');Plis enfòmasyon sou manipile DOM ou ka jwenn nan MDN web docs . Genyen tou yon Entwodiksyon nan DOM ki disponib.
Pwopriyetè API
Pou itilize API a, nou bezwen premye egzanp Gridzy la, ki se mare nan eleman veso Gridzy la:
// get the Gridzy instance
var gridzyInstance = document.querySelector('.gridzy').gridzy;Jwenn Opsyon
// get the value of a single option
var currentLayout = gridzyInstance.getOption('layout');Jwenn Tout Opsyon yo
// get all option values as an object
var currentOptions = gridzyInstance.getOptions();Mete Opsyon
// set specific option values
gridzyInstance.setOptions({
spaceBetween: 10,
layout: 'waterfall'
});
// or reset options to their default values
gridzyInstance.setOptions({
spaceBetween: null,
layout: null
});Aplike filtè
Aplike yon filtè se jis mete filter opsyon ki kapab nenpòt seleksyon CSS valab:
// 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'
});Ajoute Fonksyon Callback
DEPREKATE depi vèsyon 2.4.0
Sèvi ak Evènman modèn ak pi fleksib pito. Gade pwochen seksyon an pou plis detay.
Gridzy.js 2 sipòte kèk opsyon pou fonksyon callback. Yo ka mete sèlman atravè API propriétaires, men jis tankou lòt opsyon:
// 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.
}
});Sèvi ak Evènman
depi vèsyon 2.4.0
Ou ka itilize evènman Gridzy egzakteman menm jan ak evènman JavaScript nòmal:
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.
});Gen kèk evènman yo te tire sou eleman nan veso Gridzy ak lòt evènman yo te tire sou eleman yo endividyèl atik ki nan eleman nan veso.
Evènman ki te tire sou eleman veso Gridzy la:
event.target bay eleman veso Gridzy la.
event.detail.instance bay egzanp Gridzy la.
Evènman ki te tire sou eleman atik yo:
event.target bay eleman respektif atik la.
event.detail.instance bay egzanp Gridzy la.
API la vle di Global
Gen kèk fonksyon ki endepandan de egzanp Gridzy. Se konsa, nou pa bezwen jwenn yon egzanp anvan.
Jwenn Opsyon Default
// get the default value of a single option
var defaultLayout = Gridzy.getDefaultOption('layout');Jwenn Tout Opsyon Default
// 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');Mete Opsyon Default
Sa a pa mete opsyon yo nan tout sikonstans Gridzy ki deja inisyalize yo, men li defini baz pou nouvo ka yo. Sepandan, si yon opsyon yon egzanp ki egziste deja ta dwe reset atravè valè a null , li ta sèvi ak nouvo valè default la.
// set default option values
Gridzy.setDefaultOptions({
spaceBetween: 10,
layout: 'waterfall'
});Ou ka itilize sa a pou mete opsyon globalman, si ou rele li anvan DOM pare. Se konsa, ou pa ta bezwen mete opsyon kòm atribi ankò.
Automatismes
Osi lontan ke tout automatism nan Gridzy.js 2 yo aktif, pa gen okenn bezwen pou metòd ki anba yo. Men, automatis yo ka etenn pou itilize Gridzy nan yon fason ki pi tradisyonèl:
// 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
});Gen kèk nan opsyon sa yo pa ka mete atravè atribi data-gridzy- oswa atravè setOptions() , akòz rezon ki lojik:
Inisyalize Manyèlman
// initialize a new Gridzy instance
var gridzyInstance = new Gridzy(document.querySelector('.gridzy'), {
spaceBetween: 10,
layout: 'waterfall'
});Detwi Enstans lan
Apeprè di, opoze a nan inisyalize Gridzy.
gridzyInstance.destroy();
gridzyInstance = null;Senkronize lis timoun yo manyèlman
// after child elements (images) are added to or removed from the DOM.
gridzyInstance.syncChildList();Senkronize yon sèl Eleman Timoun Manyèlman
Anjeneral pa nesesè, eksepte nan ka ki ra anpil.
// after child elements (images) are added to the DOM and only one of them should be synced to Gridzy.
gridzyInstance.syncChild(childElement);Senkronize atribi yo manyèlman
Remake byen ke opsyon useOptionAttributes dwe true pou sa.
// after data-gridzy- attributes have changed
gridzyInstance.syncAttributes();Fòs rann
Anjeneral pa nesesè, menm si tout automatism yo etenn
gridzyInstance.render();