Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexkingorg/1613119 to your computer and use it in GitHub Desktop.
Save alexkingorg/1613119 to your computer and use it in GitHub Desktop.
Hover effect for image format excerpts
<?php
// Cut off images at 300px high in excepts, show full image on hover
function akv3_image_excerpt_hover_js() {
?>
<script>
;jQuery(function($) {
$('.format-image.excerpt .entry-content').hover(function() {
if ($('body').width() < 768) {
return;
}
var $img = $(this).find('.entry-media img');
if ($img[0].offsetHeight > 300) {
$img.parent().clone()
.addClass('hovered').find('img').removeAttr('title').end()
.prependTo($(this));
}
}, function() {
$(this).find('a.hovered').remove();
});
// for touch devices like an iPad
$('body').click(function() {
$('.format-image.excerpt .entry-content a.hovered').remove();
});
});
</script>
<?php
}
add_action('wp_footer', 'akv3_image_excerpt_hover_js');
function akv3_image_excerpt_hover_css() {
?>
<style>
@media only screen and (min-width: 768px) {
#content .format-image.excerpt {
overflow: visible;
position: relative;
}
.format-image.excerpt .entry-media {
max-height: 300px;
overflow: hidden;
}
.format-image.excerpt a.hovered img {
box-shadow: 0px 3px 5px #888;
position: absolute;
top: 46px;
z-index: 5;
}
}
</style>
<?php
}
add_action('wp_head', 'akv3_image_excerpt_hover_css');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment