1

This is my first question on stackoverflow.

Wondering if anyone can point me to a solution/resource on animating buttons using JS/JQuery.

Particularly, the animation I can't figure out is spinning a circular button 180 degrees on hover.

Thanks :)

protoEvangelion
  • 4,355
  • 2
  • 29
  • 38

3 Answers3

1

You can use css keyframes

div {
    width: 100px;
    height: 100px;
    background: red;
    position :relative;
    -webkit-animation: mymove 1s infinite; /* Chrome, Safari, Opera */
    animation: mymove 1s infinite;
}


/* Standard syntax */
@keyframes mymove {
       from   {    transform: rotateY(0deg);}
to { transform: rotateY(360deg);

}
Piyush.kapoor
  • 6,715
  • 1
  • 21
  • 21
  • Thanks! Is there a way to have it spin 180 degrees on hover and then when pointer is moved off of element, have it spin back? Right now it spins back and forth on hover. – protoEvangelion Jun 28 '16 at 15:52
1

you can animate buttons using CSS. At http://www.w3schools.com/css/css3_animations.asp you can learn about CSS animations. You may also want to learn about CSS transitions at http://www.w3schools.com/css/css3_transitions.asp. If you what to create an animation using JS what you would do is set a CSS transition on the HTML element that you want to animate and then use JS to set CSS properties like background-color and transform. You can access the CSS of an element using element.style.property. replace property with the property you want to change or add.

Mr. Rar
  • 11
  • 1
1

The most intuitive answer I found was this:

  <div class="flip-container" ontouchstart="this.classList.toggle('hover');">
    <div class="flipper">
        <div class="front">
            <!-- front content -->
        </div>
        <div class="back">
            <!-- back content -->
        </div>
    </div>
</div>

    /*CSS entire container, keeps perspective */
.flip-container {
    perspective: 1000px;
}
    /* flip the pane when hovered */
    .flip-container:hover .flipper, .flip-container.hover .flipper {
        transform: rotateY(180deg);
    }

.flip-container, .front, .back {
    width: 320px;
    height: 480px;
}

/* flip speed goes here */
.flipper {
    transition: 0.6s;
    transform-style: preserve-3d;

    position: relative;
}

/* hide back of pane during swap */
.front, .back {
    backface-visibility: hidden;

    position: absolute;
    top: 0;
    left: 0;
}

/* front pane, placed above back */
.front {
    z-index: 2;
    /* for firefox 31 */
    transform: rotateY(0deg);
}

/* back, initially hidden pane */
.back {
    transform: rotateY(180deg);
}

Further explanation can be found here: https://davidwalsh.name/css-flip

protoEvangelion
  • 4,355
  • 2
  • 29
  • 38