Last active
March 6, 2019 15:18
-
-
Save moxdev/772b967b033d67648b6d1acf178e2078 to your computer and use it in GitHub Desktop.
Photo Gallery with Lightbox ACF #acf #wp #jsLibrary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* IMAGE LIGHTBOX SELECTOR */ | |
#imagelightbox { | |
cursor: pointer; | |
position: fixed; | |
z-index: 10000; | |
top: 50%; | |
touch-action: none; | |
} | |
.imagelightbox-open { | |
user-select: none; | |
overflow: hidden; | |
} | |
/* WITH OVERLAY */ | |
.imagelightbox-overlay { | |
background-color: rgba(255, 255, 255, .95); | |
position: fixed; | |
z-index: 9998; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
} | |
/* WITH ARROWS */ | |
.imagelightbox-arrow { | |
// display: none; | |
position: fixed; | |
z-index: 10001; | |
top: 50%; | |
font-size: 1rem; | |
border: none; | |
border-radius: 50%; | |
width: 4em; | |
/* 53.3 */ | |
height: 4em; | |
/* 53.3 */ | |
background: transparent; | |
vertical-align: middle; | |
padding: 0; | |
margin-top: -3.75em; | |
/* 60 */ | |
cursor: pointer; | |
box-shadow: none; | |
&:hover, | |
&:active, | |
&:focus { | |
background: $color__brand-2; | |
} | |
} | |
.imagelightbox-arrow-left { | |
left: 2.5em; | |
/* 40 */ | |
} | |
.imagelightbox-arrow-right { | |
right: 2.5em; | |
/* 40 */ | |
} | |
.imagelightbox-arrow:before { | |
width: 0; | |
height: 0; | |
border: 1em solid transparent; | |
content: ''; | |
display: inline-block; | |
margin-bottom: -7%; | |
} | |
.imagelightbox-arrow-left:before { | |
border-left: none; | |
border-right-color: $color__brand-1; | |
margin-left: -0.35em; | |
} | |
.imagelightbox-arrow-right:before { | |
border-right: none; | |
border-left-color: $color__brand-1; | |
margin-left: 0.2em; | |
} | |
/* WITH ACTIVITY INDICATION */ | |
.imagelightbox-loading, | |
.imagelightbox-loading div { | |
border-radius: 9999px; | |
} | |
.imagelightbox-loading { | |
width: 40px; | |
height: 40px; | |
border-radius: 50%; | |
background: transparent; | |
position: fixed; | |
left: 50%; | |
top: 50%; | |
margin: -20px 0 0 -20px; | |
z-index: 9999; | |
border-top: 6px solid $color__brand-1; | |
border-right: 6px solid $color__brand-1; | |
border-bottom: 6px solid $color__brand-2; | |
border-left: 6px solid $color__brand-2; | |
animation: loading 1.2s infinite linear; | |
} | |
.imagelightbox-loading div { | |
width: 1.3em; | |
height: 1.3em; | |
background-color: #fff; | |
animation: imagelightbox-loading .5s ease infinite; | |
} | |
@keyframes imagelightbox-loading { | |
from { | |
opacity: .5; | |
transform: scale(.75); | |
} | |
50% { | |
opacity: 1; | |
transform: scale(1); | |
} | |
to { | |
opacity: .5; | |
transform: scale(.75); | |
} | |
} | |
/* WITH "CLOSE" BUTTON */ | |
.imagelightbox-close { | |
border: none; | |
cursor: pointer; | |
width: 3em; | |
/* 40 */ | |
height: 3em; | |
/* 40 */ | |
background-color: transparent; | |
position: fixed; | |
z-index: 10002; | |
top: 2.5em; | |
/* 40 */ | |
right: 2.5em; | |
/* 40 */ | |
border-radius: 50%; | |
transition: color .3s ease; | |
&:hover, | |
&:active, | |
&:focus { | |
background-color: $color__brand-2; | |
} | |
} | |
.imagelightbox-close:before, | |
.imagelightbox-close:after { | |
width: 3px; | |
background-color: $color__brand-1; | |
content: ''; | |
position: absolute; | |
top: 20%; | |
bottom: 20%; | |
left: 50%; | |
margin-left: -1px; | |
} | |
.imagelightbox-close:before { | |
transform: rotate(45deg); | |
} | |
.imagelightbox-close:after { | |
transform: rotate(-45deg); | |
} | |
/* WITH CAPTION */ | |
.imagelightbox-caption { | |
text-align: center; | |
font-family: $font__open-semi-bold; | |
color: $color__brand-1; | |
text-transform: uppercase; | |
background-color: #ededed; | |
position: fixed; | |
z-index: 10001; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
padding: 0.625em; | |
/* 10 */ | |
} | |
/* WITH NAVIGATION */ | |
// .imagelightbox-nav { | |
// background-color: rgba(0, 0, 0, .5); | |
// position: fixed; | |
// z-index: 10001; | |
// left: 50%; | |
// bottom: 3.75em; | |
// /* 60 */ | |
// padding: 0.313em; | |
// /* 5 */ | |
// transform: translateX(-50%); | |
// border-radius: 20px; | |
// } | |
// .imagelightbox-nav a { | |
// position: relative; | |
// top: 0.2em; | |
// width: 1em; | |
// /* 20 */ | |
// height: 1em; | |
// /* 20 */ | |
// border: 1px solid #fff; | |
// display: inline-block; | |
// margin: 0 0.313em; | |
// /* 5 */ | |
// border-radius: 50%; | |
// } | |
// .imagelightbox-nav .active { | |
// animation: fade-in 0.45s linear; | |
// background-color: #fff; | |
// } | |
// .imagelightbox-navitem:active { | |
// background: #808080; | |
// } | |
.imagelightbox-loading, | |
.imagelightbox-overlay, | |
.imagelightbox-close, | |
.imagelightbox-nav, | |
.imagelightbox-arrow { | |
animation: fade-in 0.25s linear; | |
} | |
@keyframes fade-in { | |
from { | |
opacity: 0; | |
} | |
to { | |
opacity: 1; | |
} | |
} | |
@media only screen and (max-width: 41.250em) { | |
/* 660 */ | |
#container { | |
width: 100%; | |
} | |
.imagelightbox-close { | |
top: 1.25em; | |
/* 20 */ | |
right: 1.25em; | |
/* 20 */ | |
} | |
.imagelightbox-arrow { | |
width: 2.5em; | |
/* 40 */ | |
height: 3.75em; | |
/* 60 */ | |
margin-top: -1.875em; | |
/* 30 */ | |
} | |
.imagelightbox-arrow-left { | |
left: 1.25em; | |
/* 20 */ | |
} | |
.imagelightbox-arrow-right { | |
right: 1.25em; | |
/* 20 */ | |
} | |
} | |
@media only screen and (max-width: 20em) { | |
/* 320 */ | |
.imagelightbox-arrow-left { | |
left: 0; | |
} | |
.imagelightbox-arrow-right { | |
right: 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Dowload JS Library | |
* Homepage: https://rejas.github.io/imagelightbox | |
* GitHub: https://github.com/rejas/imagelightbox | |
*/ | |
// Photo Gallery with Lightbox. | |
if ( ! function_exists( 'slug_photo_gallery_lightbox' ) ) : | |
/** | |
* Displays the photo gallery with lightbox from ACF. | |
* | |
* @return void | |
*/ | |
function slug_photo_gallery_lightbox() { | |
if ( function_exists( 'get_field' ) ) : | |
$images = get_field( 'gallery' ); | |
if ( $images ) : | |
wp_enqueue_script( 'imagelightbox-library', get_template_directory_uri() . '/js/min/image-lightbox.min.js', array( 'jquery' ), '20190228', true ); | |
add_action( 'wp_footer', 'initiate_lightbox_js', 100 ); | |
/** | |
* Runs script for imagelightbox js | |
* | |
* @return void | |
*/ | |
function initiate_lightbox_js() { | |
?> | |
<script> | |
jQuery('a[data-imagelightbox="a"]').imageLightbox({ | |
activity: true, | |
arrows: true, | |
button: true, | |
caption: true, | |
enableKeyboard: true, | |
overlay: true, | |
quitOnEscKey: true | |
}); | |
</script> | |
<?php | |
} | |
?> | |
<div class='gallery'> | |
<ul> | |
<?php foreach ( $images as $image ) : ?> | |
<li> | |
<a data-imagelightbox="a" data-ilb2-caption="<?php echo esc_attr( $image['caption'] ); ?>" href="<?php echo esc_attr( $image['url'] ); ?>"> | |
<img src="<?php echo esc_attr( $image['sizes']['gallery-img'] ); ?>" alt="<?php echo esc_attr( $image['alt'] ); ?>"> | |
</a> | |
</li> | |
<?php endforeach; ?> | |
</ul> | |
</div><!-- .gallery --> | |
<?php | |
endif; | |
endif; | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment