首页 \ 问答 \ 使用GSAP动画SVG元素(Animating SVG elements with GSAP)

使用GSAP动画SVG元素(Animating SVG elements with GSAP)

我的任务是创建一个交互式SVG信息图,其中包含几张用于浏览器游戏的幻灯片,它共有5个步骤。 当您单击上一个/下一个按钮或特定步骤时,整个svg应该将自己设置为正确的步骤。

在代码方面,这就是我所拥有的:

function Slide() {

    // Cache all top-level svg elements for later use
    this.el = $('svg#betfair-slider');
    this.hands = this.el.find('#hands_8_');
    this.cardsDesk = this.el.find('g#center-cards');
    this.textContainer = $('.step-text');

    // Use a shared timeline across all slides, so there are no overlapping tweens
    this.tween = new TimelineLite();
}

function Slide2 () {

    // Inherit from the main slide
    Slide.call(this);

    // each slide has its own supporting explanatory text
    this.html = [
        '<h3>Preflop</h3>',
        '<p>Amet sit lorem ipsum dolar</p>'
    ].join('');

    // the main openslide method
    this.openSlide = function() {
        // find the cards that need to be animated for this specific slide
        var cards = this.hands.find('.card');
        // fade out each card
        this.tween.staggerTo(cards, 0.2, { opacity: 0 }, 0.2);
        // Render supporting text
        this.textContainer.html(this.html);
    };

}

以下是我想要获得的卡片: 在此处输入图像描述

我可以使用this.hands.find('.card');获取它们this.hands.find('.card'); jquery方法(我可以在控制台中看到它们),但我无法为它们设置动画。 我尝试动画不同的属性(不透明度,x,y,左等),但没有任何反应 - 屏幕上没有任何动作。

我能够执行this.hands.find('.card').hide()并使用jQuery更改css,但为什么TimelineLite在这里不起作用? 我也试过这种方法:

var cards = this.hands.find('.card');
for (var i = cards.length - 1; i >= 0; i -= 1) {
    var card = cards[i];
    this.tween.to(card, 0.2, { opacity: 0 });
}

但仍然没有成功......有趣的是,当我在补间上附加onComplete回调时,他们被解雇了,但屏幕上绝对没有任何动作。 你可以看看这里的一切。

感谢您提前获得的帮助,欢迎任何建议。


I am tasked with creating an interactive SVG infographic with few slides for a browser game, it has 5 steps total. When you click prev / next buttons or a specific step, the whole svg should animate itself to the correct step.

In terms of code, this is what I have:

function Slide() {

    // Cache all top-level svg elements for later use
    this.el = $('svg#betfair-slider');
    this.hands = this.el.find('#hands_8_');
    this.cardsDesk = this.el.find('g#center-cards');
    this.textContainer = $('.step-text');

    // Use a shared timeline across all slides, so there are no overlapping tweens
    this.tween = new TimelineLite();
}

function Slide2 () {

    // Inherit from the main slide
    Slide.call(this);

    // each slide has its own supporting explanatory text
    this.html = [
        '<h3>Preflop</h3>',
        '<p>Amet sit lorem ipsum dolar</p>'
    ].join('');

    // the main openslide method
    this.openSlide = function() {
        // find the cards that need to be animated for this specific slide
        var cards = this.hands.find('.card');
        // fade out each card
        this.tween.staggerTo(cards, 0.2, { opacity: 0 }, 0.2);
        // Render supporting text
        this.textContainer.html(this.html);
    };

}

Here are the cards I am trying to get: enter image description here

I am able to fetch them using the this.hands.find('.card'); jquery method (I can see them in the console), but I just can't animate them. I have tried animating different attributes (opacity, x, y, left, etc), but nothing happens - nothing moves on the screen.

I am able to do this.hands.find('.card').hide() and change the css using jQuery, but why TimelineLite doesn't work here? I also tried this approach:

var cards = this.hands.find('.card');
for (var i = cards.length - 1; i >= 0; i -= 1) {
    var card = cards[i];
    this.tween.to(card, 0.2, { opacity: 0 });
}

But still no success... The interesting thing is that when I attach an onComplete callback on the tweens, THEY ARE fired, but absolutely nothing moves on the screen. You can check out everything here.

Thanks for the help in advance, any suggestions are more then welcome.


原文:https://stackoverflow.com/questions/36835802
更新时间:2022-07-18 09:07

最满意答案

memset (operand, 0, 2 * 13);
memset (Result, 0, 15); memset (Result, 0, 15);


memset(operand, 0, 2 * 13);
memset(Result, 0, 15);

相关问答

更多
  • 它不会复制字符串。 您只需为指针copy分配字符串文字的地址,该地址也存储在original指针中。 两者都指向内存中的相同位置但具有不同的类型。 It does not copy the string. You just assign the pointer copy with the address of the string literal which address is also stored in the original pointer. Both point to the same plac ...
  • 当与算术运算符一起使用时,所有小整数类型( bool , char , short )在对它们执行任何算术之前都要进行整数提升 。 在a + 1表达式中, a被提升为int ,这意味着该表达式实际上被解释为(int) a + 1 。 char的范围在这里没有任何作用。 所有计算都在int域中执行,结果具有int类型。 127 + 1是128 ,这是你看到的打印。 你的++i被定义为i = i + 1 。 出于同样的原因,右侧计算为(int) i + 1 ,这意味着在这种情况下,添加也在int的域中执行。 稍 ...
  • 在printf语句中,您使用的是%d ,它会打印一个有符号整数 。 由于符号位已设置,输出正确。 将格式字符串更改为%u ,它将显示无符号整数值。 没有更多的符号位和您正在寻找的价值。 无论如何你应该使用unsigned int来进行samp 。 In your printf statement you are using %d, which prints a signed integer. The output is correct due to the sign bit being set. Chang ...
  • memset (operand, 0, 2 * 13); memset (Result, 0, 15); memset (Result, 0, 15); memset(operand, 0, 2 * 13); memset(Result, 0, 15);
  • 它抛弃了const 。 这意味着它会使你的程序崩溃,以防my_print修改该字符串,因为它的内存可能被标记为只读。 因此,通过const转换删除const修饰符通常是个坏主意。 在你的情况下,它看起来有点像实现my_print人不认为要打印的字符串永远不会被修改,因此不会使它接受const char *参数。 那么你应该做什么而不是my_print转换是改变my_print的定义来接受const char *而不是char *作为它的第一个参数。 It casts away the const. This ...
  • 你需要为new_fname和fname_base分配内存。 以下是你如何为new_fname做到这new_fname : new_fname = (char*)malloc((strlen(outdir)+1)*sizeof(char)); 在strlen(outdir)+1 ,+1部分用于为NULL CHARACTER '\0'终止符分配内存。 You need to allocate memory for new_fname and fname_base. Here's is how you woul ...
  • char*是指向char的指针, char **是指向char的指针。 char *ptr; 不为字符分配内存,它为指向char的指针分配内存。 char arr[10]; 分配10个字符, arr保存第一个字符的地址。 (尽管arr不是一个指针(不是char * ),而是char[10]类型) 用于演示: char *str = "1234556"; 就好像: char *str; // allocate a space for char pointer on the stack str ...
  • 你应该看看Boost :: DateTime 。 但是为了回答你的问题,在C ++中没有日期时间“处理” You should check out Boost::DateTime. But to answer your question there is no date time 'handling' as such in C++
  • 你需要使用移位,加上| 或|=运算符。 unsigned int ch3 = (ch1 << 6) | ch2; // ch3 = 0000010111010000 我在这里假设unsigned int是16位。 你的旅费可能会改变。 You need to use shifting, plus the | or |= operator. unsigned int ch3 = (ch1 << 6) | ch2; // ch3 = 0000010111010000 I'm assuming here th ...
  • 这段代码: aux = (unsigned char *) &len; buff[1] = aux[0]; buff[0] = aux[1]; 创建存储在len中的整数值的字节数组视图。 在Java中,你不能完全做同样的事情,但你可以通过几种方式获得你想要的东西。 最简单的就是使用位屏蔽和移位: int len = ...; byte[] buff = ...; byte[0] = (byte) (len & 0xff); byte[1] = (byte) ((len >> 8) & 0xff); 另一 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)