AngularJS 'Typewriter' Directive
How do I make an angularjs 'typewriter' directive?
AngularJS Directive that simulates the effect of typing on a text editor - the text is passed as an attribute as well as speed configs.. What is a angularjs 'typewriter' directive? How do you make a angularjs 'typewriter' directive? This script and codes were developed by António Capelo on 15 December 2022, Thursday.
AngularJS 'Typewriter' Directive - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>AngularJS 'Typewriter' Directive</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div ng-app="sampleApp"> <div class="container"> <h1>AngularJS 'Typewrite' effect directive</h1> <a target="_blank" href="https://github.com/antoniocapelo/AngularJS-Typewrite"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://github-camo.global.ssl.fastly.net/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a> <p typewrite type-delay="100" blink-cursor="false" text="This is a 'typewrite' directive."></p> <p typewrite type-delay="100" blink-cursor="false" text="You can set an initial delay." initial-delay="5s"></p> <p typewrite blink-cursor="false" text="You can also change the typing speed," initial-delay="9.5s" type-delay="50"></p> <p typewrite text="or the blinking frequency" initial-delay="11s" type-delay="50" blink-delay="500"></p> <p typewrite text="Or even change the cursor :)" cursor="~" initial-delay="13s" type-delay="50" blink-delay="1s"></p> </div>
</div> <script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
AngularJS 'Typewriter' Directive - Script Codes CSS Codes
/* All the keyframes 'vendor prefix' versions: */
@-webkit-keyframes blink-it { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; }
}
@-moz-keyframes blink-it { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; }
}
@-o-keyframes blink-it { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; }
}
@keyframes blink-it { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; }
}
/* Blinking class */
.blink { -webkit-animation: blink-it steps(1) 1s infinite; -moz-animation: blink-it steps(1) 1s infinite; -ms-animation: blink-it steps(1) 1s infinite; -o-animation: blink-it steps(1) 1s infinite; animation: blink-it steps(1) 1s infinite;
}
html { background-image: url('https://subtlepatterns.com/patterns/dark_fish_skin.png'); color: #efefef;
}
p { font-family: Arial; font-size: 46px;
}
h1 { font-family: Arial; font-size: 52px;
}
AngularJS 'Typewriter' Directive - Script Codes JS Codes
var app = angular.module('sampleApp', []);
app.controller('MainCtrl',['$scope', function ($scope) {
$scope.cenas = "oi";
}]);
app.directive('typewrite', ['$timeout', function ($timeout) { function linkFunction (scope, iElement, iAttrs) { var timer = null, initialDelay = iAttrs.initialDelay ? getTypeDelay(iAttrs.initialDelay) : 200, typeDelay = iAttrs.typeDelay ? getTypeDelay(iAttrs.typeDelay) : 200, blinkDelay = iAttrs.blinkDelay ? getAnimationDelay(iAttrs.blinkDelay) : false, cursor = iAttrs.cursor ? iAttrs.cursor : '|', blinkCursor = iAttrs.blinkCursor ? iAttrs.blinkCursor === "true" : true, auxStyle; if (iAttrs.text) { timer = $timeout(function() { updateIt(iElement, 0, iAttrs.text); }, initialDelay); } function updateIt(element, i, text){ if (i <= text.length) { element.html(text.substring(0, i) + cursor); i++; timer = $timeout(function() { updateIt(iElement, i, text); }, typeDelay); return; } else { if (blinkCursor) { if (blinkDelay) { auxStyle = '-webkit-animation:blink-it steps(1) ' + blinkDelay + ' infinite;-moz-animation:blink-it steps(1) ' + blinkDelay + ' infinite ' + '-ms-animation:blink-it steps(1) ' + blinkDelay + ' infinite;-o-animation:blink-it steps(1) ' + blinkDelay + ' infinite; ' + 'animation:blink-it steps(1) ' + blinkDelay + ' infinite;'; element.html(text.substring(0, i) + '<span class="blink" style="' + auxStyle + '">' + cursor + '</span>'); } else { element.html(text.substring(0, i) + '<span class="blink">' + cursor + '</span>'); } } else { element.html(text.substring(0, i)); } } } function getTypeDelay(delay) { if (typeof delay === 'string') { return delay.charAt(delay.length - 1) === 's' ? parseInt(delay.substring(0, delay.length - 1), 10) * 1000 : +delay; } } function getAnimationDelay(delay) { if (typeof delay === 'string') { return delay.charAt(delay.length - 1) === 's' ? delay : parseInt(delay.substring(0, delay.length - 1), 10) / 1000; } } scope.$on('$destroy', function() { if(timer) { $timeout.cancel(timer); } }); } return { restrict: 'A', link: linkFunction, scope: false }; }]);
Developer | António Capelo |
Username | capelo |
Uploaded | December 15, 2022 |
Rating | 4.5 |
Size | 3,111 Kb |
Views | 16,192 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Camera click | 1,963 Kb |
Background cover | 3,735 Kb |
Gif as page background | 3,521 Kb |
Custom checkbox example | 3,495 Kb |
Full-width slider. | 3,886 Kb |
React Boilerplate | 1,457 Kb |
8-Bit Avatar | 2,527 Kb |
Clock loading | 2,351 Kb |
ToDo | 8,475 Kb |
Room | 5,196 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
JQuery Validate checkbox group | Lunaman | 2,466 Kb |
Hc first draft | Stepfray | 5,104 Kb |
A Pen by Andrea Verlicchi | Verlok | 2,018 Kb |
Two Element Typeface | Chrisota | 4,942 Kb |
Simple DevTools | Deegill | 2,511 Kb |
Website Concept | Sagoza | 3,104 Kb |
Countdown with Rings | Ewganoel | 2,490 Kb |
Nice textured background | Hans | 2,659 Kb |
Calculator | Rzencoder | 4,572 Kb |
Flat design iframe | Damienpm | 1,819 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!