0

I am trying to add vertical movement to a list of stacked titles time I change page changes in FullPageJS. I get no error at all, but the action is not happing. My guess is that I am wrong trying to modify the CSS property transition using the element ref. Can anyone spot something wrong with the code below?

Thank you in advance.

React

  componentDidMount() {
    titleWidth = this.title.current.clientHeight
    titleHeight = this.title.current.clientHeight
    this.mask.current.css = {
      height: titleHeight + "px",
      width: titleWidth + "px",
    }
    this.frame.current.css = { top: titleHeight + "px" }
  }

  onLeave(origin, destination, direction) {
    console.log("Leaving section " + origin.index)

    // Actions not working
    if (direction == "down") {
      this.frame.current.style.transition = { top: "-=" + titleHeight }
    } else if (direction == "up") {
      this.frame.current.style.transition = { top: "+=" + titleHeight }
    }
  }

HTML

<div id="wrapper--frame" className="flex justify-center">
  <div ref={this.mask} id="mask" className="w-5/6 overflow-hidden">
    <div ref={this.frame} id="frame">
      <div ref={this.title} className="text-p frame--title ">
        One
      </div>
      <div ref={this.title} className="text-p frame--title ">
        Two
      </div>
      <div ref={this.title} className="text-p frame--title ">
        Three
      </div>
      <div ref={this.title} className="text-p frame--title ">
        Four
      </div>
    </div>
  </div>
</div>
3
  • Don't? Never set styles directly, add/toggle/remove CSS classes. If you're positioning elements based on other elements, you shouldn't need any JS calculations here, CSS layout should be more than enough. Commented Jan 30, 2021 at 19:26
  • How can I do that with CSS? I need to keep adding the height of the element to move the list. Any suggestion on how to do that? Commented Jan 30, 2021 at 19:34
  • It sounds like a job for a flexbox transtion (at the bottom of the article) Commented Jan 30, 2021 at 19:39

0

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.