Last active
August 29, 2015 14:05
-
-
Save swapnilshrikhande/eecd9eb1a6ae469762b3 to your computer and use it in GitHub Desktop.
Fix Alt text not showing when image width too low to fit
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
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<style> | |
.alt-div{ | |
text-align : center; | |
vertical-align:middle; | |
min-height : 200px; | |
min-width : 200px; | |
} | |
</style> | |
<!-- PUT WHERE IS APPEARS CURRENTLY --> | |
ADD class my-img TO IMAGE TAG | |
<div class="alt-div" style="display:none;"/> | |
<script> | |
$(document).ready(function(event){ | |
updateImageAlt(); | |
}); | |
var updateImageAlt = function(event){ | |
$("img").each(function(index,image){ | |
if(!$.trim($(image).attr("src"))){ | |
var altDiv = $(image).closest("a").find('.alt-div'); | |
$(image).hide(); | |
altDiv.height($(image).height()); | |
altDiv.height($(image).width()); | |
altDiv.text($(image).attr("alt")); | |
altDiv.show(); | |
} | |
}) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment