Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Typing Feature #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion _includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<div class="header-content-inner">
<h1>Your Favorite Source of Free Bootstrap Themes</h1>
<hr>
<p>Start Bootstrap can help you build better websites using the Bootstrap CSS framework! Just download your template and start going, no strings attached!</p>
<p id="messages" style="display: inline-block;"> </p>
<br>
<a href="#about" class="btn btn-primary btn-xl page-scroll">Find Out More</a>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions _includes/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@

<!-- Custom Theme JavaScript -->
<script src="js/creative.js"></script>

<!-- Automatic Typing Feature -->
<script src="js/autoType.js"></script>
25 changes: 25 additions & 0 deletions js/autoType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var text = ["Start Bootstrap can help build better websites using the CSS framework!",
"Just download your template and start going, no strings attached!"]; // add more messages here!
var delay = 50;
var currentWord = 0;
var currentChar = 0;
var dest = document.getElementById("messages");;

function type() {
dest.innerHTML = text[currentWord].substr(0, ++currentChar);
if (currentChar > text[currentWord].length) setTimeout("unType()", 2000); // delay before erasing message
else setTimeout("type()", delay);
}

function unType() {
dest.innerHTML = text[currentWord].substr(0, currentChar);
if (--currentChar === 0) {
dest.innerHTML = "<br>"; // otherwise page will jump due to line deletion
if (currentWord + 1 === text.length) currentWord = 0;
else ++currentWord;
setTimeout("type()", 750); // delay before typing new message
} else setTimeout("unType()", delay/2);
}

// delay typing for page to partially load
setTimeout("type()", 3000);