animate CSS3 gradient-positions using jQuery

前端 未结 6 517
生来不讨喜
生来不讨喜 2021-01-01 04:58

Is it possible to animate the position of a CSS3-gradient-color using jQuery?

I\'d like to animate from this

background: -moz-linear-gradient(top, #F         


        
6条回答
  •  别那么骄傲
    2021-01-01 05:28

    what about animating the width of the container to which the gradient applies ?

    (example for Chrome with JQuery)

    html:

    css:

     #test 
     { 
          width:400px; height: 400px; float:left;           
          background: linear-gradient(90deg, #5e5e5e 0%, #000 100%);
     }
    

    js:

    $('#click_me').on('click',function () 
       { 
          $('#test').animate({'width':'+=400'},400); 
       } 
    );
    

    works a treat

    EDIT: I've made a mistake here as regards the original question. I am going to leave the answer here though as I think that by using more elements than just one the position of the fade could be moved about with the animate() function within a container div, creating the effect of the fade position sliding

提交回复
热议问题