Vèsyon 2.x


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

Valè DefaultDeskripsyon
animatetrueDetèmine si wi ou non animasyon yo ta dwe itilize lè kadriyaj la chanje (pa egzanp, lè redimensionnement fenèt navigatè a oswa lè w ap mete yon filtè).
layoutjustifiedDefini layout itilize a. Gridzy.js 2 sipòte de layouts diferan justified ak waterfall . Chak nan yo gen pwòp paramèt opsyon adisyonèl, ki ou ka jwenn anba a tablo sa a.
filter*Detèmine ki imaj yo ta dwe montre. Nenpòt seleksyon CSS ka itilize kòm valè isit la. Anjeneral mete otomatikman atravè filterControls (gade pwochen opsyon).
Tcheke Filtè yo
filterControlsDetèmine ki eleman fòm yo ka itilize pou filtre imaj yo. Nenpòt seleksyon CSS, ki chwazi eleman fòm HTML, ka itilize kòm valè isit la.
Tcheke Filtè yo
autoConsiderScrollBarstruePou predi lajè ki disponib si ba woulo liv parèt oswa disparèt. Li toujou rekòmande pou kite li sou true sof si automatism sa a lakòz pwoblèm.

Justified Opsyon Layout

Valè DefaultDeskripsyon
autoFontSizefalseOtomatikman mete ajou pwopriyete a font-size nan chak bwat ki baze sou gwosè bwat orijinal la. Pa default pwopriyete font-size pa mete klèman.
desiredHeight190Defini wotè vle a nan ranje eleman yo. Wotè aktyèl la pral kalkile depann sou lajè ki disponib ak eleman ki nan ranje a.
hideOnMissingImagetrueKache bwat ki gen imaj ki pa t kapab chaje.
spaceBetween4Defini distans ki genyen ant eleman an piksèl.
lastRowAlign
depi vèsyon 2.3.0
justifiedDefini konpòtman dènye ranje a. Valè yo otorize yo left , center , right ak justified .
singleRowAlign
depi vèsyon 2.3.0
justifiedDefini konpòtman an si gen sèlman yon sèl ranje. Valè yo otorize yo left , center , right ak justified .
fillLastRow
depi vèsyon 2.1.0
trueRETIRE depi vèsyon 2.4.0 (DEPREKATE depi vèsyon 2.3.0 )
Fè aranjman imaj yo pou dènye ranje a toujou ranpli nèt. Si w gen plan pou ajoute imaj dinamik, li ta ka yon bon lide dezaktive sa a.
Pa pran okenn efè sou yon sèl ranje (gade fillSingleRow ).
fillSingleRow
depi vèsyon 2.1.0
trueRETIRE depi vèsyon 2.4.0 (DEPREKATE depi vèsyon 2.3.0 )
Si gen yon sèl ranje, li fè aranjman pou imaj yo pou ke ranje a toujou konplètman ranpli. Si li ka rive ke ou gen sèlman youn oubyen de imaj nan galri a, li ta ka yon bon lide yo dezaktive sa a.

Waterfall Opsyon Layout

Valè DefaultDeskripsyon
autoFontSizefalseOtomatikman mete ajou pwopriyete a font-size nan chak bwat ki baze sou gwosè bwat orijinal la. Pa default pwopriyete font-size pa mete klèman.
desiredWidth250Defini lajè a vle nan kolòn. Lajè aktyèl la pral kalkile depann sou lajè ki disponib ak kantite kolòn yo.
hideOnMissingImagetrueKache bwat ki gen imaj ki pa t kapab chaje.
horizontalOrderfalseDefini ke eleman yo yo mete estrikteman yon sèl eleman nan chak kolòn soti nan goch a dwat, Lè sa a, kòmanse ankò nan kolòn ki pi gòch la endepandan nan ki kolòn se plis plas. Pa default eleman yo ap toujou mete nan kolòn ki gen wotè ki pi piti a.
spaceBetween4Defini distans ki genyen ant eleman an piksèl.
singleRowAlign
since version 2.7.0
justifiedDefines the behavior when not all columns can be filled due to too few images. Allowed values are left, center, right and justified.

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 ul ak li (jis konsidere reset navigatè default).
  • Si yon eleman img se pa yon timoun dirèk tèt li, li bezwen klas gridzyImage .

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
gridzySkinClassicLight(DEPREKATE depi vèsyon 2.6.0)
gridzySkinFullOverlay
aperçu live
gridzySkinFullOverlay
gridzySkinFullOverlayLight(DEPREKATE depi vèsyon 2.6.0)
gridzySkinLift
aperçu live
gridzySkinLift
gridzySkinLiftLight(DEPREKATE depi vèsyon 2.6.0)
gridzySkinMagnifier
Fonksyonalite zoom pa enkli
aperçu live
gridzySkinMagnifier
gridzySkinMagnifierLight(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
gridzySkinBlurLight(DEPREKATE depi vèsyon 2.6.0)
gridzySkinCard
aperçu live
gridzySkinCard
gridzySkinCardLight(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
VaryabValè DefaultEnfòmasyon
--backgroundrgba(0, 0, 0, .7)pèmèt nenpòt valè background CSS
--colorrgb(255, 255, 255)pèmèt nenpòt valè koulè CSS
--text-shadownonepèmèt nenpòt valè tèks-lonbraj CSS
gridzySkinFullOverlay
VaryabValè DefaultEnfòmasyon
--backgroundrgba(0, 0, 0, .7)pèmèt nenpòt valè background CSS
--colorrgb(255, 255, 255)pèmèt nenpòt valè koulè CSS
--text-shadownonepèmèt nenpòt valè tèks-lonbraj CSS
gridzySkinLift
VaryabValè DefaultEnfòmasyon
--backgroundrgba(0, 0, 0, .7)pèmèt nenpòt valè background CSS
--colorrgb(255, 255, 255)pèmèt nenpòt valè koulè CSS
--text-shadow0 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
VaryabValè DefaultEnfòmasyon
--backgroundrgba(0, 0, 0, .7)pèmèt nenpòt valè background CSS
--colorrgb(255, 255, 255)pèmèt nenpòt valè koulè CSS

Po sa a pa sipòte --text-shadow

gridzySkinBlur
VaryabValè DefaultEnfòmasyon
--backgroundrgba(0, 0, 0, .7)pèmèt nenpòt valè background CSS
--colorrgb(255, 255, 255)pèmèt nenpòt valè koulè CSS
--text-shadow0 0 10px rgb(0, 0, 0)pèmèt nenpòt valè tèks-lonbraj CSS
gridzySkinCard
VaryabValè DefaultEnfòmasyon
--backgroundrgba(0, 0, 0, 1)pèmèt nenpòt valè background CSS
--colorrgb(255, 255, 255)pèmèt nenpòt valè koulè CSS
--text-shadownonepè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

  1. 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.
  2. 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 laDeskripsyon
gridzy
yo mete manyèlman
Gridzy otomatikman jwenn eleman ak klas sa a epi li inisyalize yo.
gridzyAnimatedYo 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 laDeskripsyon
gridzyItemYo pral mete le pli vit ke atik la kòmanse pwosesis la inisyalize. Yo pap janm retire.
gridzyItemInitializingYo 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.
gridzyItemReadyPral 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.
gridzyItemLoadingYo 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.
gridzyItemCompletePral ranplase gridzyItemLoading le pli vit ke imaj ki genyen yo (anjeneral yon sèl) yo konplètman chaje. Yo pap janm retire.
gridzyItemInitialToVisibleYo 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.
gridzyItemVisibleYo 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.
gridzyItemVisibleToHiddenYo pral mete le pli vit ke atik la kòmanse disparèt. Yo pral retire le pli vit ke atik la konplètman kache.
gridzyItemHiddenYo pral mete le pli vit ke atik la konplètman kache. Yo pral retire le pli vit ke atik la kòmanse parèt.
gridzyItemHiddenToVisibleYo 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.
gridzyItemVisibleToVisibleYo 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:

  1. Mete atribi width ak height jan sa dekri pi wo a (asire w ou sèvi ak valè kòrèk yo)
  2. Ranplase tout atribi src ak data-gridzylazysrc jan yo montre anba a (si ou gen atribi srcset tou, ranplase yo ak data-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:

  1. Mete chak eleman img nan yon eleman div
    (oswa nan nenpòt lòt eleman - gade HTML semantik pou plis)
  2. Ajoute klas gridzyImage nan chak eleman img
<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.
  }
});
Deskripsyon
onBeforeOptionsChangedFonksyon callback ki envoke dirèkteman anvan yo tabli opsyon.
onOptionsChangedFonksyon callback ki envoke dirèkteman apre yo fin mete opsyon.
onBeforeRenderFonksyon callback ki envoke dirèkteman anvan rann.
onRenderFonksyon callback ki envoke dirèkteman apre rann.

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:

Deskripsyon
gridzyBeforeInitDife anvan inisyalizasyon galri a.
gridzyInitDife apre inisyalizasyon galri.
gridzyBeforeOptionsChangedDife anvan yo mete opsyon.
gridzyOptionsChangedDife apre yo fin mete opsyon.
gridzyBeforeRenderDife anvan rann.
gridzyRenderDife apre rann.
Si w rate nenpòt evènman isit la, tanpri voye yon demann sipò .

event.target bay eleman veso Gridzy la.
event.detail.instance bay egzanp Gridzy la.

Evènman ki te tire sou eleman atik yo:

Deskripsyon
gridzyItemBeforeInitDife anvan inisyalizasyon atik la.
gridzyItemInitDife apre inisyalizasyon atik la.
gridzyItemLoadingDife lè atik la kòmanse chaje.
gridzyItemReadyDife lè atik la pare pou kalkil kadriyaj la. Se konsa, rapò aspè a li te ye, men imaj la ka toujou ap chaje.
gridzyItemCompleteDife lè imaj atik la konplètman chaje.
Si w rate nenpòt evènman isit la, tanpri voye yon demann sipò .

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:

Valè DefaultDeskripsyon
autoInitOnDomReadytrueDetekte eleman ak klas gridzy sou paj chaje ak inisyalize yo.

Konfitab atravè Gridzy.setDefaultOptions()
autoInitOnDomMutation
MutationObserver
trueDetekte eleman nouvo ak gridzy klas le pli vit ke yo parèt nan DOM la epi inisyalize yo. (pa egzanp lè w itilize tranzisyon paj)

Konfitab atravè Gridzy.setDefaultOptions()
autoSyncChildListMutation
MutationObserver
trueDetekte si eleman timoun yo (imaj) yo ajoute oswa retire, epi mete ajou kadriyaj la otomatikman.

Konfitab atravè data-grizy- , new Gridzy() , setOptions() , Gridzy.setDefaultOptions()
useOptionAttributestrueDefini si atribi data-gridzy- yo jeneralman itilize oswa ou pa. Si sa a se false opsyon yo ka mete sèlman atravè API propriétaires la.

Konfitab atravè new Gridzy() , setOptions() , Gridzy.setDefaultOptions()
autoSyncAttributesMutation
MutationObserver
trueDetekte chanjman nan data-gridzy- atribi, epi mete ajou kadriyaj la otomatikman. Epitou detekte si yo ajoute oswa retire klas gridzyAnimated la epi si chanjman nan atribi style yo rive. Si useOptionAttributes se false , li detekte sèlman chanjman nan atribi style .

Konfitab atravè data-grizy- , new Gridzy() , setOptions() , Gridzy.setDefaultOptions()
autoSyncChildClassMutation
MutationObserver
trueDetekte chanjman nan atribi class nan tout eleman timoun (imaj). Ki enpòtan konsènan filtè yo.

Konfitab atravè data-grizy- , new Gridzy() , setOptions() , Gridzy.setDefaultOptions()
autoSyncImageMutation
MutationObserver

depi vèsyon 2.5.0
trueDetekte chanjman nan atribi src nan tout imaj. Ki enpòtan lè yo itilize ak React oswa bibliyotèk menm jan an.

Konfitab atravè data-grizy- , new Gridzy() , setOptions() , Gridzy.setDefaultOptions()
autoRenderOnResize
ResizeObserver

depi vèsyon 2.6.0
trueDetekte chanjman nan lajè eleman an. Ki enpòtan konsènan konsepsyon reponn. (Anvan vèsyon 2.6.0 yo te itilize yon oditè evènman redimensionnement fenèt)

Konfitab atravè data-grizy- , new Gridzy() , setOptions() , Gridzy.setDefaultOptions()

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();