简体   繁体   English

动画宽度从左到右(带文字)

[英]Animate width from left to right (with text)

I have text content with a 'wipe'-like transition, using jQuery to animate element width. 我有一个带有“擦拭”过渡的文本内容,使用jQuery来动画元素宽度。 This works fine when anchored to the left, as width is removed from the right side. 当锚定在左侧时,这可以正常工作,因为宽度从右侧移除。

See fiddle for simple example: https://jsfiddle.net/4jz7e0dw/5/ 请看小提琴的简单示例: https//jsfiddle.net/4jz7e0dw/5/

You can see in the fiddle, that when aligned left (red) the text stays still and the width animation trims it back from the right. 您可以在小提琴中看到,当左对齐(红色)时,文本保持静止,宽度动画从右侧向后修剪。 This is good. 这很好。

However, I now need this to work when aligned to the right. 但是,我现在需要在右边对齐时才能工作。

If I align everything right, the text stays anchored to the left of its element, and width is removed from the right (blue text block in fiddle). 如果我将所有内容对齐,文本将保持锚定在其元素的左侧,并且宽度将从右侧移除(小提琴中的蓝色文本块)。 This results in a sliding effect rather than the static 'wipe' effect I want. 这会产生滑动效果,而不是我想要的静态“擦拭”效果。 This is not good. 这个不好。

If I align to the right but use direction: rtl; 如果我向右对齐但使用direction: rtl; (like the green example), the 'wipe' effect works correctly, but the content of the elements is reversed. (如绿色示例),“擦除”效果正常工作,但元素的内容相反。 This is not good. 这个不好。

How can I have text right aligned and get the width to remove from the left (making the 'wipe' effect instead of a slide), without reversing the content order? 如何才能将文本右对齐并从左侧移除宽度(制作“擦除”效果而不是幻灯片),而不反转内容顺序? Basically I need the same effect as when aligned to the left (red), but mirrored (without mirroring content elements). 基本上我需要与左对齐(红色)时相同的效果,但镜像(不镜像内容元素)。

I was able to get the desired effect using a flex-box display. 我能够使用柔性盒显示器获得所需的效果。

Here is the fiddle: https://jsfiddle.net/4jz7e0dw/11/ 这是小提琴: https//jsfiddle.net/4jz7e0dw/11/

By using direction: rtl in combination with flex-direction: row-reverse in the child, the list keeps the original order of elements. 通过使用direction: rtl结合flex-direction: row-reverse ,列表保持元素的原始顺序。

A simple solution would be to put all of the content into a single <li> instead of seperate ones. 一个简单的解决方案是将所有内容放入单个<li>而不是单独的内容中。

<div class="container slide-right rtl">
  <ul id="target3" class="slide">
  <li>CLICK THIS TO DEMO</li>
  </ul>
</div>

If for whatever reason you do need multiple items, another solution would be to simply reverse the order of the elements in your HTML 如果由于某种原因您需要多个项目,另一种解决方案是简单地颠倒HTML中元素的顺序

Try adding this 尝试添加此功能

.slide {
...
unicode-bidi: plaintext;
}

I forked a fiddle: https://jsfiddle.net/am87yhp9/ 我分道扬琴: https//jsfiddle.net/am87yhp9/

Is this the effect you want to achieve? 这是你想要达到的效果吗?

Manipulating the Margin property, and changing the direction from rtl -> ltr. 操纵Margin属性,并从rtl - > ltr改变方向。

JQ: JQ:

jQuery('.slide').click(function(){
    var width = this.clientWidth;
    $(this).animate({ 'width': 0, "marginRight": width}, 1500);
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM