Tailwind如何使旋转过渡效果生效?

huangapple go评论64阅读模式
英文:

Any way to make Tailwind rotate transition work?

问题

我正在尝试平滑旋转这个chevron-icon

<div
  class="w-[18px] ml-6 mr-2 text-slate-500 transition-all"
  :class="{ 'rotate-180': store.accountMenu }"
>
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
    <path
      fill="none"
      stroke="currentColor"
      stroke-linecap="round"
      stroke-linejoin="round"
      stroke-width="2"
      d="M20 6L10 16l10 10"
    />
  </svg>
</div>

通过使用tailwind的transition-all类和通过vue 3 condition有条件地应用的rotate-180类来实现。store.accountMenu只是一个带有布尔属性的导入的响应式函数。过渡效果仅在图标从右向左旋转回来时有效,而不是在初始从左向右旋转时。

英文:

I am trying to smoothly rotate this chevron-icon:

&lt;div
  class=&quot;w-[18px] ml-6 mr-2 text-slate-500 transition-all&quot;
  :class=&quot;{ &#39;rotate-180&#39;: store.accountMenu }&quot;&gt;
  &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; viewBox=&quot;0 0 32 32&quot;&gt;
    &lt;path
      fill=&quot;none&quot;
      stroke=&quot;currentColor&quot;
      stroke-linecap=&quot;round&quot;
      stroke-linejoin=&quot;round&quot;
      stroke-width=&quot;2&quot;
      d=&quot;M20 6L10 16l10 10&quot; /&gt;
  &lt;/svg&gt;
&lt;/div&gt;

by using the tailwind transition-all class and a rotate-180 class that gets applied conditionally via vue 3 condition. store.accoutnMenu is just an imported reactive function with a boolean property. The transition works but only when the icon rotates back from right to left, not when it is supposed to initially rotate left to right.

答案1

得分: 2

尝试添加 transform 类。

我创建了一个 codepen:

&lt;div
  class=&quot;w-[18px] ml-6 mr-2 text-slate-500 过渡-all 变换&quot;
  :class=&quot;{ &#39;rotate-180&#39;: store.accountMenu }&quot;&gt;
  &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; viewBox=&quot;0 0 32 32&quot;&gt;
    &lt;path
      fill=&quot;none&quot;
      stroke=&quot;currentColor&quot;
      stroke-linecap=&quot;round&quot;
      stroke-linejoin=&quot;round&quot;
      stroke-width=&quot;2&quot;
      d=&quot;M20 6L10 16l10 10&quot; /&gt;
  &lt;/svg&gt;
&lt;/div&gt;
英文:

Try adding the transform class.

I created a codepen:

&lt;div
  class=&quot;w-[18px] ml-6 mr-2 text-slate-500 transition-all transform&quot;
  :class=&quot;{ &#39;rotate-180&#39;: store.accountMenu }&quot;&gt;
  &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; viewBox=&quot;0 0 32 32&quot;&gt;
    &lt;path
      fill=&quot;none&quot;
      stroke=&quot;currentColor&quot;
      stroke-linecap=&quot;round&quot;
      stroke-linejoin=&quot;round&quot;
      stroke-width=&quot;2&quot;
      d=&quot;M20 6L10 16l10 10&quot; /&gt;
  &lt;/svg&gt;
&lt;/div&gt;

huangapple
  • 本文由 发表于 2023年5月11日 01:11:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221018.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定