Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带jquery ui彩色动画的blast.js动画_Javascript_Jquery_Css_Jquery Ui_Animation - Fatal编程技术网

Javascript 带jquery ui彩色动画的blast.js动画

Javascript 带jquery ui彩色动画的blast.js动画,javascript,jquery,css,jquery-ui,animation,Javascript,Jquery,Css,Jquery Ui,Animation,我使用blast.js制作两个单词的动画,使用jqueryui制作颜色的动画。我试过的一切都没用 CSS在演示中是不相关的,因为颜色按钮没有CSS规则 var newColor = '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6); $('.color_button').on('click', function(){ var words = $('color_body').blast({

我使用blast.js制作两个单词的动画,使用jqueryui制作颜色的动画。我试过的一切都没用

CSS在演示中是不相关的,因为颜色按钮没有CSS规则

var newColor = '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);

$('.color_button').on('click', function(){
    var words = $('color_body').blast({
        delimiter: 'word',
        generateValueClass: true
    });
    words.each(function(){
    $(this).animate({
    color: newColor
    }, 500);
});
});

目标是将每个单词的颜色更改为随机颜色。

确保将此jQuery颜色插件添加到您的项目中,因为它似乎在DOM中丢失:(我必须使用
标记将整个脚本复制并粘贴到JSbin。)

然后将代码更改为如下所示。newColor必须在按钮的onClick内部生成,并在.each()函数内部生成,该函数在单个单词上循环。然后,“彩色文本”按钮将随机更改每个单词的文本颜色

第1版:

$('.color_button').on('click', function(){
    var words = $('.color_body').blast({
        delimiter: 'word',
        generateValueClass: true
    });
    words.each(function(idx, obj){
      var newColor = '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
      $(obj).animate({
        "color": newColor
      }, 500);
    });
});
第2版(见评论):

第3版(请参阅注释-以下是示例JSFIDLE):


你知道我如何在不按下按钮的情况下连续改变颜色吗?我需要一个setTimeout吗?尝试使用setInterval,因为它将在无限循环中重复,直到清除为止。setTimeout函数将仅循环1x,然后停止。将setTimeout放入无限循环需要额外的代码,而setInterval将非常适合这样做!只需将应答代码示例中的第一行和最后一行替换为
setInterval(function(){
},500),分别为。然后将500毫秒计时器从动画功能中取出&它应该可以工作。从未使用过间隔,很高兴知道。我将再一次打扰你,并询问我如何设置它,以便在它改变颜色一次后设置间隔。否则,它似乎没有做任何事,点击2000毫秒的方式,我有它的设置我已经添加了2个代码示例,让你看看。
setInterval(function() {
    var words = $('.color_body').blast({
        delimiter: 'word',
        generateValueClass: true
    });
    words.each(function(idx, obj){
      var newColor = '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
      $(obj).animate({
        "color": newColor
      });
    });
},500);
var timer = null;
(function setColor() {
    var words = $('.color_body').blast({
        delimiter: 'word',
        generateValueClass: true
    });
    words.each(function(idx, obj){
      var newColor = '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
      $(obj).animate({
        "color": newColor
      });
      if (!timer) {
          timer = setInterval(setColor,2000); // Loops continuously.
      }
    });
})(); // This function will Auto-Run 1x