Ta'n 'website' er ny aittaghey dy h-automagh. Mannagh vel red erbee soilshaghey, cur-my-ner y documentation Bearlagh.
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
Justified Roghanyn skeeal
Waterfall Roghanyn skeeal
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
ulasli(ny smooinee er reset y browser). - Mannagh vel eiraght
imgny leigh direct hene, shegin da'n classgridzyImage.
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(ER CHEEILLEY veih'n veear 2.6.0) |
| gridzySkinFullOverlay Roish-akin beo | gridzySkinFullOverlay(ER CHEEILLEY veih'n veear 2.6.0) |
| gridzySkinLift Roish-akin beo | gridzySkinLift(ER CHEEILLEY veih'n veear 2.6.0) |
| gridzySkinMagnifier cha nel obbyr zoom er ny choyrt stiagh Roish-akin beo | gridzySkinMagnifier(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(ER CHEEILLEY veih'n veear 2.6.0) |
| gridzySkinCard Roish-akin beo | gridzySkinCard(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-chaghlaa | Lught ry-hoi | Fys |
|---|---|---|
--background | rgba(0, 0, 0, .7) | t'eh ceaut dagh ymmyd CSS |
--color | rgb(255, 255, 255) | t'eh ceaut dagh ymmyd CSS |
--text-shadow | none | t'eh ceaut dagh ard-valjagh text-shadow CSS |
gridzySkinFullOverlay
| Ard-chaghlaa | Lught ry-hoi | Fys |
|---|---|---|
--background | rgba(0, 0, 0, .7) | t'eh ceaut dagh ymmyd CSS |
--color | rgb(255, 255, 255) | t'eh ceaut dagh ymmyd CSS |
--text-shadow | none | t'eh ceaut dagh ard-valjagh text-shadow CSS |
gridzySkinLift
| Ard-chaghlaa | Lught ry-hoi | Fys |
|---|---|---|
--background | rgba(0, 0, 0, .7) | t'eh ceaut dagh ymmyd CSS |
--color | rgb(255, 255, 255) | t'eh ceaut dagh ymmyd CSS |
--text-shadow | 0 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-chaghlaa | Lught ry-hoi | Fys |
|---|---|---|
--background | rgba(0, 0, 0, .7) | t'eh ceaut dagh ymmyd CSS |
--color | rgb(255, 255, 255) | t'eh ceaut dagh ymmyd CSS |
Cha nel y crosh shoh cur tastey da --text-shadow
gridzySkinBlur
| Ard-chaghlaa | Lught ry-hoi | Fys |
|---|---|---|
--background | rgba(0, 0, 0, .7) | t'eh ceaut dagh ymmyd CSS |
--color | rgb(255, 255, 255) | t'eh ceaut dagh ymmyd CSS |
--text-shadow | 0 0 10px rgb(0, 0, 0) | t'eh ceaut dagh ard-valjagh text-shadow CSS |
gridzySkinCard
| Ard-chaghlaa | Lught ry-hoi | Fys |
|---|---|---|
--background | rgba(0, 0, 0, 1) | t'eh ceaut dagh ymmyd CSS |
--color | rgb(255, 255, 255) | t'eh ceaut dagh ymmyd CSS |
--text-shadow | none | t'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
- 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. - 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 Chlass | Coontey |
|---|---|
gridzydy reayll lesh laue | Gridzy t'eh glenney elementyn rish y chlass shoh as t'eh ymmyrkey ad. |
gridzyAnimated | T'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 Chlass | Coontey |
|---|---|
gridzyItem | T'eh er ny choyrt choud's ta'n obbyr toshiaght y phroses initializing. Cha bee eh er ny ghoaill ersooyl. |
gridzyItemInitializing | T'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. |
gridzyItemReady | Ta'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. |
gridzyItemLoading | T'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. |
gridzyItemComplete | Ta'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. |
gridzyItemInitialToVisible | T'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. |
gridzyItemVisible | T'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. |
gridzyItemVisibleToHidden | Bee eh set choud as t'eh toshiaght dy gholl ersooyl. T'eh er ny chur magh choud's ta'n red follit dy kiaralagh. |
gridzyItemHidden | T'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. |
gridzyItemHiddenToVisible | T'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. |
gridzyItemVisibleToVisible | T'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:
- Cur stiagh ymmyd
widthasheightmyr t'eh er ny screeu harrish (jean shiu shickyr dy uss ny luaghyn cooie) - Cur stiagh ooilley ny t'ayns
srcleshdata-gridzylazysrcmyr te er ny hoilshaghey (my ta t'aynssrcsetmyrgeddin, t'ad ry-cheilley leshdata-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:
- Cur gagh eiraght
imgayns eiraghtdiv
(ny ayns red erbee elley – cur-my-ner HTML semantic son ny smoo) - Cur rish y chlass
gridzyImageda gach eiraghtimg
<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.
}
});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:
event.target t'eh cur y ghraih Gridzy.
t'eh ry event.detail.instance akin 'sy Gridzy.
Tammyltaghyn er nyn skeaylley er eilynnyn:
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:
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();