jQuery animating along a sine wave

前端 未结 6 1738
-上瘾入骨i
-上瘾入骨i 2021-01-20 01:02

I\'ve spent a couple days at this and I give up.

I\'m trying to get an object to animate along a sine wave infinitely. It should not end after the first period.

6条回答
  •  北海茫月
    2021-01-20 01:18

    Here's a solution (demonstrated in this fiddle) to making a Sinusoidal Wave just by using Jquery's four .animate parameters:

        $("div").animate({ left: [ '+=8%', 'linear' ],  
                           top:  [ '+=5%' , 'swing'  ]  }, 1000, null, function() {
            $(this).animate({ left: [ '+=8%', 'linear' ],  
                              top:  [ '-=5%' , 'swing'  ]  }, 1000, null, function() {
                $(this).animate({ left: [ '+=8%', 'linear' ],  
                                      top:  [ '+=5%' , 'swing'  ]  }, 1000, null, function() {
                    $(this).animate({ left: [ '+=8%', 'linear' ],  
                                          top:  [ '-=5%' , 'swing'  ]  }, 1000, null, function() {
    
                            //(etc.)
                    })                                                                                  
    
                })
            })
        })
    

提交回复
热议问题