仅使用Javascript在Qualtrics中淡入淡出文本

仅使用Javascript在Qualtrics中淡入淡出文本,javascript,html,prototypejs,qualtrics,Javascript,Html,Prototypejs,Qualtrics,我正在使用Qualtrics进行调查,我需要在同一空间中淡入淡出的多个文本。它只是一个每1秒不断变化的文本,上面写着: 选择一种语言 艾斯考拉 伊莱贾 언어를 선택하세요 等等等等 我在这里找到了一些有用的代码,但没有一个真正有效,因为Qualtrics只适用于HTML和奇怪的JS格式(对不起,我不是编码高手)。任何帮助都将不胜感激!谢谢。尝试以下javascript: Qualtrics.SurveyEngine.addOnload(function() { var lines = ["Cho

我正在使用Qualtrics进行调查,我需要在同一空间中淡入淡出的多个文本。它只是一个每1秒不断变化的文本,上面写着:

  • 选择一种语言
  • 艾斯考拉
  • 伊莱贾
  • 언어를 선택하세요
  • 等等等等

  • 我在这里找到了一些有用的代码,但没有一个真正有效,因为Qualtrics只适用于HTML和奇怪的JS格式(对不起,我不是编码高手)。任何帮助都将不胜感激!谢谢。

    尝试以下javascript:

    Qualtrics.SurveyEngine.addOnload(function()
    {
    var lines = ["Choose a language", 
                 "Escolha um idioma", 
                 "Elija un idioma", 
                 "언어를 선택하세요",
                 "Choose a language<br>" + 
                 "Escolha um idioma<br>" + 
                 "Elija un idioma<br>" +  
                 "언어를 선택하세요"]; //Add all lines of text to this array except the first line, I recommend ending with a list of all versions of the text.
    var time = 8000; //Change me to your desired amount of time fading in and out for each element
    
    (function() {
        var FX = {
            easing: {
                linear: function(progress) {
                    return progress;
                },
                quadratic: function(progress) {
                    return Math.pow(progress, 2);
                },
                swing: function(progress) {
                    return 0.5 - Math.cos(progress * Math.PI) / 2;
                },
                circ: function(progress) {
                    return 1 - Math.sin(Math.acos(progress));
                },
                back: function(progress, x) {
                    return Math.pow(progress, 2) * ((x + 1) * progress - x);
                },
                bounce: function(progress) {
                    for (var a = 0, b = 1, result; 1; a += b, b /= 2) {
                        if (progress >= (7 - 4 * a) / 11) {
                            return -Math.pow((11 - 6 * a - 11 * progress) / 4, 2) + Math.pow(b, 2);
                        }
                    }
                },
                elastic: function(progress, x) {
                    return Math.pow(2, 10 * (progress - 1)) * Math.cos(20 * Math.PI * x / 3 * progress);
                }
            },
            animate: function(options) {
                var start = new Date;
                var id = setInterval(function() {
                    var timePassed = new Date - start;
                    var progress = timePassed / options.duration;
                    if (progress > 1) {
                        progress = 1;
                    }
                    options.progress = progress;
                    var delta = options.delta(progress);
                    options.step(delta);
                    if (progress == 1) {
                        clearInterval(id);
                        options.complete();
                    }
                }, options.delay || 10);
            },
            fadeOut: function(element, options) {
                var to = 1;
                this.animate({
                    duration: options.duration,
                    delta: function(progress) {
                        progress = this.progress;
                        return FX.easing.swing(progress);
                    },
                    complete: options.complete,
                    step: function(delta) {
                        element.style.opacity = to - delta;
                    }
                });
            },
            fadeIn: function(element, options) {
                var to = 0;
                this.animate({
                    duration: options.duration,
                    delta: function(progress) {
                        progress = this.progress;
                        return FX.easing.swing(progress);
                    },
                    complete: options.complete,
                    step: function(delta) {
                        element.style.opacity = to + delta;
                    }
                });
            }
        };
        window.FX = FX;
    })()
    
    lines.forEach(function(element, index, array){
        setTimeout(function(){
            FX.fadeOut($('animatedText'),{
                duration: time/2,
                complete: function() {
                    console.log(lines[index]);
                    $('animatedText').update(lines[index]);
                    FX.fadeIn($('animatedText'),{
                        duration: time/2,
                        complete: function(){}
                    });
                }
            });
        }, time*index);
    });
    
    });
    
    Qualtrics.SurveyEngine.addOnload(函数()
    {
    变量行=[“选择一种语言”,
    “埃斯科拉·乌姆·西莫拉”,
    “Elija un idioma”,
    "언어를 선택하세요",
    “选择一种语言
    ”+ “习惯用语”
    “+ “Elija un idioma
    ”+ "언어를 선택하세요“];//将除第一行之外的所有文本行添加到此数组,我建议以所有文本版本的列表结尾。 var time=8000;//将我更改为每个元素淡入淡出所需的时间量 (功能(){ var外汇={ 放松:{ 线性:功能(进度){ 返回进度; }, 二次:函数(进度){ 返回Math.pow(progress,2); }, swing:功能(进度){ 返回0.5-Math.cos(progress*Math.PI)/2; }, 保监会:职能(进展){ 返回1-Math.sin(Math.acos(progress)); }, 返回:函数(进度,x){ 返回Math.pow(进度,2)*((x+1)*进度-x); }, 反弹:功能(进度){ 对于(变量a=0,b=1,结果;1;a+=b,b/=2){ 如果(进度>=(7-4*a)/11){ return-Math.pow((11-6*a-11*progress)/4,2)+Math.pow(b,2); } } }, 弹性:功能(进度,x){ 返回Math.pow(2,10*(progress-1))*Math.cos(20*Math.PI*x/3*progress); } }, 动画:函数(选项){ var开始=新日期; var id=setInterval(函数(){ var timePassed=新日期-开始; var progress=timePassed/options.duration; 如果(进度>1){ 进展=1; } options.progress=进度; var delta=选项。delta(进度); 选项。步骤(增量); 如果(进度==1){ 清除间隔(id); options.complete(); } },options.delay | | 10); }, 淡出:功能(元素、选项){ var-to=1; 这是动画({ 持续时间:options.duration, 增量:功能(进度){ 进步=这个。进步; 外汇收益率。缓和。波动(进度); }, 完成:选项。完成, 步骤:函数(增量){ element.style.opacity=to-delta; } }); }, fadeIn:功能(元素、选项){ var-to=0; 这是动画({ 持续时间:options.duration, 增量:功能(进度){ 进步=这个。进步; 外汇收益率。缓和。波动(进度); }, 完成:选项。完成, 步骤:函数(增量){ element.style.opacity=to+delta; } }); } }; window.FX=FX; })() forEach(函数(元素、索引、数组){ setTimeout(函数(){ FX.fadeOut($('animatedText'){ 持续时间:时间/2, 完成:函数(){ log(行[索引]); $('animatedText')。更新(行[索引]); FX.fadeIn($('animatedText'){ 持续时间:时间/2, 完成:函数(){} }); } }); },时间*指数); }); });
    结合此html:

    这是将要更改的文本,请将其设置为第一个元素。

    这将从div中已经存在的文本开始,并在每次闪烁时替换它,将行数组更新为所需的文本行,并将时间变量更新为每个元素应闪烁的时间量,单位为ms(1000ms=1s)

    以下是Qualtrics的演示:


    为了充分披露,FX.fadeIn/fadeOut函数是用户gabrieleromanato在

    上的工作,请参见。我们需要一些您尝试过的代码,了解您所做的工作,etcStack Overflow确实适用于已经做了一些工作并有东西要展示的用户。不过,请欣赏我下面的实现。