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 DevShahidul/a90a76a505e840b815db72915349f677 to your computer and use it in GitHub Desktop.
Save DevShahidul/a90a76a505e840b815db72915349f677 to your computer and use it in GitHub Desktop.
Note: Please Don't use the float: left css in body-copy selector ;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<title>Strider | Home</title>
<link type="text/css" rel="stylesheet" href="css/style.css">
<style>
.body-copy{position: relative; width: 100%; height: auto;}
.body-copy-two{position: absolute; visibility: hidden; height: 0; padding: 0; margin: 0;}
</style>
</head>
<body>
<h2 class="white body-copy">Technology that changes financial services to better people’s lives.</h2>
<h2 class="body-copy-two"></h2>
<script type="text/javascript">
function wordWrap() {
$(".body-copy").each(function(){
var bdy = $(this);
var body2 = bdy.parent().find(".body-copy-two");
var text = $(bdy).text();
var html = $(bdy).html();
var bWidth = $(bdy).width();
var words = text.split(" ");
var span = "";
var word = "";
var allSpans = "";
var lastWord = "";
$(words).each(function(i, w) {
if (lastWord != "") {
w = lastWord + " "+ w ;
lastWord = "";
};
word = w + " ";
span = span + word;
body2.append(word);
if (body2.width() >= bWidth) {
var wLen = word.length;
span = span.slice(0, -wLen);
lastWord = w + " ";
allSpans = allSpans + "<span>" + $.trim(span) + "</span>";
body2.html("");
span = "";
word = "";
}
});
var lastSpan = "<span>" + body2.text() + "</span>";
$(bdy).html(allSpans + lastSpan);
})
}
wordWrap();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment