最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

css - Why doesn't transition-duration work on this view transition? - Stack Overflow

matteradmin6PV0评论

This is working, but the duration setting is ignored. What am I missing?

/

function onClick(e) {
  e.target.classList.add('clicked_media_transition')
  document.startViewTransition(() => {
    e.target.classList.add('expand')
  })
}
body {
  margin: 0;
}

div {
  width: 300px;
  height: 300px;
  background-color: pink;
  position: absolute;
}

.expand {
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
}

::view-transition-group(clicked_media_transition) {
  transition-duration: 5s;
  transition-timing-function: ease-out;
}

.clicked_media_transition {
  view-transition-name: clicked_media_transition;
}
<div onclick="onClick(event)"></div>

This is working, but the duration setting is ignored. What am I missing?

https://jsfiddle/r76z0o8s/

function onClick(e) {
  e.target.classList.add('clicked_media_transition')
  document.startViewTransition(() => {
    e.target.classList.add('expand')
  })
}
body {
  margin: 0;
}

div {
  width: 300px;
  height: 300px;
  background-color: pink;
  position: absolute;
}

.expand {
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
}

::view-transition-group(clicked_media_transition) {
  transition-duration: 5s;
  transition-timing-function: ease-out;
}

.clicked_media_transition {
  view-transition-name: clicked_media_transition;
}
<div onclick="onClick(event)"></div>

Share Improve this question edited Nov 18, 2024 at 21:46 Daniel Beck 21.5k5 gold badges43 silver badges60 bronze badges asked Nov 18, 2024 at 21:43 JorenJoren 9,94520 gold badges67 silver badges106 bronze badges 1
  • @Yogi you're right! You should post that as the answer. – Joren Commented Nov 18, 2024 at 22:06
Add a comment  | 

1 Answer 1

Reset to default 2

As mentioned by @Yogi:

Changing transition-duration: 5s; to animation-duration: 5s; seems to work.

In general, transition-duration is used between two distinct states (start/end), while animation-duration involves a sequence of keyframes. When you're trying to trigger the animation on click, the use of animation-duration should be used.

Post a comment

comment list (0)

  1. No comments so far