Machine Gun Text Effect w/ GSAP JS

Developer
Size
3,380 Kb
Views
50,600

How do I make an machine gun text effect w/ gsap js?

Check out this enhanced version that intelligently groups words together: http://codepen.io/GreenSock/pen/sxdfe. What is a machine gun text effect w/ gsap js? How do you make a machine gun text effect w/ gsap js? This script and codes were developed by GreenSock on 11 June 2022, Saturday.

Machine Gun Text Effect w/ GSAP JS Previews

Machine Gun Text Effect w/ GSAP JS - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Machine Gun Text Effect w/ GSAP JS</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <link href='http://fonts.googleapis.com/css?family=Asap:400,700' rel='stylesheet' type='text/css'>
<div id="demo"></div>
<h2>special features</h2>
<ul> <li>Duration of each word's animation is based on character count giving you more time to read longer words</li> <li>Last word in sentence stays on screen longer</li> <li>Pause added after each sentence</li> <li><a href="http://codepen.io/GreenSock/pen/sxdfe">new version that groups words</a>
</ul> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/plugins/TextPlugin.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Machine Gun Text Effect w/ GSAP JS - Script Codes CSS Codes

body{	background-color:#111; color:white;
}
#demo{ position:relative; width:800px; height:300px; background-color:#000; margin:auto; overflow:hidden;
}
#demo h3 { position:absolute; font-family: 'Asap', sans-serif; font-weight:700; margin:0; padding:0; width:800px; text-align:center; visibility:hidden; font-size:120px; top:65px;
}
h2 { color:#9af600; margin-left:24px; margin-bottom:0px;
}
li { font-family: 'Asap', sans-serif; color:#999; margin-bottom:10px;
}
a:link, a:visited, a:active{ color:#f60;
}

Machine Gun Text Effect w/ GSAP JS - Script Codes JS Codes

var container = $("#demo"), _sentenceEndExp = /(\.|\?|!)$/g; //regular expression to sense punctuation that indicates the end of a sentence so that we can adjust timing accordingly
function machineGun(text) { var words = text.split(" "), tl = new TimelineMax({delay:0.6, repeat:2, repeatDelay:4}), wordCount = words.length, time = 0, word, element, duration, isSentenceEnd, i; for(i = 0; i < wordCount; i++){ word = words[i]; isSentenceEnd = _sentenceEndExp.test(word); element = $("<h3>" + word + "</h3>").appendTo(container); duration = Math.max(0.5, word.length * 0.08); //longer words take longer to read, so adjust timing. Minimum of 0.5 seconds. if (isSentenceEnd) { duration += 0.6; //if it's the last word in a sentence, drag out the timing a bit for a dramatic pause. } //set opacity and scale to 0 initially. We set z to 0.01 just to kick in 3D rendering in the browser which makes things render a bit more smoothly. TweenLite.set(element, {autoAlpha:0, scale:0, z:0.01}); //the SlowMo ease is like an easeOutIn but it's configurable in terms of strength and how long the slope is linear. See http://www.greensock.com/v12/#slowmo and http://api.greensock.com/js/com/greensock/easing/SlowMo.html tl.to(element, duration, {scale:1.2, ease:SlowMo.ease.config(0.25, 0.9)}, time) //notice the 3rd parameter of the SlowMo config is true in the following tween - that causes it to yoyo, meaning opacity (autoAlpha) will go up to 1 during the tween, and then back down to 0 at the end.	.to(element, duration, {autoAlpha:1, ease:SlowMo.ease.config(0.25, 0.9, true)}, time); time += duration - 0.05; if (isSentenceEnd) { time += 0.6; //at the end of a sentence, add a pause for dramatic effect. } }
}
machineGun("These words are constantly animating in your face to suck you in and leave you hanging for what comes next. Can you handle the awesomeness? Or are you left quivering in fear? It's only text, silly. Longer words stay on the screen for a greater duration. Each sentence ends with a dramatatic pause. Yes, that pause. The End");
/* learn more about the GreenSock Animation Platfrom (GSAP) for JS
http://www.greensock.com/gsap-js/
watch a quick video on how TimelineLite allows you to sequence animations like a pro
http://www.greensock.com/sequence-video/
*/
//Check out this enhanced version that intelligently groups words together: http://codepen.io/GreenSock/pen/sxdfe
Machine Gun Text Effect w/ GSAP JS - Script Codes
Machine Gun Text Effect w/ GSAP JS - Script Codes
Home Page Home
Developer GreenSock
Username GreenSock
Uploaded June 11, 2022
Rating 4.5
Size 3,380 Kb
Views 50,600
Do you need developer help for Machine Gun Text Effect w/ GSAP JS?

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!

GreenSock (GreenSock) Script Codes
Create amazing sales emails with AI!

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!