Kua whakamaori aunoatia te paetukutuku. Mena kaore i te marama tetahi mea, tena koa tirohia nga tuhinga Ingarihi.
Whakamahi Taketake
Tukuna nga konae Gridzy ki to tuumau ka taapiri atu ki to paetukutuku (i te nuinga o te waa kei te waahanga upoko):
<link rel="stylesheet" href="gridzy/gridzy.min.css" />
<script src="gridzy/gridzy.min.js"></script>Tāpirihia te waehere HTML (kei hea i te wahanga tinana):
<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>Koia tena! He tauira tino mahi tera. Kaore e hiahiatia he arawhitinga taapiri.
Whirihoranga
Ko te huarahi ngawari ki te whirihora i a Gridzy ko te whakamahi noa i nga huanga HTML. Me tohu tuatahi koe i nga ingoa whiringa me data-gridzy- . Na, ki te tautuhi i te waahi spaceBetween , taapiri noa i te huanga 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ōwhiringa Matua
Justified Kōwhiringa Tahora
Waterfall Kōwhiringa Tahora
Ētahi atu Kōwhiringa Arā Atu Anō
Mo etahi atu whiringa matatau, tirohia te API .
HTML Semantic
Ko te hanganga HTML ngawari o Gridzy ko tenei:
<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>Heoi, he tino ngawari a Gridzy ka taea e koe te whakamahi tata ki etahi atu hanganga HTML. He iti noa nga waahanga hei whakaaro:
- Ko ia tamaiti o te huānga ipu e whakaatu ana i tetahi mea kei te matiti.
- Ko te huānga ipu me ana tamariki he momo tohu, penei i
ulmeli(whakaaro noa ki te tautuhi i nga taunoa o te tirotiro). - Mena karekau te huānga
imgi te tamaiti tika, me te akomangagridzyImage.
Na he hanganga HTML mahi ano tenei:
<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>Ina koa ka hiahia koe ki te taapiri i nga tapanga, me whai hanganga HTML matatau koe. Hei ako atu mo tena, tirohia nga Tapanga me nga Hiako .
Tapanga me nga Hiako
Mena kei te hiahia koe ki te taapiri i nga tapanga ki to taiwhanga, me tautuhi koe i te ahua. Na reira, kei te waatea etahi hiako kua tohua. Ko ia kiri he konae CSS. Me taapiri koe i tenei konae hei taapiri atu ki nga konae Gridzy matua (i te nuinga o te waa kei te waahanga upoko):
<link rel="stylesheet" href="gridzy/skins/gridzySkinClassic/style.min.css" />I tua atu ka hiahia koe ki te hanganga HTML matatau:
<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>Mena kei te whakaaro koe mo te hanganga HTML, tirohia te Semantic HTML .
Mo te tapanga ka taea e koe te whakamahi i tetahi momo tohu, me whakarite kei a ia te karaehe gridzyCaption . Ko te huānga img me te class gridzyImage .
Ko te tauira o runga ake e whakaatu ana i te kiri gridzySkinClassic . Hei whakamahi i tetahi atu, whakakapi noa i te ingoa kiri ki tetahi o enei:
Nga Hiako kei roto
| Nga karaehe e waatea ana | |
|---|---|
| gridzySkinBlank he timatanga pai mo te hanga kiri ake arokite ora | gridzySkinBlank |
| gridzySkinClassic arokite ora | gridzySkinClassic(DEPRECATED mai i te putanga 2.6.0) |
| gridzySkinFullOverlay arokite ora | gridzySkinFullOverlay(DEPRECATED mai i te putanga 2.6.0) |
| gridzySkinLift arokite ora | gridzySkinLift(DEPRECATED mai i te putanga 2.6.0) |
| gridzySkinMagnifier kaore i whakauruhia nga mahi topa arokite ora | gridzySkinMagnifier(DEPRECATED mai i te putanga 2.6.0) |
Ko nga kiri katoa o runga ake nei he konae CSS anake, engari tera ano etahi hiako ka hiahiatia he konae JavaScript:
<link rel="stylesheet" href="gridzy/skins/gridzySkinBlur/style.min.css" />
<script src="gridzy/skins/gridzySkinBlur/script.min.js"></script>| Nga karaehe e waatea ana | |
|---|---|
| gridzySkinBlur e kore e mahi i roto i te IE arokite ora | gridzySkinBlur(DEPRECATED mai i te putanga 2.6.0) |
| gridzySkinCard arokite ora | gridzySkinCard(DEPRECATED mai i te putanga 2.6.0) |
Kōwhiringa kiri
Mai i te putanga 2.6.0 he Kōwhiringa hei whirihora i nga hiako kua oti te hanga. I runga i te kiri motuhake ka taea e koe te whakarite i te tae papamuri, te tae kuputuhi me te atarangi kuputuhi. Me whakamahi noa koe i nga ahuatanga ritenga CSS ka kite koe i konei:
<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>Tirohia nga taurangi tautoko me nga uara taunoa mo ia kiri i konei:
gridzySkinClassic
| Taurangi | Uara Taunoa | Nga korero |
|---|---|---|
--background | rgba(0, 0, 0, .7) | ka taea tetahi uara papamuri CSS |
--color | rgb(255, 255, 255) | taea tetahi uara tae CSS |
--text-shadow | none | ka taea tetahi uara kupu-atarangi CSS |
gridzySkinFullOverlay
| Taurangi | Uara Taunoa | Nga korero |
|---|---|---|
--background | rgba(0, 0, 0, .7) | ka taea tetahi uara papamuri CSS |
--color | rgb(255, 255, 255) | taea tetahi uara tae CSS |
--text-shadow | none | ka taea tetahi uara kupu-atarangi CSS |
gridzySkinLift
| Taurangi | Uara Taunoa | Nga korero |
|---|---|---|
--background | rgba(0, 0, 0, .7) | ka taea tetahi uara papamuri CSS |
--color | rgb(255, 255, 255) | taea tetahi uara tae CSS |
--text-shadow | 0 0 10px rgb(0, 0, 0), 0 0 20px rgb(0, 0, 0), 0 0 30px rgb(0, 0, 0) | ka taea tetahi uara kupu-atarangi CSS |
gridzySkinMagnifier
| Taurangi | Uara Taunoa | Nga korero |
|---|---|---|
--background | rgba(0, 0, 0, .7) | ka taea tetahi uara papamuri CSS |
--color | rgb(255, 255, 255) | taea tetahi uara tae CSS |
Kaore tenei kiri e tautoko --text-shadow
gridzySkinBlur
| Taurangi | Uara Taunoa | Nga korero |
|---|---|---|
--background | rgba(0, 0, 0, .7) | ka taea tetahi uara papamuri CSS |
--color | rgb(255, 255, 255) | taea tetahi uara tae CSS |
--text-shadow | 0 0 10px rgb(0, 0, 0) | ka taea tetahi uara kupu-atarangi CSS |
gridzySkinCard
| Taurangi | Uara Taunoa | Nga korero |
|---|---|---|
--background | rgba(0, 0, 0, 1) | ka taea tetahi uara papamuri CSS |
--color | rgb(255, 255, 255) | taea tetahi uara tae CSS |
--text-shadow | none | ka taea tetahi uara kupu-atarangi CSS |
Ko nga hiako kua tautuhia kee ka tautoko i nga tapanga kupu ngawari. Ka taea e koe te hanga i a koe ake me nga hiako uaua ake. Tena koa tirohia te Style Gridzy .
Kāhua Mātiti
Mena karekau he kiri kua tautuhia e tau ki o hiahia, ka taea e koe te hanga i a koe ake.
Ko te huarahi ngawari ko te kape tuatahi i te kiri o mua ka urutau ki o hiahia. Ko te gridzySkinBlank kiri kua tautuhia i mua ka whakarato i te turanga pai me nga tuhinga pai i roto i te konae CSS:
/** 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;
}I roto i te kōnae CSS ka kitea e koe nga akomanga gridzySkinBlank , gridzyImage me gridzyCaption . Karekau a Gridzy e hiahia ki enei karaehe. Ka whakamahia noa mo te whakaahua, na ka taea e koe te tango, te whakaingoa ano ranei ki te pai koe.
I tua atu ka kitea e koe te CSS class gridzyItem . Ka tautuhi aunoa a Gridzy i tenei akomanga ki nga tamariki tika katoa o te huānga ipu matua. Na, ka taea e koe te whakamahi i tenei karaehe ki te tarai i nga taonga o to taiwhanga.
Hinengaro Nga Mea Nui
- Ko nga ihirangi o nga taonga me tino whakautu. Whakaarohia ka tino huri te rahi o te huānga. Whakamahia nga uara ōrau hei utu i nga uara pika. A ka titiro ki te kōwhiringa tahora Gridzy
autoFontSize, e herea ana te momotuhi-rahi ki te rahi o te pouaka taonga. - Ko ia tuemi me whai ahua pai te ahua o te waahanga. Ko te ahua ōwehenga o te tūemi e kore e huri, ā, me tātai i te mātiti. Na, ki te kore e kitea aunoatia te ahua ōwehenga o te tuemi, tautuhia-a-ringa (hei tauira ma te css).
I etahi wa, he ngawari ake pea te whakaahua i nga ihirangi o nga mea i mua i te tiimata o Gridzy. Tango noa te gridzy akomanga, te konae javascript Gridzy mo te wa poto mo tenei.
Koia tena! Ko te mea anake hei hanga i to kiri ake. Ko te nuinga o nga hiako kua tautuhia ake kaore e nui ake te whakamahi i tenei.
Engari tera pea ka nui ake mena ka pai koe…
Nga Hiako Ake
He maha ake nga akomanga CSS ka whakamahia e Gridzy i gridzyItem anake. Ko te nuinga ka tautuhi aunoa ka taea e koe te whakamahi mo te whakaahua.
Nga Karaehe Ipu Matua
| Ingoa Karaehe | Whakaahuatanga |
|---|---|
gridzyki te tautuhi ā-ringa | Ka kimi aunoa a Gridzy i nga huānga me tenei akomanga ka arawhiti. |
gridzyAnimated | Ka tautuhi aunoa mena he true te kowhiringa animate . Mēnā ka whakaritea ā-ringatia tēnei karaehe, ka true aunoa te kōwhiringa animate (haunga mena kua tautuhia ki false ). |
Nga Karaehe Tuemi
| Ingoa Karaehe | Whakaahuatanga |
|---|---|
gridzyItem | Ka tautuhia ina timata te tuemi i te tukanga arawhiti. E kore rawa e tangohia. |
gridzyItemInitializing | Ka tautuhia ina timata te tuemi i te tukanga arawhiti. Ka whakakapihia e te gridzyItemReady i te wa e tino arawhiti ana te taonga. Ehara i te mea kua utaina katoa nga whakaahua (tirohia gridzyItemLoading ), engari kua reri te taonga kia kitea. |
gridzyItemReady | Ka whakakapi i gridzyItemInitializing i te wa e tino arawhiti ana te mea. E kore rawa e tangohia. Ehara i te mea kua utaina katoa nga whakaahua (tirohia gridzyItemComplete ), engari kua reri te taonga kia kitea. |
gridzyItemLoading | Ka tautuhia ina timata te tuemi i te tukanga arawhiti. Ka whakakapihia e te gridzyItemComplete ina oti nga whakaahua kei roto (ko te tikanga kotahi anake) ka utaina katoa. |
gridzyItemComplete | Ka whakakapi i gridzyItemLoading ina ka utaina katoa nga whakaahua kei roto (ko te tikanga kotahi anake). E kore rawa e tangohia. |
gridzyItemInitialToVisible | Ka tautuhia ina timata te puta mai o te taonga i te wa tuatahi. Ka tangohia ina ka tino kitea te taonga. |
gridzyItemVisible | Ka tautuhia ina kitea rawatia te taonga. Ka tangohia ina timata te ngaro o te taonga. |
gridzyItemVisibleToHidden | Ka tautuhia ina timata te ngaro o te taonga. Ka tangohia ina kua huna katoatia te taonga. |
gridzyItemHidden | Ka whakaturia ina kua huna katoatia te taonga. Ka tangohia i te wa ka timata te puta mai o te taonga. |
gridzyItemHiddenToVisible | Ka tautuhia ina timata te puta mai o te taonga (haunga te puta tuatahi - tirohia te class gridzyItemInitialToVisible ). Ka tangohia ina ka tino kitea te taonga. |
gridzyItemVisibleToVisible | Ka tautuhia ina huri tetahi mea i roto i te matiti, engari ko te mea tonu i kitea, ka kitea tonu. Ka tangohia ina oti te huringa huringa. |
Ma te taunoa ko te tohu tukanga me nga pakiwaituhi mo te puta me te ngaro o nga whakaahua kua tautuhia e te konae CSS matua Gridzy.
Ma enei karaehe CSS kua whakahuahia i runga ake nei ka taea e koe te tarai i to tohu tohu me nga mahi pakiwaituhi. Kia maia ki te titiro ki te konae CSS matua a Gridzy, kia mohio ai koe he aha te mea ka whakakorehia e koe. Kaore he mataku, he pai te tuhi i nga mea katoa ki reira.
Arotau Uta
Mena ka whakamahi koe i nga whakaahua maha, he pai pea te awhina i a Gridzy ki te hanga tere ake i te matiti.
Aukati i te peke Whakaahua
Me tino hiahia a Gridzy ki te ahua ōwehenga o nga whakaahua katoa hei tatau i te matiti. Ko enei mea ka puta he huānga pekepeke mena kua reri etahi whakaahua ko etahi kaore. Ko te nui ake o nga whakaahua, ka nui ake te hoha o tenei paanga.
Hei aukati i tenei whanonga, tautuhi noa i nga huanga width me height mo nga huānga img katoa. He mea nui ki te whakarite i nga uara tika mo ia ahua takitahi, ki te kore ka hee nga whakaahua. Ko nga uara tika ko te whanui taketake me te teitei o ia ahua:
<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>I muri mai ka taea e Gridzy te tatau i te matiti me te kore e mohio ki nga rahi o nga whakaahua.
Uta mangere
Hei uta i nga whakaahua anake kei roto i te tauranga tiro, whaia enei mahi:
- Whakauruhia nga huanga
widthmeheightpera i te whakaahuatanga i runga ake nei (kia mohio ki te whakamahi i nga uara tika) - Whakakapihia nga huanga
srckatoa medata-gridzylazysrce whakaatuhia ana i raro nei (mehemea kei a koe ano nga huangasrcset, whakakapihia kidata-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>Whai muri i enei mahi ka utaina nga whakaahua ina tata ana ki roto ranei i te tauranga tirohanga.
Tohu Tukatuka
Ko te tohu tukanga ko te ata pakiwaituhi iti ka puta i te wa e utaina ana te ahua. Mena ka whakamahi koe i nga tapanga me nga hiako , ka whakaatuhia aunoatia te tohu tukanga. Mena ka hiahia koe ki etahi whakatikatika:
- Hoatu ia huānga
imgki roto i te huāngadiv
(ki tetahi atu huānga ranei - tirohia te HTML tohutoro mo etahi atu) - Tāpirihia te class
gridzyImageki ia huāngaimg
<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>I muri i tera me kite koe i nga tohu o te tukanga mena ka roa nga whakaahua ki te uta.
Tātari
Ko nga whiriwhiringa i Gridzy he tino ngawari engari he kaha. Ahakoa he aha te momo tātari e hiahia ana koe, tera pea ka taea. Ko nga mea katoa e hiahia ana koe, he iti CSS me etahi huānga puka HTML ...
Anei he tauira mahi:
<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>Kia Hangaia e Taaahi Ma te Mahinga
1. Tuatahi ka hiahia matou ki te hanganga HTML o Gridzy me te tautuhi i nga ingoa akomanga mo nga taonga taiwhanga katoa kia taea ai e matou te tarai i muri mai.
<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>I tenei tauira ka whakamahi kotahi noa te karaehe mo ia huānga. Engari ka taea hoki e koe te whakarite i nga karaehe maha mo te huānga kotahi, mena ka kitea taua huānga ma nga whiriwhiringa maha.
2. Na ka taapirihia e matou etahi paatene e taea ai e matou te whakarereke i nga whiriwhiringa katahi
<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>Engari i nga patene, ka taea ano e koe te whakamahi i etahi atu huānga ahua penei i nga pouakataki, patene reo irirangi, tohu mara me era atu.
Ka taea e koe te kite, ko nga uara o nga paatene he kaikowhiri CSS noa. Ka mutu ta maatau, ma te paatene i te paatene penei ka whakaatu nga whakaahua e rite ana ki taua kaiwhiriwhiri CSS. Ma te hangarau ka tautuhi noa te whiringa filter ki tenei uara.
Ka taea hoki e koe te whakamahi i nga whiriwhiringa uaua ake. Hei tauira :not(.animals) ka mahi ano, me .animals.people me .animals, .people .
3. Ka mutu, ka whakauruhia e matou nga paatene ki roto i te ipu div ka herea ki te taiwhanga Gridzy, ma te tautuhi i te whiriwhiringa 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>Ka taea e koe te kite, ka whakamahia ano e matou he kaikowhiri CSS mo te whiriwhiringa filterControls . Ko te ipu div me te huanga id e mahi ana kia ngawari ake nga paatene ki te kowhiri ma taua kaiwhiriwhiri CSS.
Koia tena!
Ki te hiahia koe ki te otinga JavaScript, tirohia te API .
API
Ahakoa kei a Gridzy tana ake API, ka taea te nuinga o nga mahi me te kore, ma te whakamahi noa i te DOM. Ka kite a Gridzy ka whakatika i te matiti. Engari tera ano tetahi API tino kaha ...
Te whakahaere i te DOM
Mo nga raweketanga Tauira Ahanoa Tuhinga (DOM) ka hiahia tuatahi tatou ki te huānga ipu:
// get the container element
var gridzyElement = document.querySelector('.gridzy');Tāpirihia nga Whakaahua
He mea nui ki te hanga me te whakaki i te huānga tamaiti hou i mua i to taapiri atu ki te huānga ipu. Ki te kore e taea e Gridzy te kite i nga rahi tika.
// 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);Tango Whakaahua
// remove the first image
gridzyElement.removeChild(gridzyElement.firstElementChild);Huri Kōwhiringa
// 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');He korero ano mo te raweke i te DOM ka kitea e koe i nga tuhinga paetukutuku MDN . Kei te waatea ano he Whakataki ki te DOM .
API rangatira
Hei whakamahi i te API, me hiahia tuatahi ki te tauira Gridzy, e herea ana ki te huānga ipu Gridzy:
// get the Gridzy instance
var gridzyInstance = document.querySelector('.gridzy').gridzy;Tikina te Kōwhiringa
// get the value of a single option
var currentLayout = gridzyInstance.getOption('layout');Tikina nga Kōwhiringa Katoa
// get all option values as an object
var currentOptions = gridzyInstance.getOptions();Tautuhi Kōwhiringa
// set specific option values
gridzyInstance.setOptions({
spaceBetween: 10,
layout: 'waterfall'
});
// or reset options to their default values
gridzyInstance.setOptions({
spaceBetween: null,
layout: null
});Hoatu te Tātari
Ko te tono tātari he whakarite noa i te filter whiriwhiringa he kaikowhiri CSS whaimana:
// 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'
});Tāpiri Mahi Waea Whakahoki
DEPRECATED mai i te putanga 2.4.0
Whakamahia nga Takahanga hou me te ngawari ake. Tirohia te waahanga e whai ake nei mo nga taipitopito.
Kei te tautoko a Gridzy.js 2 i etahi whiringa mo nga mahi hokiwaea. Ka taea anake te whakarite ma te API rangatira, engari pera ano i etahi atu whiringa:
// 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.
}
});Whakamahia nga Takahanga
mai i te putanga 2.4.0
Ka taea e koe te whakamahi i nga kaupapa Gridzy kia rite ki nga kaupapa JavaScript o mua:
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.
});Ka puhia etahi huihuinga ki runga i te huānga ipu Gridzy me etahi atu takahanga ka panaia ki runga i nga huānga mea takitahi kei roto i te huānga ipu.
Ko nga takahanga i puhia ki te huānga ipu Gridzy:
Ka whakaratohia e event.target te huānga ipu Gridzy.
Ka whakaratohia e te event.detail.instance te tauira Gridzy.
Ko nga takahanga i puhia ki nga huānga tūemi:
Ka whakaratohia e event.target te huānga tūemi.
Ka whakaratohia e te event.detail.instance te tauira Gridzy.
API – Ao
He mahi motuhake mai i nga tauira Gridzy. No reira karekau e hiahia ki te tiki tauira i mua.
Tikina te Kōwhiringa Taunoa
// get the default value of a single option
var defaultLayout = Gridzy.getDefaultOption('layout');Tikina Nga Kōwhiringa Taunoa Katoa
// 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');Tautuhi Kōwhiringa Taunoa
Kaore tenei e tautuhi i nga whiringa o nga tauira Gridzy katoa kua arawhiti, engari ka tautuhia te putake mo nga waa hou. Heoi, mena ka tautuhia ano he whiringa o tetahi tauira o naianei ma te uara null , ka whakamahia e ia te uara taunoa hou.
// set default option values
Gridzy.setDefaultOptions({
spaceBetween: 10,
layout: 'waterfall'
});Ka taea e koe te whakamahi i tenei ki te whakarite i nga whiringa puta noa i te ao, mena ka karanga koe i mua i te reri a DOM. No reira kaore koe e hiahia ki te tautuhi i nga whiringa hei huanga.
Nga mahi aunoa
I te mea kei te kaha nga automatisms katoa o Gridzy.js 2, kaore he hiahia mo nga tikanga i raro nei. Engari ka taea te whakakore i nga miihini ki te whakamahi i a Gridzy i roto i nga tikanga tuku iho:
// 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
});Ko etahi o enei whiringa kaore e taea te tautuhi ma data-gridzy- huanga, ma te setOptions() ranei, na nga take arorau:
Arawhiti ā-ringa
// initialize a new Gridzy instance
var gridzyInstance = new Gridzy(document.querySelector('.gridzy'), {
spaceBetween: 10,
layout: 'waterfall'
});Whakangaromia te Instance
I kii te ahua, he rereke te tiimata o te Gridzy.
gridzyInstance.destroy();
gridzyInstance = null;Tukutahia te Rarangi Tamaiti
// after child elements (images) are added to or removed from the DOM.
gridzyInstance.syncChildList();Tukutahi A-ringa i te Huanga Tamariki Kotahi
I te nuinga o te waa kaore e hiahiatia, engari i nga keehi tino onge.
// after child elements (images) are added to the DOM and only one of them should be synced to Gridzy.
gridzyInstance.syncChild(childElement);Tukutahi Huanga A-ringa
Kia mahara ko te kōwhiringa useOptionAttributes me true mo tenei.
// after data-gridzy- attributes have changed
gridzyInstance.syncAttributes();Te Whakakaha
I te nuinga o te waa kaore e hiahiatia, ahakoa ka weto katoa nga mahi aunoa
gridzyInstance.render();