/ Published in: JavaScript
this is a combination of javascript and css and an image called letters.jpg that allows you to use any font you want for the first letter of each paragraph. Letters.jpg needs to have all the letters in uppercase in a row. See the link for a sample letters image. This function should be called on body load
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<style> .IllumLetter { float: left; height: 20px; width: 25px; text-indent: -9999px; } </style> <script language="javascript" type="application/javascript"> function textchange() { var contentDiv = document.getElementById("content"); var containedDivElements = contentDiv.getElementsByTagName("P"); for(i = 0; i < containedDivElements.length; i++) { var oldstring = containedDivElements[i].innerHTML; var pos = (oldstring.toUpperCase().charCodeAt(1) - 65) * 25; var style = "background: url(/images/letters.jpg) -" + pos +"px 0px no-repeat;"; var newstring = oldstring.replace(oldstring[1],"<div class='IllumLetter' style='" + style + "'>" + oldstring[1] + "</div>"); containedDivElements[i].innerHTML = newstring; } } </script>
URL: http://mycodebytes.net/images/letters.jpg