
Working hard to work on
Jquery
and get some amazing every time,however the case is revert I got a simple gallery with category,every button you click gets the class
and match the class with the images in the gallery,the set of matched element get highlighted.So lets see at demo,HTML
The above pen,shows
HTML
of the gallery,- First create a outer wrapper of buttons as
class='buttons'
. - Then,each button will come under
span
,with a particularclass
,that will be same of the images it will highlight. - Then create a outer container of images that is
class='gallery'
. - After that add the images in it,make sure that each image have the same
class
of its respective button.,as mentioned in second point.
CSS
The major part in
CSS
is the opacity
of the image,the opacity
I've set is 0.3 so the unwanted images get lighter and I've done some customization in order to make it a bit pretty.Jquery
The
Jquery function
matches the button class with the images in the container and highlight the matched element.- First when a button is clicked,then the variable as
active
get theclass
of clicked button. - Then,according to a condition if the clicked button is already have the class='active' then remove it,else remove the
class='active'
from all the buttons and add thisclass
in the clicked button. - Then the last function applies on every image,that is if the image class matched with the var active,then make it
opacity
to 1 or else make it0.3
.
Post A Comment:
0 comments: