【问题标题】:CSS3 fadeIn transistion not functioning on iOS devicesCSS3 fadeIn 转换在 iOS 设备上不起作用
【发布时间】:2015-12-30 04:16:27
【问题描述】:

试图获得以下似乎适用于桌面的内容,也适用于移动设备,但我看到的只是白色。所以淡入永远不会发生。这是我的 HTML:

<a href="https://thecleverroot.com/meet-your-makers-hudson-valley-foie-gras/" title="Folio: Meet Your Makers" class="feature-link">
<section class="feature fade-in one" style="background: linear-gradient( rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.35) ), url(https://thecleverroot.com/wp-content/uploads/header-hudson-valley-foie-gras.jpg ) no-repeat top center!important; background-size: cover!important;">
<section class="feature-caption"><p class="category-link">Growers</p><h2>Folio: Meet Your Makers </h2><p>Jenny Chamberlain, Chef of Product Development for Hudson Valley Foie Gras, Ferndale, NY</p><p class="read-more">Read</p></section></section>
</a>

这是 CSS:

.fade-in.one { -webkit-animation-delay: 1.25s; -moz-animation-delay: 1.25s; -o-animation-delay: 1.25s; animation-delay: 1.25s; }
.fade-in { opacity: 0; -webkit-animation: 1s ease-in 0s normal forwards 1 running fadeIn; -moz-animation: 1s ease-in 0s normal forwards 1 running fadeIn; -o-animation: 1s ease-in 0s normal forwards 1 running fadeIn; animation: 1s ease-in 0s normal forwards 1 running fadeIn; }
 body.home a.feature-link { text-decoration: none; }
.feature-caption h2 { font-size: 64px; line-height: .75em; margin: .25em 0; }
.category-link {
    background: #000;
    border-radius: 14px;
    display: inline-block;
    margin: 0;
    padding: 0 20px;
    min-width: 90px;
    height: 31px;
    line-height: 31px;
    color: #FFF;
    font-size: 14px;
    text-align: center;
    font-weight: 400;
    text-transform: uppercase;
}

代码笔:http://codepen.io/anon/pen/ojZXNy

【问题讨论】:

    标签: ios css css-animations


    【解决方案1】:

    我在 CodePen 上试过你的代码,但它也不能在桌面上运行(我在 Mac OS Yosemite 上测试了最新的 Chrome 和 Safari)。

    如果你想在 HTML 页面加载后淡入它的内容,你可以这样做:

    <!DOCTYPE html>
    <html>
        <head>
            <style type="text/css">
                .faded-out {
                    opacity: 0;
                }
                .fade-in {
                    opacity: 1;
                    transition: opacity 1s ease-in-out;
                    -moz-transition: opacity 1s ease-in-out;
                    -webkit-transition: opacity 1s ease-in-out;
                }
                #fadeInContainer {
                    background: url(https://thecleverroot.com/wp-content/uploads/header-hudson-valley-foie-gras.jpg);
                    padding: 60px;
                }
            </style>
            <script type="text/javascript">
                window.onload = function () {
                    document.getElementById("fadeInContainer1").className = "fade-in";
                    document.getElementById("fadeInContainer2").className = "fade-in"
                }
            </script>
        </head>
        <body>
            <a href="https://thecleverroot.com/meet-your-makers-hudson-valley-foie-gras/" title="Folio: Meet Your Makers" class="feature-link">
                <section id="fadeInContainer1" class="faded-out">
                    <h1>Content 1</h1>
                </section>
                <section id="fadeInContainer2" class="faded-out">
                    <h1>Content2</h1>
                </section>
            </a>
        </body>
    </html>
    

    有 2 个 CSS 类:.faded-out(在页面加载时隐藏内容)和fade-in(淡入内容)。

    最初,内容具有faded-out 类。加载页面时,我们将 CSS 类切换为 fade-in 以淡入内容。这是通过 javascript 完成的。

    编辑:我现在按照您评论中的要求淡入两个部分

    【讨论】:

    • 我不想在整个页面中淡入淡出。只是某些链接到文章的 div / 部分(它是一个新闻网站)。
    • 您也可以这样做。只需给每个部分一个唯一的 id 和“淡出”类,并按照我的回答中所述将每个部分的 CSS 类更改为“淡入”。
    • 我更新了我的答案,现在有 2 个部分会淡入
    • 似乎奏效了。必须对样式进行一些重新格式化(现在有点混乱,但在意料之中)。很遗憾,它必须包含 ID 而不仅仅是类。
    • 你可以改用document.getElementsByClassName("faded-out"),然后遍历元素,但是通过元素的id获取元素更可靠。
    猜你喜欢
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 2011-06-22
    • 2018-09-20
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    • 2015-02-02
    相关资源
    最近更新 更多