我找到了这个 JavaScript,它完美地为文本设置了动画,但是如何在谷歌网页设计器中为这个脚本分配一个动态字段?
下面是 jsfiddle 链接,说明动态文本将如何动画化。
https://jsfiddle.net/MarilynM84/2angj8tL/
function airport(el, array) {
var self = el;
var items = array.length;
var items2 = array.length;
var chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', ' ', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0','!','¿','?','-','+','.',',',"'",'"','ç','ñ','à','á','è','é','ì','í','ò','ó','ù','ú','À','Á','È','É','Ì','Í','Ò','Ó','Ù','Ú'];
var longest = 0;
var opts = {
transition_speed: 2000,
fill_space: false,
longest: 0
};
//adds extra spaces to strings in array that are shorter than longest
function pad(a, b) {
return a + new Array(b - a.length + 1).join(' ');
}
self.innerHTML = '';
//finds the longest string in array
while (items--) {
if(array[items].length > longest) {
longest = array[items].length;
}
}
//makes all strings in array the same length
while (items2--) {
array[items2] = pad(array[items2],longest);
}
spans = longest;
while (spans--) {
var span = document.createElement('span');
span.className = 'c' + spans;
self.insertBefore(span, self.firstChild);
}
//a - number of the span element
//b - for checking char[b] against each letter in array[xx]
//c - current word in array[c]
//d - used to track position of each letter in array[xx]
function init(a, b, c, d) {
var el = self.querySelector('.c' + a);
var current_letter = array[c] ? array[c].substring(d, d + 1) : null,
timer,
word_len = array[c] ? array[c].trim.length : null,
prev_word_len = array[c - 1] ? array[c - 1].trim.length : array[0].trim.length;
if (c >= array.length) { //reset
timer = setTimeout(function() {
init(1, 1, 1, 1);
}, 10);
}
else if (d >= longest) { //go to next word
timer = setTimeout(function() {
init(0, 0, c + 1, 0);
}, opts.transition_speed);
console.log(opts);
}
else {
el.innerHTML = chars[b] === ' ' ? ' ' : chars[b];
timer = setTimeout(function() {
if (b > chars.length) {
init(a + 1, 0, c, d + 1);
}
//go to next letter in chars[] if it doesnt match current letter in array[xx]
else if (chars[b] !== current_letter.toLowerCase()) {
init(a, b + 1, c, d);
}
else { //found the letter here
el.innerHTML = current_letter === ' ' && opts.fill_space ? ' ' : current_letter;
if (word_len < prev_word_len) {
if (a > word_len) {
for (a; a < prev_word_len; a++) {
self.querySelector('.c' + a).innerHTML = '';
}
d = longest;
}
}
init(a + 1, 0, c, d + 1);
}
}, 10);
}
}
init(0, 0, 0, 0);
}
// Call element by selected class or ID
airport(
document.querySelector('.example'),
// pass in data to be outputed here
[ 'Dynamic Content', ]
);
请帮忙,我是 JavaScript 的新手,我边走边学。谢谢!!