简体   繁体   English

我如何模仿这种旋转的文字效果?

[英]How can I mimic this rotating text effect?

I am working on a new project, and I would like to learn how to emulate the text effect on this site 我正在研究一个新项目,我想学习如何在此站点上模拟文本效果

http://papertiger.com/ http://papertiger.com/

I am familiar with CSS transform involved rotating the text up, what I haven't figured out yet is how they have different text fields (as in, how do they set it to where it cycles through the different words) 我熟悉CSS转换所涉及的向上旋转文本,但我还没有弄清楚它们是如何具有不同的文本字段的(例如,如何将其设置为在不同的单词之间循环的位置)

Because the text changes every few seconds, it makes it challenging to inspect the element, and my attempts at searching for a solution have not been fruitful. 由于文本每隔几秒钟更改一次,因此检查该元素很有挑战性,而我寻找解决方案的尝试并未取得成果。

I don't need this solved necessarily. 我并不需要解决这个问题。 If someone could point me in the direction of a tutorial that covers the base functionality of how they cycle through the different words, It would be greatly appreciated. 如果有人能指出指导我的方向,该指南涵盖了他们如何循环使用不同单词的基本功能,将不胜感激。 Thanks! 谢谢!

You can achieve this using CSS3. 您可以使用CSS3来实现。

  • Rotate (x-axis) the element that holds the word (for example a div) 旋转(x轴)包含单词的元素(例如div)
  • When the element is rotated by 90 degrees then change the elements value to another word 元素旋转90度后,将元素值更改为另一个单词
  • Rotate the element back to 0 degrees 将元素旋转回0度

Demo: http://jsfiddle.net/DerekL/8ZLTc/ 演示: http//jsfiddle.net/DerekL/8ZLTc/

在此处输入图片说明

I believe this is the effect you are going for. 我相信这就是您想要的效果。

This is <div>
    <h3 class="front">FRONT</h3>
    <h3 class="back">BACK</h3>
</div>.
h3 {
    position: absolute;
    margin: 0;
    padding: 0;
    color: #ff4056;
    cursor: pointer;
}
div {
    position: relative;
    display: inline-block;
    width: 170px;
    height: 50px;
    margin: 0;
    padding: 0;
}
.front {
    z-index: 2;
}
body > * {
    vertical-align: text-bottom;
}

* Suggested JavaScript: ( Transit.js is used for better readability. And jQuery too.) *建议的JavaScript :(使用Transit.js具有更好的可读性。还有jQuery。)

$(".back").css({
    rotateX: '-180deg'
});

var words = [
    "useful", "interesting", "lorem", "ipsum",
    "stack", "overflow", "easter", "eggs"],
    angle = 0;

setInterval(function (){
    angle += 180;
    $('div').transition({
        perspective: '150px',
        rotateX: '+=180deg'
    }, 1000);

    var currentB = "." + ((angle / 180) % 2 ? "front" : "back"),
        current = "." + ((angle / 180) % 2 ? "back" : "front");
    $(current).html(words[(Math.random() * 8) | 0]);
    $("div").transition({
        width: $(current).width(),
        height: $(".front").height()
    });
}, 1000);

This works on all modern browsers, except IE. 这适用于除IE之外的所有现代浏览器。

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

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