Created
January 14, 2012 22:26
-
-
Save alexkingorg/1613119 to your computer and use it in GitHub Desktop.
Hover effect for image format excerpts
This file contains 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 | |
// 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