Version 2.x


Cleaysh Bun-Troggalys

Lught-thie ny coadanyn Gridzy er dty serveyr as cuir ad er dty laghyn-lhee (goaill stiagh y rannagh head):

<link rel="stylesheet" href="gridzy/gridzy.min.css" />
<script src="gridzy/gridzy.min.js"></script>

Cur rish y code HTML (erbee 'sy rannagh corp):

<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>

Shen eh! Ta shen ymmyd glen. Cha nel feme erbee er y toshiaght.

Reihys

Yn raad s'easys da Gridzy y rheynn, she ymmyd y yannoo jeh attributes HTML. Ta feme ort agh ymmyd y yannoo jeh ainmyn roghnagh lesh data-gridzy- . So, dy set y roshtyn spaceBetween , cuir rish y ghraih 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>

Pryssoonyn

Lught ry-hoiCoontey
animatetrueTa'n 'animation' ry-chlashtyn tra ta'n grid ry-chaghlaa (mar shampleyr, tra t'eh ry-chasley 'sy 'browser' ny tra t'eh ry-chasley rish y 'filter').
layoutjustifiedDefines y layout ymmydit. Gridzy.js waterfall t'eh jannoo ymmyd jeh'n daa layout justified . Ta parameteryn option ymmyrchagh ec gagh un jeh, as t'ad ry-gheddyn fo'n table shoh.
filter*Determines c'raad dy row ny skeealyn dy ve soilshit. Faggys da'n CSS-selector y ghleiyrey myr 'valjagh' 'sy 'valjagh' shoh. As t'eh ry-hoi ry-hoi trooid filterControls (fakin y rowl ry-hoi).
Cur-my-ner ny Filteryn
filterControlsDetermines c'raad t'eh ry-chlashtyn cre'n form elements t'eh ry-chlashtyn rish y skeeal. Faggys da'n rheynn CSS, ta roshtyn eilynnyn form HTML, ve ushit myr value 'sy 'nnyd shoh.
Cur-my-ner ny Filteryn
autoConsiderScrollBarstrueSon dy row yn lead ta ry-gheddyn my ta barrantyn scroll ry-akin ny ry-gholl ersooyl. Ta'n aght shoh dagh ooilley traa ry-hoi 'sy true , mannagh vel y automatism shoh cur rish faghtyn.

Justified Roghanyn skeeal

Lught ry-hoiCoontey
autoFontSizefalseTa'n font-size jeh gach box ry-hickyraghey dy h-automagh er y box t'er-dy-hoshiaght. By default cha nel y font-size ry-hoi ry-hoi.
desiredHeight190Ta'n ard-vooinjer taitnyssagh jeh rowyn element. Ta'n ard-chree ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi.
hideOnMissingImagetrueTa bocsanyn ry-gheddyn ayndoo nagh row ry-loadaghey.
spaceBetween4Ta'n aght t'eh ry-akin ry-akin ayns pixelyn.
lastRowAlign
veih'n veear 2.3.0
justifiedDefines gimmeeaght y row s'jerree. Ta ny values left , center , right as justified .
singleRowAlign
veih'n veear 2.3.0
justifiedDefines y gimmeeaght mannagh vel agh un row. Ta ny values left , center , right as justified .
fillLastRow
veih'n veear 2.1.0
trueER CHOYRT jeh'n veear 2.4.0 (ER CHEEILLEY veih'n veear 2.3.0 )
Reih ny skeealyn myr shen dy bee y row s'jerree dagh ooilley traa ry-liooar. Raad taitnys ayd dy chur stiagh ymmydyn dynamysagh, shegin da ve red mie dy ghleiy eh.
Cha nel eh jannoo ymmyd jeh rowyn shingil (fakin fillSingleRow ).
fillSingleRow
veih'n veear 2.1.0
trueER CHOYRT jeh'n veear 2.4.0 (ER CHEEILLEY veih'n veear 2.3.0 )
Mannagh vel agh un row, t'eh ry-cheilley ny skeealyn dy vod y row dagh ooilley traa y llieeney dy kiaralagh. Mannagh vod eh tarroo dy vel agh un ymmyd ny daa ymmyd ayd 'sy gallery, shegin da ve red mie dy 'deactivate' eh.

Waterfall Roghanyn skeeal

Lught ry-hoiCoontey
autoFontSizefalseTa'n font-size jeh gach box ry-hickyraghey dy h-automagh er y box t'er-dy-hoshiaght. By default cha nel y font-size ry-hoi ry-hoi.
desiredWidth250Defines y lheid y column. Ta'n leed ghrinney er ny rheynn lurg y leed ta ry-gheddyn as yn earroo dy cholumnyn.
hideOnMissingImagetrueTa bocsanyn ry-gheddyn ayndoo nagh row ry-loadaghey.
horizontalOrderfalseTa'n aght shoh cur stiagh dy vel ny eilynnyn currit stiagh strictly un eiraght ayns gagh column veih'n chleaysh gys y laue yesh, as t'eh toshiaght reesht 'sy cholumn chleaysh s'leaie er-lheh ayns c'raad ta'n column ny s'leaie. By default, bee ny eilynnyn dagh ooilley traa er nyn goyrt ayns y cholught lesh y h-ardjyn sloo.
spaceBetween4Ta'n aght t'eh ry-akin ry-akin ayns pixelyn.
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.

Roghyn Ard-vooaralagh

Son roghanyn ny s'ardjey, jeeagh er y API .

HTML cowraghey

Yn structuur HTML smoo symmoil jeh Gridzy eh shoh:

<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>

Agh, ta Gridzy feer flexible as t'ou uss able dy uss strughtoor HTML elley. Cha nel agh beggan pointaghyn dy chur ayns coontey:

  • Ta gagh leigh jeh'n eilley container currit da un red 'sy grid.
  • Faggys da'n eiraght container as e chloan ve dagh sorch taggyrt, myr ul as li (ny smooinee er reset y browser).
  • Mannagh vel eiraght img ny leigh direct hene, shegin da'n class gridzyImage .

So t'eh shoh myrgeddin strughtoor HTML obbree:

<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>

Son y chooid smoo, my shegin dhyt captions y chur rish, shegin dhyt structure HTML ry-hoi. Son tushtey er, cur-my-ner Captions & Skins .

Captanyn as Skinyn

As my shegin dhyt captions y chur rish dty gallery, shegin dhyt y appearance y mharkey. Son shen, ta cuid jeh'n skianyn predefined ry-gheddyn. Gagh skin t'ayns file CSS. Ta feme ort da'n coadan shoh y chur rish ny coadanyn Gridzy p'raad (goaill stiagh 'sy rannagh 'head'):

<link rel="stylesheet" href="gridzy/skins/gridzySkinClassic/style.min.css" />

As ry-hoi, shegin dhyt structuur HTML ry-hoi:

<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>

Marish y strughtoor HTML, cur-my-ner Semantic HTML .

Son y caption t'ou uss uss ymmyd jeh'n aght taggyrt, agh jean shickyr dy vel y class gridzyCaption . Ta'n eiraght img feme er y chlass gridzyImage .

Ta'n eie ry gridzySkinClassic akin ry-akin rish y skin . Son ymmyd jeh fer elley, gow yn ennym skin ayns ynnyd jeh'n ennym shoh:

Skins Goit stiagh

Classyn ry gheddyn
craie gridzy blank
boayl toshiaght mie son cruinnaghey craidey hene
Roish-akin beo
gridzySkinBlank
gridzySkinClassic
Roish-akin beo
gridzySkinClassic
gridzySkinClassicLight(ER CHEEILLEY veih'n veear 2.6.0)
gridzySkinFullOverlay
Roish-akin beo
gridzySkinFullOverlay
gridzySkinFullOverlayLight(ER CHEEILLEY veih'n veear 2.6.0)
gridzySkinLift
Roish-akin beo
gridzySkinLift
gridzySkinLiftLight(ER CHEEILLEY veih'n veear 2.6.0)
gridzySkinMagnifier
cha nel obbyr zoom er ny choyrt stiagh
Roish-akin beo
gridzySkinMagnifier
gridzySkinMagnifierLight(ER CHEEILLEY veih'n veear 2.6.0)

Ta ooilley ny skinnyn shoh feme er file CSS, agh ta skinnyn elley ta feme er file JavaScript myrgeddin:

<link rel="stylesheet" href="gridzy/skins/gridzySkinBlur/style.min.css" />
<script src="gridzy/skins/gridzySkinBlur/script.min.js"></script>
Classyn ry gheddyn
gridzySkinBlur
cha nel eh gobbraghey ayns IE
Roish-akin beo
gridzySkinBlur
gridzySkinBlurLight(ER CHEEILLEY veih'n veear 2.6.0)
gridzySkinCard
Roish-akin beo
gridzySkinCard
gridzySkinCardLight(ER CHEEILLEY veih'n veear 2.6.0)

Roghyn Skin

Ta'n version 2.6.0 ry-gheddyn Roghyn dy rheynn ny skianyn ry-gheddyn. Ta'n skin ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi. Ta feme ort agh ymmyd y yannoo jeh eiraghtyn custom CSS myr ta shiu er vakin ec shoh:

<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>

Cur-my-ner ny variablyn tastey as ny values ry-hoi ry-hoi son gach skin shoh:

gridzySkinClassic
Ard-chaghlaaLught ry-hoiFys
--backgroundrgba(0, 0, 0, .7)t'eh ceaut dagh ymmyd CSS
--colorrgb(255, 255, 255)t'eh ceaut dagh ymmyd CSS
--text-shadownonet'eh ceaut dagh ard-valjagh text-shadow CSS
gridzySkinFullOverlay
Ard-chaghlaaLught ry-hoiFys
--backgroundrgba(0, 0, 0, .7)t'eh ceaut dagh ymmyd CSS
--colorrgb(255, 255, 255)t'eh ceaut dagh ymmyd CSS
--text-shadownonet'eh ceaut dagh ard-valjagh text-shadow CSS
gridzySkinLift
Ard-chaghlaaLught ry-hoiFys
--backgroundrgba(0, 0, 0, .7)t'eh ceaut dagh ymmyd CSS
--colorrgb(255, 255, 255)t'eh ceaut dagh ymmyd CSS
--text-shadow0 0 10px rgb(0, 0, 0), 0 0 20px rgb(0, 0, 0), 0 0 30px rgb(0, 0, 0)t'eh ceaut dagh ard-valjagh text-shadow CSS
gridzySkinMagnifier
Ard-chaghlaaLught ry-hoiFys
--backgroundrgba(0, 0, 0, .7)t'eh ceaut dagh ymmyd CSS
--colorrgb(255, 255, 255)t'eh ceaut dagh ymmyd CSS

Cha nel y crosh shoh cur tastey da --text-shadow

gridzySkinBlur
Ard-chaghlaaLught ry-hoiFys
--backgroundrgba(0, 0, 0, .7)t'eh ceaut dagh ymmyd CSS
--colorrgb(255, 255, 255)t'eh ceaut dagh ymmyd CSS
--text-shadow0 0 10px rgb(0, 0, 0)t'eh ceaut dagh ard-valjagh text-shadow CSS
gridzySkinCard
Ard-chaghlaaLught ry-hoiFys
--backgroundrgba(0, 0, 0, 1)t'eh ceaut dagh ymmyd CSS
--colorrgb(255, 255, 255)t'eh ceaut dagh ymmyd CSS
--text-shadownonet'eh ceaut dagh ard-valjagh text-shadow CSS

Ta ooilley ny skinyn ro-mharkey jannoo ymmyd jeh captions text simply. Ta shiu able dy chroo ny skianyn eu hene as ny smoo complex. Ta mee er n'yannoo rish Style Gridzy .

Stiyl Gridzy

As mannagh vel skin predefined ry-hoi rish dty ymmyd, t'ou uss stylish dty skin hene.

Yn raad s’easys t’ayn, she copy y yannoo jeh’n skin ta ry-gheddyn as dy ghleiy eh gys dty h-earroo. Ta'n gridzySkinBlank skin ry-mharkey ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi:

/** 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;
}

'Sy file CSS t'ou uss goaill rish ny claasyn gridzySkinBlank , gridzyImage as gridzyCaption . Gridzy hene cha nel eh feme er ny claassyn shoh. Ta'd ry-chleayney son stylish as shen-y-fa t'ou uss ry-chur magh ny ry-enmyssey my shegin dhyt.

As t'eh ry-akin 'sy chlass CSS gridzyItem . Gridzy t'eh cur y chlass shoh dy h-automagh da ooilley ny cloan direct jeh'n phreeu-element container. So, t'ou uss uss y class shoh y stylish rish ny reddyn 'sy gallery.

Mind Ruddyn Pooar

  1. Bun-chowrey y red dy row freggyrtagh. Smooinee er dy bee y mhean element ry-chasley dy shickyr. Cleaysh ymmyd percentage ayns ynnyd ymmyd pixel. As cur-my-ner y rowl layout Gridzy autoFontSize , ta ceau y font-mean er y box-item.
  2. Bun-chowrey t’ayn dy vel aspect ratio ry-akin ec gagh red. Cha jean aspect ratio y red y chaghlaa as t'eh ry-hoi ry-hoi ry-hoi ry-hoi ry-hoi. Son mannagh vel red erbee ry-mharkey dy mie, mharkey eh ry-mharkey lesh laue (e.g. trooid css).

Ayns cuid jeh'n aght, t'eh ny s'easyl stylish y ghraih jeh'n obbyr roish my t'eh Gridzy y toshiaght. Ta'n gridzy class ny y file javascript Gridzy ry-gheddyn son shoh.

Shen eh! Ta shen ooilley ny ta ry-yannoo son y skin hene y thooilley. Ta'n chooid smoo jeh ny skinyn predefined cha n'ussaghey ny smoo na shoh.

Agh might be ny smoo my shegin dhyt ...

Skinnyn Ard-Sheer

Ta Gridzy usaghey ny smoo claassyn CSS na gridzyItem . Ta'n chooid smoo jeu ry-gheddyn automatically as t'ou uss ry-chleayney son stylish myrgeddin.

Pryssoonyn Pryssoonagh

Ennym y ChlassCoontey
gridzy
dy reayll lesh laue
Gridzy t'eh glenney elementyn rish y chlass shoh as t'eh ymmyrkey ad.
gridzyAnimatedT'eh er ny choyrt dy h-automagh my ta'n roshtyn animate true . Mannagh vel y class shoh soit lesh laue, bee'n roshtyn animate ry-gheddyn true myrgeddin (agh my t'eh soit ry-cheilley er false ).

Classyn ny reddyn

Ennym y ChlassCoontey
gridzyItemT'eh er ny choyrt choud's ta'n obbyr toshiaght y phroses initializing. Cha bee eh er ny ghoaill ersooyl.
gridzyItemInitializingT'eh er ny choyrt choud's ta'n obbyr toshiaght y phroses initializing. T'eh er ny choyrt ayns ynnyd gridzyItemReady choud's t'eh er ny h-insh. Ta shen dy ghra dy vel ymmydyn ry-loadaghey dy kiaralagh (fakin gridzyItemLoading ), agh ta'n obbyr ry-loadaghey dy ve feeu.
gridzyItemReadyTa'n gridzyItemInitializing er ny choyrt ayns ynnyd choud's ta'n obbyr er ny h-oardaghey dy kiaralagh. Cha bee eh er ny ghoaill ersooyl. Ta shen dy ghra, cha nel ymmydyn ry-loadaghey dy kiaralagh (fakin gridzyItemComplete ), agh ta'n obbyr ry-loadaghey dy ve feeu.
gridzyItemLoadingT'eh er ny choyrt choud's ta'n obbyr toshiaght y phroses initializing. T'eh er ny chur ayns ynnyd gridzyItemComplete choud's ta ny skeealyn ayn (goaill stiagh un skeeal) er nyn loadaghey dy kiaralagh.
gridzyItemCompleteTa'n gridzyItemLoading er ny chur ayns ynnyd choud's ta'n skeeal t'ayn (goaill stiagh un skeeal) er ny lhoobaghey dy kiaralagh. Cha bee eh er ny ghoaill ersooyl.
gridzyItemInitialToVisibleT'eh er ny choyrt choud's t'eh toshiaght dy heet magh y chiad cheayrt. T'eh er ny chur ersooyl choud as ta'n red er ny hoilshaghey dy kiaralagh.
gridzyItemVisibleT'eh er ny set choud as ta'n red er ny hoilshaghey dy kiaralagh. T'eh er ny chur ersooyl choud as t'eh toshiaght dy gholl ersooyl.
gridzyItemVisibleToHiddenBee eh set choud as t'eh toshiaght dy gholl ersooyl. T'eh er ny chur magh choud's ta'n red follit dy kiaralagh.
gridzyItemHiddenT'eh er ny choyrt choud as t'eh er ny h-offrey dy kiaralagh. T'eh er ny chur magh choud as t'eh toshiaght dy heet magh.
gridzyItemHiddenToVisibleT'eh er ny choyrt choud as t'eh toshiaght dy h-earroo (agh t'eh er ny h-earroo y chiad cheayrt – cur-my-ner y chlass gridzyItemInitialToVisible ). T'eh er ny chur ersooyl choud as ta'n red er ny hoilshaghey dy kiaralagh.
gridzyItemVisibleToVisibleT'eh er ny choyrt choud's ta red erbee 'sy grid er chaghlaa, agh va'n red hene as stay visible. T'eh er ny chur magh choud's t'an animation y chaghlaa er jeet gys jerrey.

As t'eh ry-akin, ta'n indicator process as ny animations son ymmydyn ta ry-akin as ry-akin er nyn rheynn ro-laue liorish y phreeu-fail CSS Gridzy.

Lesh ny claassyn CSS shoh t'er ny mharkey, t'ou uss stylish y stiureyder as ny animations. Dare s'cosoylagh rish y phreeu-fail CSS Gridzy, dy hoiggal cre'n red t'ou dy ghra. Cha nel aggle erbee, ta ooilley ny reddyn documentit dy mie ayn.

Optimize y lhoobey

Mannagh uss uss ymmyd jeh ymmodee ymmydyn, shegin da ve red mie dy chur cooney da Gridzy dy thoggal y grid ny s'faggys da.

Cur cass da skeealyn leshtal

Ta Gridzy dy bragh feme er y ratio aspect jeh ooilley ny skeeallyn dy ghra y grid. Ta ny reddyn shoh ry-akin ayns elementyn leshtal my ta cuid jeh ny skeealyn ready as feallagh elley nagh vel. Yn chooid smoo dy skeealyn, y chooid smoo annoying t'eh y effect shoh.

Son y ghraih shoh y chosney, s'cosoylagh dy row attributes width as height ry-gheddyn son ooilley ny eilynnyn img . Ta'n red s'taitnyssagh dy row ny values cooie ry-gheddyn son gach ymmyd, er-nonney veagh ny ymmydyn ry-gheddyn. Ta ny luaghyn cooie yn lead as y h-ardjyn bunneydagh jeh'n deiney:

<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>

As lurg shen, t'eh ry-hoi Gridzy y grid y rheynn dy h-oikoil gyn feme dy hoiggal maghyn y skeeal.

Loading Lazy

Son ymmyd y yannoo jeh ymmydyn ta 'sy viewport feer-feeu, lesh ny steppyn shoh:

  1. Cur stiagh ymmyd width as height myr t'eh er ny screeu harrish (jean shiu shickyr dy uss ny luaghyn cooie)
  2. Cur stiagh ooilley ny t'ayns src lesh data-gridzylazysrc myr te er ny hoilshaghey (my ta t'ayns srcset myrgeddin, t'ad ry-cheilley lesh 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>

As lurg ny steppyn shoh, bee ny skeealyn loadaghey choud as t'ad ry-cheilley ny ry-cheilley rish y viewport.

Tastey Process

Yn 'process indicator' t'eh y 'icon' beg 'animated' ta ry-akin tra ta'n 'image' ry-loadaghey. As t'eh ry-akin captions & skins , as t'eh ry-akin 'sy phroseas. As cha nee shen, shegin dhyt jannoo ymmyd jeh:

  1. Cur gagh eiraght img ayns eiraght div
    (ny ayns red erbee elley – cur-my-ner HTML semantic son ny smoo)
  2. Cur rish y chlass gridzyImage da gach eiraght 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>

As lurg shen, shegin dhyt ny cowreydyn prosess y akin my ta'n skeeal goaill traa dy load.

Screeuyn

Filteryn ayns Gridzy t'ad s'simpley agh cummaltagh. Cha nel red erbee ry-akin cre'n sorch filter t'ayd, t'eh feer chymmoil dy vel eh realable. Ta'n red t'ayd feme, beggan CSS as beggan eilynnyn form HTML ...

Ta'n eie obbragh shoh:

<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>

Lhig dooin eh y hroggal Cashtal er Cashtal

1. Ard-earroo ta feme ain er y structuur HTML custoory jeh Gridzy as set ainmyn class son ooilley ny reddyn gallery dy voddyn ad y filter erreish da .

<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>

Ayns y skeeal shoh cha nel shin uss agh un chlass son gach element. Agh t'ou uss myrgeddin s'cosoylagh dy row ymmodee claasyn son un eiraght, my shegin da'n eiraght shen ve ry-gheddyn trooid ymmodee filteryn.

2. As t'ad cur rish cuid jeh'n botoonyn trooid y voddyn ny filteryn y chaghlaa eisht

<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>

Ayns ny botoonyn, might oo uss uss ymmyd y yannoo jeh form-elementyn elley myr checkboxyn, botoonyn radio, fieldyn roshtyn as myr shen.

As t'ou uss goaill rish, ta ny values jeh'n botanyn ny selectoryn CSS glen. Choud as ta shin er chlashtyn, click er botoon myr shen, bee ny skeeallyn ta co-chosney rish y CSS selector shen soilshaghey. Technically t'eh ry-hoi y filter 'sy 'value' shoh.

Faggys da selectoryn mooar ny s'cosoylagh y usaghey. Mar s'cosoylagh :not(.animals) obbree eh myrgeddin, myr shen .animals.people as .animals, .people .

3. Er-jerrey, ta shin encapsulate ny botanyn ayns cowrey div as ceau ad rish y galley Gridzy, trooid y rheynn 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>

As t'eh ry-akin, ta shin uss ry-chlashtyn rish CSS son y roshtyn filterControls . Ta'n container div lesh an id attribute ny s'easyl dy yannoo ny botanyn ny s'easyl dy reih trooid y reih CSS shen.

Shen eh!

Mannagh vel ymmyd jeh JavaScript, jeeagh er y API .

API

C'raad as ta Gridzy API echey hene, t'eh ry-hoi y chooid smoo jeh ny reddyn gyn eh, liorish ymmyd y yannoo jeh'n DOM. Gridzy t'eh ry-akin as t'eh ry-adjust y grid. Agh ta API ard-pooaralagh ayn myrgeddin ...

Ta'n DOM er ny obbraghey

Son ooilley ny obbraghyn Model Object Document (DOM) ta feme ain ec y toshiaght er y red container:

// get the container element
var gridzyElement = document.querySelector('.gridzy');

Cur Jaillyn rish

Ta'n red s'taitnyssagh dy h-earroo as dy h-earroo y h-element 'child' 'sy 'child element' 'sy 'container element'. As cha nel Gridzy ry-akin rish ny dimensionyn cooie.

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

Cur stiagh ymmydyn

// remove the first image
gridzyElement.removeChild(gridzyElement.firstElementChild);

Caghlaa roghanyn

// 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');

Tuilley er y DOM t'ou uss goaill rish MDN web docs . Ta Introduction 'sy DOM ry-gheddyn myrgeddin.

API ymmyrchagh

Son ymmyd y yannoo jeh'n API, shegin dooin yn instance Gridzy y chied cheayrt, ta ceaut rish y h-element container Gridzy:

// get the Gridzy instance
var gridzyInstance = document.querySelector('.gridzy').gridzy;

Faigh roshtyn

// get the value of a single option
var currentLayout = gridzyInstance.getOption('layout');

Faigh ooilley ny roghanyn

// get all option values as an object
var currentOptions = gridzyInstance.getOptions();

Roghanyn

// set specific option values
gridzyInstance.setOptions({
  spaceBetween: 10,
  layout: 'waterfall'
});

// or reset options to their default values
gridzyInstance.setOptions({
  spaceBetween: null,
  layout: null
});

Cur stiagh y screeudeyr

Ta cur ymmyd jeh'n filter ny s'cosoylagh rish y filter roghain oddys ve red erbee CSS ymmydoil:

// 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'
});

Cur rish obbraghyn Callback

ER CHEEILTYN veih'n veear 2.4.0
Cleays ny Eventyn noa-emshyragh as ny smoo flexible ayns ynnyd. Shionnee yn rannagh ry-heet son fys.

Gridzy.js 2 t'eh jannoo ymmyd jeh rollageyn son obbraghyn callback. Faggys da'n API 'sy 'proprietary', agh myr roghanyn elley:

// 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.
  }
});
Coontey
onBeforeOptionsChangedCallback function ta ry-gheddyn directly roish y rheynn roghanyn.
onOptionsChangedCallback function ta ry-gheddyn directly erreish da roghanyn ry-chur.
onBeforeRenderFunction callback ta ry-gheddyn dy kiart roish y rendering.
onRenderCallback function ta ry-gheddyn directly erreish da'n rendering.

Cleaysh Taghyrtyn

veih'n veeal 2.4.0

Faggys da taghyrtyn Gridzy y usaghey dy kiart myr taghyrtyn JavaScript glen:

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.
});

Ta roinney jeh'n obbyr ry-gheddyn 'sy 'element container Gridzy' as ta roinney jeh'n 'element item' ry-gheddyn 'sy 'element container'.

Taghyrtyn v'er nyn skeaylley er yn eiraght container Gridzy:

Coontey
gridzyBeforeInitFires roish y ghraih galley.
gridzyInitFires lurg y ghraih gallery.
gridzyBeforeOptionsChangedFires roish y rheynn roghanyn.
gridzyOptionsChangedFires lurg y rheynn roghanyn.
gridzyBeforeRenderFeeaghyn roish y rendering.
gridzyRenderFeeaghyn erreish da rendering.
Mannagh vel oo er n'yannoo red erbee 'sy 'nnyd shoh, cur stiagh irriney tastey .

event.target t'eh cur y ghraih Gridzy.
t'eh ry event.detail.instance akin 'sy Gridzy.

Tammyltaghyn er nyn skeaylley er eilynnyn:

Coontey
gridzyItemBeforeInitFires roish y toshiaght jeh'n obbyr.
gridzyItemInitFires lurg y toshiaght jeh'n obbyr.
gridzyItemLoadingFires tra t'eh toshiaght dy load.
gridzyItemReadyFires tra ta'n obbyr ready son rieughid grid. So ta'n ratio aspect ainjyssagh, agh t'eh ry-hoi y skeeal y loadaghey foast.
gridzyItemCompleteFires tra t'an ymmyd jeh'n item laghyn.
Mannagh vel oo er n'yannoo red erbee 'sy 'nnyd shoh, cur stiagh irriney tastey .

event.target t'eh cur y 'element' 'sy 'element'.
t'eh ry event.detail.instance akin 'sy Gridzy.

API - Cruinney

Ta rollageyn ayn ta neu-chrauee jeh instansyn Gridzy. So cha nel feme orrin instance y gheddyn roish.

Faigh roshtyn ry-hoi

// get the default value of a single option
var defaultLayout = Gridzy.getDefaultOption('layout');

Faigh ooilley ny roghanyn ry-hoi

// 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 Roghanyn ry-hoi

Ta'n red shoh cur stiagh ny roghanyn jeh ooilley ny instansyn Gridzy ta er nyn 'initialized', agh t'eh cur stiagh y bun son instansyn noa. Agh, my vees roshtyn jeh'n instance ta ry-gheddyn ry-reayll trooid y value null , t'eh uss y value ry-gheddyn ry-gheddyn.

// set default option values
Gridzy.setDefaultOptions({
  spaceBetween: 10,
  layout: 'waterfall'
});

Faggys oo eh dy hroggal roghanyn global, my t'ou uss goaill rish roish my bee DOM ready. Son cha row feme erbee erbee dy row roghanyn myr attributes ny s'anmey.

Automaghyn

Choud as ta ooilley ny automatismyn jeh Gridzy.js 2 glan, cha nel feme er ny moddey t'er-y-skyn. Agh t'eh ry-hoi y automatism y scughey dy uss Gridzy y usaghey ayns aght ny s'traidishonail:

// 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
});

Cuid jeh ny roghanyn shoh cha nel ad ry-chur trooid ymmyd data-gridzy- ny trooid setOptions() , er y fa dy vel adhbhantyn loghtagh:

Lught ry-hoiCoontey
autoInitOnDomReadytrueTa'n 'element' ry-akin lesh class gridzy er y 'load' 'page' as t'eh ry-insh ad.

Taitnyssagh trooid Gridzy.setDefaultOptions()
autoInitOnDomMutation
Arreyder Mutashoon
trueTa'n 'elementyn' noa ry-akin lesh gridzy class choud's ta'd ry-akin 'sy DOM as ry-insh ad. (e.g. er ymmyd jeh ymmyd jeh ymmyd jeh duillagyn)

Taitnyssagh trooid Gridzy.setDefaultOptions()
autoSyncChildListMutation
Arreyder Mutashoon
trueTa'n 'child element' (imageyn) er ny chur rish ny er ny chur magh, as t'eh cur y grid er-y-fa shen.

Taitnyssagh trooid data-grizy- , new Gridzy() , setOptions() , Gridzy.setDefaultOptions()
useOptionAttributestrueTa'n ' data-gridzy- ry-chlashtyn rish y 'data-gridzy-'. As t'eh false cha nel roghanyn ry-hoi ry-hoi agh trooid y API proprietary.

Taitnyssagh liorish new Gridzy() , setOptions() , Gridzy.setDefaultOptions()
autoSyncAttributesMutation
Arreyder Mutashoon
trueTa'n 'data-gridzy-' 'sy ' data-gridzy- attributes', as t'eh 'sy 'grid' 'sy 'data-gridzy'. Ta'n claas gridzyAnimated er ny chur rish ny er ny chur magh as my ta caghlaaghyn style er ny yannoo. Mannagh vel useOptionAttributes false , cha nel eh ry-akin agh ymmyd style .

Taitnyssagh trooid data-grizy- , new Gridzy() , setOptions() , Gridzy.setDefaultOptions()
autoSyncChildClassMutation
Arreyder Mutashoon
trueTa'n 'detect' jeh 'attributes class jeh ooilley ny eilynnyn-leigh (images). Relevant mychione ny filteryn.

Taitnyssagh trooid data-grizy- , new Gridzy() , setOptions() , Gridzy.setDefaultOptions()
autoSyncImageMutation
Arreyder Mutashoon

veih'n veear 2.5.0
trueDetects aghtyn src attributes jeh ooilley ny skeeallyn. Relevant tra t'eh ry-chleayney lesh React ny leabharlannyn elley.

Taitnyssagh trooid data-grizy- , new Gridzy() , setOptions() , Gridzy.setDefaultOptions()
autoRenderOnResize
Ath-mhean-arrey

veih'n veeal 2.6.0
trueDetects ymmyd jeh'n lead element. Relevant mychione y skeeal freggyrtagh. (Roish y veear 2.6.0 v'eh ry-chleaysh rish y vee-chraueeaght)

Taitnyssagh trooid data-grizy- , new Gridzy() , setOptions() , Gridzy.setDefaultOptions()

Toshiaght lesh laue

// initialize a new Gridzy instance
var gridzyInstance = new Gridzy(document.querySelector('.gridzy'), {
  spaceBetween: 10,
  layout: 'waterfall'
});

Screeu yn stayd

Roughly said, y coontid jeh initialize Gridzy.

gridzyInstance.destroy();
gridzyInstance = null;

Sync Lioar ny Leigh lesh laue

// after child elements (images) are added to or removed from the DOM.
gridzyInstance.syncChildList();

Sync un Element Leigh lesh laue

As cha nel eh feme, agh ayns caghlaaghyn ard-raad.

// after child elements (images) are added to the DOM and only one of them should be synced to Gridzy.
gridzyInstance.syncChild(childElement);

Sync ny h-earrooyn lesh laue

Tastey dy row y roshtyn useOptionAttributes ry true hoi ry-hoi.

// after data-gridzy- attributes have changed
gridzyInstance.syncAttributes();

Rendering Force

As cha nel feme er, agh my ta ooilley ny automatismyn currit magh

gridzyInstance.render();