2

I'm using an angular js button, but i cant seem to use conventional css&js methods to put animations on it..i'm trying to implement an opacity animation on the button. can anyone please help?

HTML

<span id="sign_btn">
   <md-button>Button</md-button>
</span>

CSS:

#sign_btn{
-webkit-transition: opacity 0.2s ease-in-out;
-moz-transition: opacity 0.2s ease-in-out;
-o-transition: opacity .2s ease-in-out;
-ms-transition: opacity .2s ease-in-out;
transition: opacity .2s ease-in-out;
display:none;
opacity:0;
}

JS:

$("#sign_btn").css('display', 'block');
$("#sign_btn").css('opacity', '1');
6
  • Can you share the code that you are trying to get to work. Putting it in something like a jsfiddle will also help Commented Jul 13, 2016 at 9:01
  • It can be done, with transition css property Commented Jul 13, 2016 at 9:01
  • If possible share your Jsfiddle code .. Commented Jul 13, 2016 at 9:02
  • How do you try to apply the opacity exactly? Please post your code Commented Jul 13, 2016 at 9:03
  • you use transition, therefore, it should be trigger, like on hover event for instance. Commented Jul 13, 2016 at 9:06

3 Answers 3

1

You should use animation instead of transition.

First, create a custom animation

    @-webkit-keyframes opanimation {
          0% {
            opacity:0;
          }
          100% {
            opacity:1;
          }
    }
    @-moz-keyframes opanimation {
          0% {
            opacity:0;
          }
          100% {
            opacity:1;
          }
    }
    @-o-keyframes opanimation {
          0% {
            opacity:0;
          }
          100% {
            opacity:1;
          }
    }
    @keyframes opanimation {
          0% {
            opacity:0;
          }
          100% {
            opacity:1;
          }
    }

Then apply it to you element

#sign_btn {
   animation: opanimation 5s; //you can modify the seconds here
}

Check this fiddle https://jsfiddle.net/2up5y71k/

Sign up to request clarification or add additional context in comments.

7 Comments

how can i trigger the animation with js?
This will be triggered automatically (check fiddle). on this animation, the element will animate from 0 to 1 opacity. You can modify it according to what you want.
You should also remove the JS code you've posted in order for this to work.
i need to trigger the animation on an event, so i need the js code
On what event you want to trigger it?
|
0

Transitions only work for changes from one visible state to another. Your button is initially display:none; so the opacity change is not considered as a change in opacity from one state to another. Remove it (use other techniques like positioning, z-index, translate etc to achieve similar effect) and the transition should work.

1 Comment

@ShanzidS.Bidhan then it should be some other issue with your code. Please share a minimal reproducible example
0

found out the solution..

$("#sign_btn").delay(0).animate({"opacity": "1"}, 200);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.