I have a static resource JavaScript file that is referenced via <apex:includeScript>
that displays a simple typing effect on the VF page however it is not working when previewed and displays as if there is no JS at all.
Do I need to reference the css class differently in VF?
JS
const texts = ['Developer', 'Writer'];
//Counter to iterate through each word
let count = 0;
//Check which word we are iterating over
let index = 0;
//Current word
let currentText = '';
//Letters
let letter = '';
(function type() {
if(count === texts.length) {
count = 0;
}
//Use count to select text to display
currentText = texts[count];
letter = currentText.slice(0, ++index);
document.querySelector('.typing').textContent = letter;
if(letter.length === currentText.length) {
count++;
index = 0;
}
setTimeout(type, 400);
}());
VFP
<apex:page showHeader="false" applyHtmlTag="true" applyBodyTag="false">
<apex:slds >
<head>
<title>John's Portfolio</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="styles.css" rel="stylesheet"/>
<apex:stylesheet value="{!URLFOR($Resource.portfolioStyle)}"/>
<apex:includeScript value="{!URLFOR($Resource.portfolioScript)}"/>
</head>
<br/>
<div align="center" class="slds-scope">
<p class="header">John Smith</p>
<br/>
<div class="row centercontainer">
<div class="column" align="left">
<button class="slds-button" style="margin-right: 60px; margin-left: 40px; font-size: 16px">Salesforce</button>
</div>
<div class="column" align="center">
<button class="slds-button" style="margin-right: 60px; margin-left: 40px;font-size: 16px">Software</button>
</div>
<div class="column" align="right">
<button class="slds-button" style="margin-right: 60px; margin-left: 40px;font-size: 16px">About Me</button>
</div>
</div>
<br/>
<div class="container">
<apex:image url="{!URLFOR($Resource.backgroundimg)}" height="2403" width="903">
</apex:image>
<div class="centered">
<div class="intro">
<p>A</p>
<p class="typing">Salesforce Consultant</p>
</div>
</div>
</div>
<br/>
<br/>
<div>
</div>
</apex:slds>
</apex:page>
Thanks in advance