简体   繁体   English

iPhone .scrollTo()无法正确呈现屏幕

[英]iPhone .scrollTo() not rendering screen properly

I have created an angularJS and Phonegap app with a fixed navbar and footer which sit outside the ui-view. 我创建了一个angularJS和Phonegap应用,其中的固定导航栏和页脚位于ui视图之外。 Like such. 像这样

<div class="topcoat-navigation-bar">
  // Contents of navigation bar
</div>
<div class="main" ui-view="main"></div>
<div class="topcoat-button-bar button-bar-footer">
  // Contents of footer 
</div>

Templates are loaded into the ui-view depending on the state. 根据状态将模板加载到ui视图中。 In the device template I have this div which has a big list of devices. 在设备模板中,我有这个div,其中包含大量设备。 This list is scrollable. 该列表是可滚动的。

<div class="device-container" scrollRecord scrollTo>
   //list of devices
</div>

Here is the css for this container 这是此容器的CSS

.device-container {
  position: absolute;
  width: 100%;
  top: 0;
  bottom: 0;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  -webkit-transform: translate3d(0px, 0px, 0px);
  clear: both;
}

What I wanted is while scrolling down the list the app stores the location of the scroll. 我想要的是在向下滚动列表时,应用程序存储滚动的位置。 When you close the app and open it again it opens to the same scroll position. 当您关闭应用程序并再次打开它时,它会打开到相同的滚动位置。 So I made these directives to record the scroll position and then match the position when the screen is loaded again. 因此,我制定了这些指令来记录滚动位置,然后在再次加载屏幕时匹配滚动位置。

    .directive('scrollRecord', function () {
            return {
                restrict: 'A',
                link: function (scope, element, attrs) {

                    angular.element(element).bind("scroll", function () {
                        var element_top = $(element).scrollTop();
                        localStorage.setItem('devicesScrollPosition', JSON.stringify(element_top));

                    });


                }
            };
        })  
  .directive('scrollTo', function ($anchorScroll, $timeout, $location) {
            return {
                restrict: 'A',
                link: function (scope, element, attrs) {
                    var scrollPost = JSON.parse(localStorage.getItem('devicesScrollPosition'));
                    $timeout(function () {
                        $(element).scrollTop(scrollPost);               
                    });
                }

            };
        })

This is working 100% on Android however on iPhone the screen scrolls to the position but doesn't draw the contents until you touch the screen. 这在Android上可以100%运行,但是在iPhone上,屏幕会滚动到该位置,但是直到您触摸屏幕后才绘制内容。 I have tried numerous fixes ranging from using $(window) to record to trying to trigger a touch event and even adding div s and removing them on load of the screen. 我尝试了许多修复程序,从使用$(window)进行记录到尝试触发触摸事件,甚至添加div并在屏幕on load上将其删除均已修复。

Use window.scrollTo(0.0); 使用window.scrollTo(0.0); immediately when the screen is loaded. 屏幕加载后立即显示。

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

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