Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript height reduced when clicked

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #38840
    JoeBass
    Member

    I could get a simple setInterval to work with opacity but cannot get it to work when reducing the height of an object when it is clicked. Any clues?

    #105788
    JoeBass
    Member

    Thanks for your replies guys but I am actually looking for a raw Javascript solution. Doing it with jQuery wasn’t a problem. I am just learning pure Javascript to up my chances at advancement within the companu I work for. What I currently have is:

    HTML:

    open box

    hola

    Javascript:
    var box1 = document.getElementById(“box”);
    var box2 = document.getElementById(“boxtop”);

    box2.offsetHeight;

    box1.onclick = function fade() {
    setInterval(function() {
    box2.style.height -= 20 + “px”;
    console.log(box2.offsetHeight);
    }, 200);
    }

    The console.log is in there to track the size as it subtracts over time but it just spits the set height, which is 200px. I got this to work with just opacity on the first try and the console.log displays lesser value overtime. Why wouldn’t work with height? Didn’t think there would be a difference.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.