I have this part of html:
<h1 class="gr-title uppercase">
<span class="title-red">GET MORE</span>
<span id="wordSwap" class="title-black">PROFITS</span>
</h1>
...and this jquery code that changes the value of the span with ID wordSwap:
(function(){
//Words:
var words = [
'Profits',
'Freedom',
'Time',
'Enjoyment',
'Disconnection',
'Value'
], i = 0;
setInterval(function(){
$('#wordSwap').fadeOut(function(){
$(this).html(words[i=(i+1)%words.length]).fadeIn();
});
// 2 second interval
}, 2000);
})();
I'm trying to change the letter-spacing for each value in the array based on what value/word comes next, but I am stuck and can't get it to work. For example I'd like the word "Time" to have letter-spacing = 30px, and the word "Value" 20px, and so on. How can I get this done?
Here is a jsfiddle of what I have up to now: https://jsfiddle.net/vgum6jn6/
//Swap words effect
(function() {
// List of words:
var words = [
'Profits',
'Freedom',
'Time',
'Enjoyment',
'Disconnection',
'Value'
], i = 0;
setInterval(function() {
$('#wordSwap').fadeOut(function() {
$(this).html(words[i = (i + 1) % words.length]).fadeIn();
});
// 2 seconds
}, 2000);
})();
.gr-title {
font-family: "Arial", Georgia, Serif;
}
.uppercase {
text-transform: uppercase;
}
.title-red {
color: #CB0000;
}
.title-black {
color: #191919;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<h1 class="gr-title uppercase">
<span class="title-red">GET MORE</span> <span id="wordSwap" class="title-black">PROFITS</span>
</h1>
[{word:'Time',spacing:'30px'},{word:'Value',spacing:'20px'}]