Website eo emoj an make ukōte. Elañe ewor men eo ejjab alikar, jouj im lale jeje ko ilo kajin English.
Kōjerbal eo ebin
Likūt Gridzy file ko ñan server eo am im kobaik er ñan website eo am (ekkā ilo head section eo):
<link rel="stylesheet" href="gridzy/gridzy.min.css" />
<script src="gridzy/gridzy.min.js"></script>Kobaik HTML code eo (jabdewōt jikin ilo m̧ōttan eo):
<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>Eñin ej! Ej juon waanjonok eo elap an jerbal. Ejelok bar juon jinoin ej aikuj in kōmmane.
Kōllaajrak
Wāween eo em̧m̧an tata n̄an kōm̧m̧ane Gridzy ej, n̄an kōjerbal wōt HTML attribute ko. Kwoj aikuj wōt likit etan option ko ippāñ data-gridzy- . Innem, ñan kōmman spaceBetween option eo, baj kobaiktok attribute eo 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>Kālet ko relap
Justified Layout Options
Waterfall Layout Options
Elōñlok kālet ko relaplok
Ñan bar jet kālet ko relaplok, lale API eo.
Semantic HTML
HTML eo epidodo tata an Gridzy ej in:
<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>Ak, Gridzy ej lukkun maroñ in oktak im kwomaroñ kajerbal jabdrewot HTML structure ko jet. Ewōr wōt jejjo men ko ñan lemnok kaki:
- Kajjojo ajiri in container element eo ej jutak kin juon men ilo grid eo.
- Container element eo im ajiri ro nejin remaroñ jabdrewot kain tag, einwot
ulimli(lemnak in bar kōmman bwe en bar jerbal browser eo). - Elañe juon
imgelement ejjab juon direct child make, ej aikuj class eogridzyImage.
Innem men in ej bar juon HTML eo ej jerbal:
<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>Elaptata elañe kwoj kōnaan kobaik caption ko, kwoj aikuj juon HTML eo elap an emman. Ñan katak elaplok kake, lale Captions & Skins .
Caption & Skins
Elañe kwoj kōnaan kobaik caption ko ñan jikin pija eo am, kwoj aikuj in kwalok joñan an walok. Kin menin, jet kilin ko rej bed. Kajjojo skin ewōr juon an CSS file. Kwoj aikuj in kobaik file in ñan Gridzy file ko relap (ekkā ilo head section eo):
<link rel="stylesheet" href="gridzy/skins/gridzySkinClassic/style.min.css" />Bar juon kwoj aikuj juon HTML eo elap an emman:
<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>Elañe kwoj lemnok kin HTML structure eo, lale Semantic HTML .
Ñan caption eo kwomaroñ kōjerbal jabdewōt kain tag, baj lale bwe en wor kilaaj eo gridzyCaption . img element eo ej aikuj class eo gridzyImage .
Waanjonok eo ilōñ ej kwalok ñan yuk kilin gridzySkinClassic . Ñan kōjerbal bar juon, baj bōk jikin etan kilin kin juon ian men kein:
Kilin ko rej bed ie
| Kilaaj ko rej bed | |
|---|---|
| gridzySkinBlank juon jikin jino emman ñan kōmmane juon kilin make lale mokta | gridzySkinBlank |
| gridzySkinClassic lale mokta | gridzySkinClassic(DEPRECATED since version 2.6.0) |
| gridzySkinFullOverlay lale mokta | gridzySkinFullOverlay(DEPRECATED since version 2.6.0) |
| gridzySkinLift lale mokta | gridzySkinLift(DEPRECATED since version 2.6.0) |
| gridzySkinMagnifier jerbal in zoom ejjab bed ie lale mokta | gridzySkinMagnifier(DEPRECATED since version 2.6.0) |
Aolep skin ko ilōñ rej aikuj wōt juon CSS file, ak ewōr jet skin ko rej barāinwōt aikuj juon JavaScript file:
<link rel="stylesheet" href="gridzy/skins/gridzySkinBlur/style.min.css" />
<script src="gridzy/skins/gridzySkinBlur/script.min.js"></script>| Kilaaj ko rej bed | |
|---|---|
| gridzySkinBlur ejjab jerbal ilo IE lale mokta | gridzySkinBlur(DEPRECATED since version 2.6.0) |
| gridzySkinCard lale mokta | gridzySkinCard(DEPRECATED since version 2.6.0) |
Kālet ko ñan Kilin
Jen version 2.6.0 ewōr Option ko ñan kōmman skin ko. Ekkar ñan kilin eo kwomaroñ kōmmane color in background eo, color in text eo im text shadow eo. Kwoj aikuj in kōjerbal CSS ko einwot am maroñ loe ijin:
<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>Lale variable ko rej jipan im joñan ko ñan kajjojo kilin ijin:
gridzySkinClassic
| Oktak | Aorōk eo emōj | Kōmelele |
|---|---|---|
--background | rgba(0, 0, 0, .7) | kōtlok jabdrewot aorōk in CSS |
--color | rgb(255, 255, 255) | kōtlok jabdrewot CSS color color |
--text-shadow | none | kōtlok jabdewōt CSS text-shadow value |
gridzySkinFullOverlay
| Oktak | Aorōk eo emōj | Kōmelele |
|---|---|---|
--background | rgba(0, 0, 0, .7) | kōtlok jabdrewot aorōk in CSS |
--color | rgb(255, 255, 255) | kōtlok jabdrewot CSS color color |
--text-shadow | none | kōtlok jabdewōt CSS text-shadow value |
gridzySkinLift
| Oktak | Aorōk eo emōj | Kōmelele |
|---|---|---|
--background | rgba(0, 0, 0, .7) | kōtlok jabdrewot aorōk in CSS |
--color | rgb(255, 255, 255) | kōtlok jabdrewot CSS color color |
--text-shadow | 0 0 10px rgb(0, 0, 0), 0 0 20px rgb(0, 0, 0), 0 0 30px rgb(0, 0, 0) | kōtlok jabdewōt CSS text-shadow value |
gridzySkinMagnifier
| Oktak | Aorōk eo emōj | Kōmelele |
|---|---|---|
--background | rgba(0, 0, 0, .7) | kōtlok jabdrewot aorōk in CSS |
--color | rgb(255, 255, 255) | kōtlok jabdrewot CSS color color |
Kilin in ejjab jerbal --text-shadow
gridzySkinBlur
| Oktak | Aorōk eo emōj | Kōmelele |
|---|---|---|
--background | rgba(0, 0, 0, .7) | kōtlok jabdrewot aorōk in CSS |
--color | rgb(255, 255, 255) | kōtlok jabdrewot CSS color color |
--text-shadow | 0 0 10px rgb(0, 0, 0) | kōtlok jabdewōt CSS text-shadow value |
gridzySkinCard
| Oktak | Aorōk eo emōj | Kōmelele |
|---|---|---|
--background | rgba(0, 0, 0, 1) | kōtlok jabdrewot aorōk in CSS |
--color | rgb(255, 255, 255) | kōtlok jabdrewot CSS color color |
--text-shadow | none | kōtlok jabdewōt CSS text-shadow value |
Aolep skin ko kar kōmmani mokta rej rejetake wōt text caption ko repidodo. Kwomaroñ kōmmane kilin ko am make im elaplok air bin. Jouj im lale Style Gridzy .
Style Gridzy
Elañe ejelok kilin eo emōj kōmmane mokta ej ekkar ñan aikuj ko am, kwomaroñ kōmmane juon am make.
Wāween eo em̧m̧an tata ej n̄an m̧okta kōm̧m̧ane juon kilin eo em̧ōj an pād im kōm̧m̧ane n̄an aikuj ko am̧ make. Skin gridzySkinBlank eo emōj kōmmane mokta enaj kar letok juon pedped emman im barāinwōt juon jeje emman ilo CSS file eo:
/** 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;
}Ilo CSS file eo kwonaj loe kilaaj ko gridzySkinBlank , gridzyImage im gridzyCaption . Gridzy make ejjab aikuj kilaaj kein. Rej baj kōjerbali wōt ñan kōmman style im kin menin kwomaroñ jolok ak bar naetair elañe kwoj kōnaan.
Bar juon kwonaj loe CSS kilaaj eo gridzyItem . Gridzy ej kōmman kilaaj in ñan aolep ajiri ro an main container element eo. Innem, kwomaroñ kōjerbal kilaaj in ñan kōmman style in men ko ilo jikin pija eo am.
Lemnak kin men ko raorõk
- Men ko ilo men eo rej aikuj in lukkun jejjet. Lemnok bwe joñan men eo enaj oktak. Kōjerbal joñan percentage ko ijellokin joñan pixel ko. Im lale Gridzy layout option eo
autoFontSize, eo ej kobaik font-size eo ñan joñan item box eo. - Kajjojo men ej aikuj in wōr juon an joñan eo emman. Aspect ratio eo an men eo ejamin oktak im ej aikuj in kōmmane ñan kalōk grid eo. Innem elañe juon men ejjab make wōr juon an aspect ratio eo emman, kōmmane mokta jen peim (einwot ikijen css).
Ilo jet ien, emaron in bin ñan kōmman style in men ko ilo men ko mokta jen an Gridzy jinoe. Jolok wōt class gridzy eo ak Gridzy javascript file eo ñan jidik ien ñan men in.
Eñin ej! Men in ej men eo kwoj aikuji ñan kalek kilin am make. Enañin aolep kilin ko kar kōmmani rejjab kajerbal elaplok jen menin.
Ak emaron wor bar jet elañe kwoj kōnaan ...
Advanced Skins
Gridzy ej kōjerbal elaplok CSS class ko jen gridzyItem wōt. Elōñ iaer renaj make kōmmane im kwomaroñ kōjerbali ñan kōmman style bareinwõt.
Main Container Classes
| Etan kilaaj eo | Tibdikin melele |
|---|---|
gridzyñan kōmmane make | Gridzy ej make loe men ko ilo kilaaj in im jinoe. |
gridzyAnimated | Enaj make kōmmane elañe option animate ej true . Elañe kilaaj in ej kōmmane make, option eo animate enaj make walok true (elaptata elañe emoj kōmmane ñan false ). |
Item Classes
| Etan kilaaj eo | Tibdikin melele |
|---|---|
gridzyItem | Enaj kōmmane ilo ien eo wōt men eo ej jinoe jerbal in jinoe. Ejamin maroñ in jolok. |
gridzyItemInitializing | Enaj kōmmane ilo ien eo wōt men eo ej jinoe jerbal in jinoe. Enaj bōk jikin kin gridzyItemReady ñe men eo ej dedelok an jinoe. Ejjab melelen bwe pija ko rej lukkun obrak (lale gridzyItemLoading ), ak men eo ej pojak in walok. |
gridzyItemReady | Enaj bōk jikin gridzyItemInitializing ilo ien eo emoj an men eo jinoe. Ejamin maroñ in jolok. Ejjab melelen bwe pija ko rej lukkun obrak (lale gridzyItemComplete ), ak men eo ej pojak in walok. |
gridzyItemLoading | Enaj kōmmane ilo ien eo wōt men eo ej jinoe jerbal in jinoe. Enaj bōk jikin kin gridzyItemComplete ñe pija ko rej bed ie (ekkā an juon wōt) emōj aer obrak. |
gridzyItemComplete | Enaj bōk jikin gridzyItemLoading ñe pija ko rej bed ie (ekkā an juon wōt) emōj aer obrak. Ejamin maroñ in jolok. |
gridzyItemInitialToVisible | Enaj kōmmane ilo ien eo wōt men eo ej jino walok ilo ien eo moktata. Enaj jolok ñe men eo ej alikar. |
gridzyItemVisible | Enaj kōmmane ilo ien eo wōt men eo ej alikar. Enaj jolok ñe men eo ej jino jako. |
gridzyItemVisibleToHidden | Enaj kōmmane ilo ien eo wōt men eo ej jino jako. Enaj jolok ñe men eo ej lukkun tilekek. |
gridzyItemHidden | Enaj kōmmane ilo ien eo emoj an men eo tilekek. Enaj jolok ñe men eo ej jino walok. |
gridzyItemHiddenToVisible | Enaj kōmmane ilo ien eo wōt men eo ej jino walok (ijjab walok ilo ien eo moktata – lale kilaaj eo gridzyItemInitialToVisible ). Enaj jolok ñe men eo ej alikar. |
gridzyItemVisibleToVisible | Enaj kōmmane ilo ien eo wōt ewōr juon men ilo grid eo ej oktak, ak men eo make ekar im enaj walok wōt. Enaj jolok ilo ien eo emoj an dedelok pija in oktak eo. |
Ilo an jejjet, menin kwalok kin jerbal eo im pija ko rej walok im jako rej bed ilo Gridzy main CSS file eo.
Ilo CSS kilaaj kein kar kwalok kaki ilōñ kwomaroñ kōmmane am make process indicator im animation ko. Lale ilo Gridzy main CSS file eo, ñan melele ta eo kwoj aikuj in kōmmane. Ejelok mijak, aolep men ko rej lukkun jeje ie.
Kōmman bwe en emmanlok an load
Elañe kwoj kajerbal elōn pija ko, emaron juon lemnok emman ñan jibañ Gridzy kalōk grid eo ilo mõkaj.
Bōbrae pija ko rej ettōr
Gridzy ej lukkun aikuj joñan aspect ratio in aolep pija ko ñan an maroñ in kōllaajrake grid eo. Men kein rej walok ilo men ko rej walok elañe jet pija ko rej pojak im jet rejjab. Elaplok an lõñ pija ko, enaj laplok an kainebataik men in.
Ñan bōbrae an walok men in, baj likit wōt width im height attributes ñan aolep img element ko. Ej aorōk ñan kōmman joñan ko rejimwe ñan kajjojo pija, elañe jab pija ko renaj kar jab jimwe. joñan ko rejimwe rej joñan depakpak im utiej in pija eo:
<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>Tokālik Gridzy emaron in kalōk grid eo ilo ien eo wot ilo an jab aikuj in jelā joñan joñan pija ko.
Lazy Loading
Ñan bōk wōt pija ko rej bed ilo viewport eo ej walok, baj lor wāween kein:
- Likūt
widthimheightāinwōt kar kōmeļeļeiki ilōn̄ (lale bwe kwon kōjerbal jon̄an ko rejim̧we) - Ukōt aolep
srcattribute ko kindata-gridzylazysrceinwot an walok iumin (elañe ewor amsrcsetattribute ko bareinwõt, ukõt ir kindata-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>Elikin step kein pija ko renaj load ilo ien eo rej bed iturin ak ilowaan viewport eo.
Kakōlkōl in jerbal
Menin kwalok kin jerbal eo ej juon icon edik eo ej walok ilo ien eo ej walok pija eo. Elañe kwoj kajerbal caption ko im kilin ko , kein kalikar jerbal eo enaj walok make. Elañe jaab kwoj aikuj jet oktak ko:
- Likūt kajjojo
imgelement ilo juondivelement
(ak ñan jabdrewot men ko jet – lale semantic HTML ñan bar jet) - Kobaik kilaaj eo
gridzyImageñan kajjojoimgelement
<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>Elikin menin kwoj aikuj loe kein kalikar ko kin jerbal eo elañe pija ko rej bōk ien ñan air load.
Filter ko
Filter ko ilo Gridzy rej lukkun pidodo ak rekajur. Jekdon ta kain filter eo kwoj aikuji, elap an maroñ in walok. Men eo kwoj aikuji ej, jidik CSS im jet HTML form elements ...
Enin ej juon waanjonok eo emman:
<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>Jen kalek e juon bun̄tōn kōn bun̄tōn
1. Mokta jej aikuj HTML structure eo an Gridzy im likit etan kilaaj ko ñan aolep men ko ilo gallery eo bwe jen maroñ in filter ir tokelik
<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>Ilo waanjoñak in jej kōjerbal wōt juon kilaaj ñan kajjojo element. Ak kwomaroñ barāinwōt kōmman elōn kilaaj ko ñan juon wōt men, elañe men eo ej aikuj in maroñ in loe ikijen elōn filter ko.
2. Innem jej kobaik jet button ko me jemaroñ ukōt filter ko innem
<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>Ijellokin button ko, kwomaroñ barāinwōt kōjerbal form element ko jet einwot checkbox ko, radio button ko, select field ko im ko jet.
Einwot am maroñ loe, joñan ko an button ko rej CSS selector ko. Ilo ien eo jej kadedelok, juon click ion kain button rot in enaj kwalok pija ko rej ekkar ñan CSS selector eo. Ilo mol ej baj likit filter eo ñan joñan in.
Kwomaroñ barāinwōt kōjerbal selector ko rebinlok. N̄an waanjon̄ak :not(.animals) enaaj kar jerbal barāinwōt, barāinwōt .animals.people im .animals, .people .
3. Āliktata, jej likit button ko ilo juon div container im likiti ñan Gridzy gallery eo, ilo ad likit filterControls option eo:
<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>Einwot am maroñ loe, jej barāinwōt kōjerbal juon CSS selector ñan filterControls option eo. div container eo ippān id attribute eo ej jerbal wōt n̄an kōm̧m̧an bwe button ko ren pidodo aer kālet kōn CSS selector eo.
Eñin ej!
Elañe kwoj kōnaan juon JavaScript solution, lale API eo.
API
Meñe Gridzy ewōr an make API, elaptata men ko remaroñ kōmmane ilo ejelok, ilo ad baj kōjerbal DOM eo. Gridzy enaj loe im kōmman oktak ñan grid eo. Ak ebar wor juon API eo elap an kajoor …
Kōjerbal DOM eo
Ñan aolep Document Object Model (DOM) kōmman ko jej aikuji container element eo:
// get the container element
var gridzyElement = document.querySelector('.gridzy');Kobaik pija ko
Ej aorōk bwe kwon lukkun kalek im kobrak child element eo ekãl mokta jen am kobaik e ñan container element eo. Elañe jaab Gridzy ejjab maroñ in kile joñan ko rejimwe.
// 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);Jolok pija ko
// remove the first image
gridzyElement.removeChild(gridzyElement.firstElementChild);Ukōt kālet ko
// 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');Elaplok kin kōjerbal DOM eo kwomaroñ loe ilo MDN web docs . Ebar wor juon jinoin ñan DOM eo ej bed.
Proprietary API
Ñan kōjerbal API eo, jej aikuji Gridzy instance eo, eo ej bind ñan Gridzy container element eo:
// get the Gridzy instance
var gridzyInstance = document.querySelector('.gridzy').gridzy;Bōk kālet
// get the value of a single option
var currentLayout = gridzyInstance.getOption('layout');Bōk ao kālet ko
// get all option values as an object
var currentOptions = gridzyInstance.getOptions();Kōmman kālet ko
// set specific option values
gridzyInstance.setOptions({
spaceBetween: 10,
layout: 'waterfall'
});
// or reset options to their default values
gridzyInstance.setOptions({
spaceBetween: null,
layout: null
});Kōjerbal Filter
Kōjerbal juon filter ej baj kōmman option filter eo emaron jabdrewot CSS selector eo emman:
// 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'
});Kobaik Callback Functions
EJJOK jen version 2.4.0
Kōjerbal Event ko rekāāl im repidodoļo̧k. Lale mōttan eo tok juon ñan melele ko.
Gridzy.js 2 ej jipan jet kālet ko ñan callback function ko. Remaroñ in kōmmane wōt ikijen API eo an make, ak einwot kālet ko jet:
// 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.
}
});Kōjerbal Men ko rej walok
jen version 2.4.0
Kwomaroñ kōjerbal Gridzy event ko einwot JavaScript event ko jet:
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.
});Jet men ko rej walok ilo Gridzy container element eo im jet men ko rej walok ilo item ko kajjojo ilowaan container element eo.
Men ko rej walok ilo Gridzy container element eo:
event.target ej letok Gridzy container element eo.
event.detail.instance ej letok Gridzy instance eo.
Men ko rej walok ilo men ko:
event.target ej letok men ko rejejjet.
event.detail.instance ej letok Gridzy instance eo.
API – Global
Ewōr jet jerbal ko rejjab jerbal jen Gridzy. Innem jejjab aikuj in bōk juon waanjonok mokta.
Bōk Default Option
// get the default value of a single option
var defaultLayout = Gridzy.getDefaultOption('layout');Bōk ao kālet ko rejejjet
// 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');Kōmman Default Option ko
Menin ejjab kōmman kālet ko an aolep Gridzy instance ko emoj aer jinoe, ak ej kwalok unin instance ko rekãl. Ak, elañe juon option in juon instance eo ej bed enaj kar bar jeblak ikijen value eo null , enaj kar kajerbal value eo ekãl.
// set default option values
Gridzy.setDefaultOptions({
spaceBetween: 10,
layout: 'waterfall'
});Kwomaroñ kōjerbale men in ñan kōmman kālet ko ibelakin lal, elañe kwoj call e mokta jen an DOM pojak. Innem kwojjab aikuj in bar likit kālet ko einwot kadkad ko.
Automatisms
Ijo ien eo aolep automatism ko an Gridzy.js 2 rej jerbal, ejelok aikuj in kōjerbal wāween kein. Ak automatism ko remaroñ in bōjrak ñan kōjerbal Gridzy ilo juon wewein eo elaplok an etto:
// 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
});Jet ian men kein rejjab maroñ in kōmmane ikijen data-gridzy- attributes ak ikijen setOptions() , kin un ko rejimwe:
Jino ilo peim
// initialize a new Gridzy instance
var gridzyInstance = new Gridzy(document.querySelector('.gridzy'), {
spaceBetween: 10,
layout: 'waterfall'
});Kokkure Instance eo
Ilo mol, oktak in jinoin Gridzy.
gridzyInstance.destroy();
gridzyInstance = null;Kōmman bwe en wor laajrak in ajiri ro ilo peim
// after child elements (images) are added to or removed from the DOM.
gridzyInstance.syncChildList();Kōmmane juon single Child Element ilo peim
Ekkā an jab aikuj, ijellokin wōt ilo jekjek ko relukkuun dik.
// after child elements (images) are added to the DOM and only one of them should be synced to Gridzy.
gridzyInstance.syncChild(childElement);Sync Attributes Manually
Lale bwe useOptionAttributes ej aikuj in true ñan men in.
// after data-gridzy- attributes have changed
gridzyInstance.syncAttributes();Force Rendering
Ekkā an jab aikuj, meñe aolep automatism ko rej bōjrak
gridzyInstance.render();