Javascript / jQuery animation "Dangle"

I would like to create an animation in jQuery or the preferred pure javascript that makes the div “hang out”. I added an animated gif that shows the animation. I don't know how to do this if I can use existing jquery easing / animation to animate javascript + css or how. I also thought about canvas, but that would limit my ability to manipulate content, etc.

Dangeling animation

RESULT:

Thanks to @peirix for help with CSS animations. Here is the result I was hoping to achieve. http://jsfiddle.net/zeg61pb7/7/

CSS

#box {
   width:30px;
   height:30px;
   position:absolute;
   top:100px;
   left:100px; 
   text-indent: 90px;
   background-color:#aaaaaa;
    transform-origin: top center;
    -webkit-transform-origin: top center;
    -webkit-animation: dangle 2s infinite;
    -webkit-border-top-left-radius: 50%;
    -webkit-border-top-right-radius: 50%;
    -moz-border-radius-topleft: 50%;
    -moz-border-radius-topright: 50%;
    border-top-left-radius: 50%;
    border-top-right-radius: 50%;
}

#box:after {
    position: absolute;
    height: 5px;
    width: 5px;
    background: #aaaaaa;
    top: -4px;
    left: 12px;
    content: '';
    border-radius: 50%;
}

.dims {
    position: absolute;
    height: 10px;
    width: 10px;
    background: #aaaaaa;
    top: 125px;
    left: 110px;
    border-radius: 50%;
    -webkit-animation: movee 2s infinite;
}

@-webkit-keyframes dangle {
    0% { -webkit-transform: rotate(0deg); }
    5% { -webkit-transform: rotate(30deg); }
    10% { -webkit-transform: rotate(-28deg); }
    15% { -webkit-transform: rotate(26deg); }
    20% { -webkit-transform: rotate(-24deg); }
    25% { -webkit-transform: rotate(22deg); }
    30% { -webkit-transform: rotate(-20deg); }
    35% { -webkit-transform: rotate(18deg); }
    40% { -webkit-transform: rotate(-16deg); }
    45% { -webkit-transform: rotate(12deg); }
    50% { -webkit-transform: rotate(-10deg); }
    55% { -webkit-transform: rotate(8deg); }
    60% { -webkit-transform: rotate(-6deg); }
    65% { -webkit-transform: rotate(0deg); }
}

@-webkit-keyframes movee {
    9% { left: 110px; }
    10% { left: 120px; }
    15% { left: 100px; }
    20% { left: 114px; }
    25% { left: 106px; }
    30% { left: 113px; }
    35% { left: 107px; }
    40% { left: 111px; }
    45% { left: 109px; }
    50% { left: 110px; }
}
+4
source share
4 answers

. javascript. , , CSS. , . , , .

http://jsfiddle.net/zeg61pb7/3/

. -prefix webkit (, , ios, android ..), , . ( IE10 IE11 )

+7

css3.

Github.

, .

+1

Fiddle , . transit -Plugin jQuery.

var count = 0;
var deg = 45;
var minus = 5;
var interval = setInterval(function(){
    $ $('#box').transition({ 
        rotate: deg + 'deg',
        transformOrigin: 'center top'
    }).transition({ 
        rotate: '-'+deg+'deg',
        transformOrigin: 'center top'
    });
        if(count === 5){
            clearInterval(interval);
            $('#box').transition({ rotate: '0deg' })
        }
    if(deg > 10){
        deg = deg-(minus+5);
     }
    count++;
}, 300);

, . , .

0

, CSS3 , Javascript , , .

JSFiddle. . webkit -prefixes, moz ms.

  • animation-iteration-count: 1, , .
  • $.on('<prefix>animationStop'), . , .
0

All Articles