3

我一直在使用 PhoneGap/Cordova 构建 Web 应用程序,并且运行良好。

这些应用程序由一系列幻灯片组成,用户可以通过滑动来查看下一张幻灯片。我一直在使用 idangero swiper 来完成此操作。

一旦我尝试扩展我的应用程序以包含更多幻灯片,应用程序就会崩溃并在 XCODE 上显示内存警告。我将其缩小到 CSS3 中的硬件加速(如下)。在不崩溃的情况下,我可以拥有的最大幻灯片数是 22。一旦我添加了第 23 个,我就会收到内存警告并崩溃。

我将其进一步缩小到

.swiper-slide {
    background-color: #fff;

    -webkit-transform-style: preserve-3d;
    -webkit-transform: translate3d(0,0,0);
  }

当我从下面的 css 中删除两个 webkit-transforms 时,应用程序编译并运行,但第一页有白屏闪烁,并且像 slideToggle 这样的简单下拉动画变得紧张。

idangero css

.swiper-container {
    margin:0 auto;
    position:relative;
    overflow:hidden;
    height: 768px;
    width: 1024px;
    z-index:1;

}

.swiper-slide {
    background-color: #fff;

    -webkit-transform-style: preserve-3d;
    -webkit-transform: translate3d(0,0,0);
  }

.swiper-wrapper {
    position:absolute;
    width: 100%;
    -webkit-transition-property:-webkit-transform, left, top;
    -webkit-transition-duration:0s;
    -webkit-transition-timing-function:ease;

    -moz-transition-property:-moz-transform, left, top;
    -moz-transition-duration:0s;
    -moz-transform:translate3d(0px,0,0);
    -moz-transition-timing-function:ease;

    -o-transition-property:-o-transform, left, top;
    -o-transition-duration:0s;
    -o-transform:translate3d(0px,0,0);
    -o-transition-timing-function:ease;
    -o-transform:translate(0px,0px);

    -ms-transition-property:-ms-transform, left, top;
    -ms-transition-duration:0s;
    -ms-transform:translate3d(0px,0,0);
    -ms-transition-timing-function:ease;

    transition-property:transform, left, top;
    transition-duration:0s;
    transform:translate3d(0px,0,0);
    transition-timing-function:ease;


    transform: translate3d(0%,0,0) scale3d(1,1,1);
    -o-transform: translate3d(0%,0,0) scale3d(1,1,1);
    -ms-transform: translate3d(0%,0,0) scale3d(1,1,1);
    -moz-transform: translate3d(0%,0,0) scale3d(1,1,1);
    -webkit-transform: translate3d(0%,0,0) scale3d(1,1,1);
    overflow: hidden;
    -webkit-backface-visibility: hidden;
    -webkit-transform-style: preserve-3d;


}

.swiper-free-mode > .swiper-wrapper {
    -webkit-transition-timing-function: ease-out;
    -moz-transition-timing-function: ease-out;
    -ms-transition-timing-function: ease-out;
    -o-transition-timing-function: ease-out;
    transition-timing-function: ease-out;
    margin: 0 auto;

}
.swiper-slide {
    float: left;
}

/* IE10 Windows Phone 8 Fixes */
.swiper-wp8-horizontal {
    -ms-touch-action: pan-y;
}
.swiper-wp8-vertical {
    -ms-touch-action: pan-x;
}

2“幻灯片”的示例 html

<div class="swiper-container">
            <div class="swiper-wrapper">

                <!-- Home (Page 1) = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
                <div id="home" class="swiper-slide" rel="bkg-home.jpg">
                    <div class="page">
                        <h1>TEXt HErE</h1>   
                        <h3>Header 3</h3>
                    </div><!-- /page -->
                </div><!-- /home -->

                <!-- Page 2 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =  -->
                <div id="p2" class="swiper-slide" rel="bkg-2.jpg">
                    <div class="page">
                        <div class="menu-trigger"></div>
                        <h1 style="padding-top:17px;">MORE TITLES</h1> 
                        <div class="content">
                            <div id="table-of-contents">
                                <ul>
                                     <li><a href="#p3">Issue Overview </a></li>
                                     <li><a href="#p4">Content1</a></li>
                                     <li><a href="#p6">Content2</a></li>
                                     <li><a href="#p30">Content3</a></li>
                                     <li><a href="#p17">Content4</a></li>
            </ul>
                                </ul>
                            </div><!-- /table-of-contents -->

                        </div><!-- /content -->
                        <div class="header"></div><!-- /header -->
                        <div class="footer"></div><!-- /footer -->
                        <div class="footer-segment"></div><!-- /footer-segment -->
                    </div><!-- /page -->
                </div><!-- /p2 -->
       </div>
</div>

所以看来我需要硬件加速 CSS3 才能使应用程序顺利运行,但它似乎也导致了崩溃。有没有人可以解决代码让我的应用程序顺利运行但不会导致整个应用程序崩溃?

4

1 回答 1

1

我会尝试两种不同的东西。

1will-change

据说硬件加速的未来是新的will-changecss 属性。

https://dev.opera.com/articles/css-will-change-property/

.swiper-slide {
  background-color: #fff;
  -webkit-transform-style: preserve-3d;
  /* -webkit-transform: translate3d(0,0,0); */
  will-change: transform, top, left;
}

2 transforms 比使用topand定位更便宜left

我不知道您到底在哪里使用transitionontopleft,但我会尝试用,或替换top/ 。lefttranslateX()translateY()translate()

于 2014-10-01T02:53:45.857 回答