我想修改此代码以输出随机响应,代码从第一部分选择一个响应,从第2部分选择响应,从第3部分选择响应。
https://github.com/yckart/jquery.typer.js
(function($){
$.fn.typer = function(text, options){
options = $.extend({}, {
char: '',
delay: 5000,
duration: 800,
endless: true,
onType: $.noop,
afterAll: $.noop,
afterPhrase: $.noop
}, options || text);
text = $.isPlainObject(text) ? options.text : text;
text = $.isArray(text) ? text : text.split(" ");
return this.each(function(){
var elem = $(this),
isVal = {input:1, textarea:1}[this.tagName.toLowerCase()],
isTag = false,
timer,
c = 0;
(function typetext(i) {
var e = ({string:1, number:1}[typeof text] ? text : text[i]) + '',
char = e.substr(c++, 1);
if( char === '<' ){ isTag = true; }
if( char === '>' ){ isTag = false; }
elem[isVal ? "val" : "html"](e.substr(0, c) + ($.isFunction(options.char) ? options.char() : options.char || ' '));
if(c <= e.length){
if( isTag ){
typetext(i);
} else {
timer = setTimeout(typetext, options.duration/10, i);
}
options.onType(timer);
} else {
c = 0;
i++;
if (i === text.length && !options.endless) {
return;
} else if (i === text.length) {
i = 0;
}
timer = setTimeout(typetext, options.delay, i);
if(i === text.length - 1) options.afterAll(timer);
options.afterPhrase(timer);
}
})(0);
});
};
}(jQuery));
回复代码如下
if (animation) {
var text = $('#home .typer-title'),
textOne = "response",
textOne = "response",
textOne = "response",
textOne = "response",
textOne = "response",
textOne = "response",
textOne = "response",
textTwo = "response",
textTwo = "response",
textTwo = "response",
textThree = "response";
textThree = "response";
textThree = "response";
textThree = "response";
textThree = "response";
textThree = "response";
textThree = "response";
if (!!$.prototype.typer) {
text.typer([textOne,textTwo,textThree]);
}
}
我道歉,我的java脚本不适合snuff有用的提示或代码片段在进行此更改时会非常感激