1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Is it possible to remove the button

Discussion in 'JavaScript' started by peter_r, May 11, 2015.

  1. #1
    Hi.

    In the following url you can see a transition on javascript and css.

    http://xahlee.info/js/js_fadeout_css_transition.html

    The button "Face" turns the opacity from 1 to 2, removing the star from sight.

    The issue is that I would like also to fade the button itself.

    Is it possible?

    Thanks very much.
     
    peter_r, May 11, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    No, it changes the opacity from 1 to 0 - the opacity "scale" only goes from 0 to 1. There is no 2.
    And yes, of course it's possible to fade the button as well - I'm assuming you want to fade away the button which isn't really usable? Ie, fading away "Fade" when the star is hidden, and fading away "Unfade" when the star is shown? Or are you after something else?
    But, yes, it's of course possible, just attach the same event to the container for the button you want to fade.
     
    PoPSiCLe, May 11, 2015 IP
  3. rehan.khalid.9235

    rehan.khalid.9235 Active Member

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    85
    #3
    ok, here it is, i updated your script. i added 2 functions showBtn() and hideBtn() and call them in fade() and unfade()

    <script>
                var star = document.getElementById("id66259");
                star.style.opacity = 1;
                star.style.transition = "opacity 1s";
    
                var button1 = document.getElementById("b1");
                var button2 = document.getElementById("b2");
    
                function fade() {
                    star.style.opacity = 0;
                    hideBtn("b1");
                    showBtn("b2");
                }
    
                function unfade() {
                    star.style.opacity = 1;
                    hideBtn("b2");
                    showBtn("b1");
                }
              
                function hideBtn(id){
                    var button = document.getElementById(id);
                    button.style.display='none';
                }
                function showBtn(id){
                    var button = document.getElementById(id);
                    button.style.display='block';
                }
    
                button1.addEventListener("click", fade, false);
                button2.addEventListener("click", unfade, false);
            </script>
    Code (markup):
    and 1 change in HTML: (hide UnFade by default)
    <button id="b2" style="display:none">UnFade</button>
    Code (markup):
     
    rehan.khalid.9235, May 12, 2015 IP