0

I'm writing a Firefox extension, and one of the features is to be able to add an extra "row' of icons in the interface. I'm doing this using a combination of CSS and JavaScript, but I'm getting a weird issue if I click too quickly on the "expand" or "contract" button, where it's adding a random amount of pixels to the height. I think it's because it's getting the height from the css, and while it's transitioning, it has a "growing" height, so it does the JS equation with the wrong height.

CSS:

#wrapper {
    background: rgba(0,0,0,.85);
    box-shadow: 0px 0px 5px #000;
    color: #fff;
    height: 100px;
    width: 250px;
            -moz-transition: height 1s;
}

JavaScript:

function expand() {
            var orig = document.getElementById("wrapper").clientHeight;
            if (orig < 300) {
                var changed = orig + 100;
                document.getElementById("wrapper").style.height=changed;
                // debug
                document.getElementById("print").innerHTML="height: " + changed + "px";
                // end debug
            } else {
                // do nothing
            }
        }
        function contract() {
            var orig = document.getElementById("wrapper").clientHeight;
            if (orig > 100) {
                var changed = orig - 100;
                document.getElementById("wrapper").style.height=changed;
                // debug
                document.getElementById("print").innerHTML="height: " + changed + "px";
                // end debug
            } else {
                // do nothing
            }
        }

HTML:

<div id="wrapper">
    <a onclick="expand()">Exand Div</a> - <a onclick="contract()">Contract Div</a><br />
    <span id="print">height: 100px</span>
</div>
3
  • 1
    Can you elaborate on what the weird issue is? Commented Apr 14, 2011 at 1:14
  • ahh sorry thought i edited it, must not've clicked save... Commented Apr 14, 2011 at 1:20
  • What version of Firefox does one have to be using for this to work? I don't see any problem... or any 'transition' either. Commented Apr 14, 2011 at 1:59

1 Answer 1

1

The transitionend event could be the solution here.

Just disable your onclick handlers once clicked, then re-enable when the transitionend fires.

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

1 Comment

Mind giving me a code snippet to look at? I'm pretty new at JS ^^;

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.