以编程方式更改scrollTop后固定定位按钮上的移动Safari错误...?

发布于 2024-12-25 10:45:13 字数 880 浏览 5 评论 0原文

我刚刚完成一个网页,但 Mobile Safari(iPhone 和 iPad iOS 5.0.1)中有一个错误,有两个按钮固定在右上角和右下角。

这些按钮只有在单击提交后才会淡入在打开页面其余部分的文本框中...加载页面其余部分并且按钮淡入后,您可以单击其中任何一个,它们都可以工作...

但是,单击它们会导致程序化滚动,滚动完成后您将无法再单击在任一按钮上,直到您用手指实际滚动页面,即使只是一个很小的像素滚动...

我注意到的是,在程序化滚动之后,如果您点击“顶部”按钮稍下方,您会看到突出显示,就好像您我们点击底部按钮并处理底部按钮的操作,这告诉我错误是,当以编程方式滚动时,固定位置按钮仍然与页面的其余部分一起移动,并且不会返回到其固定位置,直到实际执行触摸滚动......

有谁知道绕过这个..?

我添加了一个弹出窗口,显示按下了哪个按钮,以便您可以对其进行测试,请记住,在第一次按下向下按钮(有效)后尝试再次按下,它将不起作用,但是单击向上按钮下方,然后您会看到发生向下按钮操作...

http://www.tsdexter.com/ceos

感谢您的帮助。

托马斯

(如果你能指出我可以在哪里向苹果提交错误,那也很好,除非已经有人提交过)

编辑:只需单击任一提交箭头,您不需要输入工资/工资它有默认值

编辑2:这是一个更简单的例子来显示相同​​的问题..

http://www.tsdexter.com/MobileSafariFixedPosBug.html

编辑 3:向 Apple 报告的错误

I'm just about done a webpage but there is one bug in Mobile Safari (iPhone and iPad iOS 5.0.1) with two buttons that are fixed to the upper and lower right corners..

The buttons are not faded in until after clicking submit on a textbox which opens up to the rest of the page... After the rest of the page is loaded and the buttons are faded in you can click on either of them and they both work...

However, clicking them causes a programmatic scroll and after that scroll is complete you can no longer click on either of the buttons until you physically scroll the page with your finger even just a tiny one pixel scroll...

What I have noticed is that after the programmatic scrolling if you tap just slightly below the TOP button you see the highlight as if you were tapping the BOTTOM button and the action of the bottom button is processed, which tells me the bug is that when scrolling programmatically the fixed position button still moves with the rest of the page and doesn't go back to it's fixed position until an actual touch scroll is performed....

Does anyone know a way around this..?

I've added a popup that shows which button was pressed so you can test it, remember after the first press of the down button (which works) trying pressing down again, it won't work, but click just below the up button and you'll see the down button actions happening....

http://www.tsdexter.com/ceos

thanks for the help.

Thomas

(also if you can point me to where I can submit a bug to Apple that'd be good too, unless one already has been)

EDIT: just click either of the submit arrows, you don't need to enter a wage/salary it has defaults

EDIT 2: Here is a simpler example to show the same issue..

http://www.tsdexter.com/MobileSafariFixedPosBug.html

EDIT 3: Bug reported to Apple

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

养猫人 2025-01-01 10:45:13

我们还在 2 个不同的 iPad 应用程序上遇到了这个错误,对我们来说,最好的解决方法是在动画滚动完成后暂时从固定元素中删除固定位置,然后使用 window.scroll 和我们刚刚执行动画的垂直值滚动到,然后最后重新应用位置固定样式。当 ipad 重新渲染元素时,它确实会导致一个非常小的问题,但它比 bug 更可取。

var $fixedElement = $('#fixedNavigation');
var topScrollTarget = 300;
$("html:not(:animated),body:not(:animated)").stop().animate({ scrollTop: topScrollTarget }, 500, "swing", function(evt) {
    $fixedElement.css({ "position": "relative" });
    window.scroll(0, topScrollTarget );
    $fixedElement.css({ "position": "fixed" });
});

We also encountered this bug on 2 different iPad applications, for us the best fix was to temporarily remove the fixed position from the fixed element once the animated scroll had finished, then use window.scroll with the vertical value we’d just performed the animated scroll to, then finally re-apply the position fixed style. It does cause a very minor blip as the ipad re-renders the element but its preferable to the bug.

var $fixedElement = $('#fixedNavigation');
var topScrollTarget = 300;
$("html:not(:animated),body:not(:animated)").stop().animate({ scrollTop: topScrollTarget }, 500, "swing", function(evt) {
    $fixedElement.css({ "position": "relative" });
    window.scroll(0, topScrollTarget );
    $fixedElement.css({ "position": "fixed" });
});
弃爱 2025-01-01 10:45:13

我通过添加 101% 高 div 然后(几乎)立即删除它来解决这个问题。

尝试:

<style>
.iosfix {
  height: 101%;
  overflow: hidden;
}
</style>

当你滚动时:

window.scrollTo(0, _NEW_SCROLLTOP_);
$('body').append($('<div></div>').addClass('iosfix'));
setTimeout(function() {
  $('.iosfix').remove();
}, 500);

它也适用于 jQuery.scrollTo。

请参阅此处的示例。

I got around it by adding a 101% high div then (almost) immediately removing it.

Try:

<style>
.iosfix {
  height: 101%;
  overflow: hidden;
}
</style>

and when you scroll:

window.scrollTo(0, _NEW_SCROLLTOP_);
$('body').append($('<div></div>').addClass('iosfix'));
setTimeout(function() {
  $('.iosfix').remove();
}, 500);

It also works with jQuery.scrollTo.

See an example here.

听,心雨的声音 2025-01-01 10:45:13

我在单独的固定元素上有多个链接(模态弹出窗口 + 固定黑屏 div + 正常固定工具栏),但这些答案都不起作用,所以我对尝试同一主题的变体进行了修补。就像所有这些表明的那样,关键是重新渲染元素。

最初我尝试将 1px 添加到固定元素的宽度并将其删除。这确实导致了重新渲染,但是重新渲染的元素与非重新渲染的元素没有对齐——我怀疑这是这个 iOS bug 的另一个结果。答案是简单地添加主体的宽度并再次减去(或设置为自动),即:

//jQuery will calculate the current width and then +1 to this and set it
$('body').css('width', '+=1');

//Remove width css
setTimeout(function() {
  $('body').css('width', '');
}, 1);

如果不使用jquery,您将需要获取主体的当前宽度+1px,然后设置宽度。

I had multiple links on separate fixed elements (a modal popup + fixed blackout div + normal fixed toolbar) and none of these answers were working so I had a tinker about trying variations on the same theme. Like all these suggest the key is getting elements re-rendered.

Initially I tried adding 1px to the width of fixed elements and removing it. This did cause re-rendering, but re-rendered elements became mis-aligned with non re-rendered elements - another result of this iOS bug I suspect. The answer was to simply add to the width of the body and subtract again (or set to auto), ie:

//jQuery will calculate the current width and then +1 to this and set it
$('body').css('width', '+=1');

//Remove width css
setTimeout(function() {
  $('body').css('width', '');
}, 1);

If not using jquery you will need to get the current width of body +1px to it and then set the width.

寄人书 2025-01-01 10:45:13

如果像我一样,以前的解决方案都不适合您,那么这是我的解决方案。

技巧是:

  • 进行滚动(Animate或scrollTo等)
  • 在滚动之后,位置:绝对固定元素
  • 在“touchmove”事件上,恢复位置:固定

这里是一个例子:

  $('body').animate({
       scrollTop: newPos}, 1000, 'jswing', function () {
          $('header').css({position:'absolute', top:newPos});
  });

  $(document).bind('touchmove',function(){
       $('header').css({position:'fixed', top:'0px'});
  });   

我对粘性页脚使用了相同的技巧和其他浮动固定元件。

Here is my solution if like me, none of the previous solution is working for you.

The trick is:

  • Do your scroll (Animate or scrollTo, etc.)
  • Just after your scroll, position:absolute your fixed elements
  • On the 'touchmove' event, restore the position:fixed

Here an example:

  $('body').animate({
       scrollTop: newPos}, 1000, 'jswing', function () {
          $('header').css({position:'absolute', top:newPos});
  });

  $(document).bind('touchmove',function(){
       $('header').css({position:'fixed', top:'0px'});
  });   

I used the same trick for sticky footer and other floating fixed elements.

猛虎独行 2025-01-01 10:45:13

这个方法的一个变体也对我有用。尽量不在移动设备上使用框架。

    var d = document.createElement("div");
    d.style.height = "101%";
    d.style.overflow = "hidden";
    document.body.appendChild(d);
    window.scrollTo(0, scrollToM);
    setTimeout(function() {
        d.parentNode.removeChild(d);
    }, 10);

A variation of this worked for me as well. Trying to not use frameworks where I can on mobile.

    var d = document.createElement("div");
    d.style.height = "101%";
    d.style.overflow = "hidden";
    document.body.appendChild(d);
    window.scrollTo(0, scrollToM);
    setTimeout(function() {
        d.parentNode.removeChild(d);
    }, 10);
绝情姑娘 2025-01-01 10:45:13

花了几个小时后,我找到了一个解决方法:尝试滚动(可能有动画),然后再次滚动到同一点(没有动画)。
通过这种方式,您可以强制浏览器从视图中删除错误的渲染。

例子:

$('body, html')
    .animate({scrollTop: 0})
    .scrollTop(0);

After spending a couple of hours on this, I found a workaround: try scrolling (maybe with an animation) and then scrolling again to the same point (without animation).
This way you force the browser to delete the wrong rendering from the view.

Example:

$('body, html')
    .animate({scrollTop: 0})
    .scrollTop(0);
穿越时光隧道 2025-01-01 10:45:13

我在 iOS5 和 JQueryMobile 上遇到了同样的问题。固定标题和页脚。可扩展的内容,突然我有一个幽灵页脚,你可以看到但不能触摸。
我在直接将位置更改为绝对位置然后返回工作时遇到了一些问题。它似乎只在某些时候有效。
我最终用了这个。

        $(myFixedFooter).css("position", "relative").hide(0, function () {
            $(this).show(0).css("position", "");
        });

当页脚执行其操作时,这无疑会产生一个“昙花一现”。然而我发现大约 98% 的时间页脚停留在页面底部。我发现和尝试的所有其他解决方法和调整并不总是将页脚留在底部,或者它们一开始就没有解决问题。

希望苹果能尽快修复。

I was having the same problem with iOS5 and JQueryMobile. Fixed Header & Footer. Expandable content and suddenly i had a ghost footer that you could see but not touch.
I had a bit of a problem getting a straight change position to absolute then back to work. It seemed to only work some of the time.
I ended up using this.

        $(myFixedFooter).css("position", "relative").hide(0, function () {
            $(this).show(0).css("position", "");
        });

This defiantly creates a "blip" as the footer does its thing. Hoever i found that some 98% of the time the footer stayed at the bottom of the page. All the other work arounds and tweaks i found and tried didn't always leave the footer at the bottom or they didn't solve the problem in the first place.

Hopefully Apple will fix soon.

迷爱 2025-01-01 10:45:13

我在我正在编写的 iPhone 应用程序中发现了您所描述的确切行为。我加载了一堆 HTML 文本,右侧有一个索引。从菜单中选择一个项目并滚动文本后,菜单将变得无响应(因为着陆区域已从其下方滚动出来)。我还发现,即使是很小的文本滚动也会重新启用索引菜单。

我创建了一个测试用例并在此处上传了文件(如果您在非 iPhone 浏览器上查看此文件,请垂直缩小窗口以查看正确的行为):

http://www.misterpeachy.com/index_test.html

我发现索引菜单随着文本滚动(即使可见菜单没有移动)我点击了 B 然后再次点击B。它没有滚动到 B(基本上不动),而是滚动到 D。

现在我被卡住了。我希望我可以添加一些 JavaScript 代码(我从来没有用 JavaScript 编程过,所以这是一个小问题),在我将手指从菜单项上移开后(并且在文本滚动之后),这些代码将滚动文本一个像素当然是到选定的地方)。也许 JavaScript 可以检测到滚动,然后向其添加另一个滚动。

I discovered the exact behavior you describe in an iPhone app I'm writing. I load a bunch of HTML text with an index on the right side. After selecting an item from the menu and scrolling the text, the menu would then become unresponsive (because the landing zone had scrolled out from under it). I also saw that even a tiny scroll of the text would reenable the index menu.

I created a test case and uploaded the file here (If you view this on a non-iPhone browser, make the window small vertically to see the correct behavior):

http://www.misterpeachy.com/index_test.html

I figured out that the index menu was scrolling with the text (even though the visible menu didn't move) after I tapped B and then tapped B again. Instead of scrolling to B (basically not moving), it scrolled to D.

Right now I'm stuck. I'm hoping that I can add some JavaScript code (I've never programmed in JavaScript, so that is a slight problem) that will scroll the text one pixel after I lift my finger off a menu item (and after the text has scrolled to the selected place, of course). Maybe JavaScript can detect the scroll and then add another scroll to that.

孤寂小茶 2025-01-01 10:45:13

如果它可以帮助某人:

我遇到了完全相同的问题,我的代码看起来像这样(它是一个单页网络应用程序):

window.scrollTo(0,0);
$('section.current').removeClass('current');
$(target).addClass('current');

我花了几个小时尝试一切(101%高度div,改变位置类型......),但最终 Device-Bugs 上描述的最后一个建议保存了 天。就我而言,这只是在 div 未渲染时滚动的问题:

$('section.current').removeClass('current');
window.scrollTo(0,0);
$(target).addClass('current');

In case it can help someone:

I had the exact same problem, and my code looked something like this (it's a single-page webapp):

window.scrollTo(0,0);
$('section.current').removeClass('current');
$(target).addClass('current');

I spent hours trying everything (101% height divs, changing the position type...), but finally the last suggestion described on Device-Bugs saved the day. In my case it was just a matter of scrolling when the divs aren't rendered:

$('section.current').removeClass('current');
window.scrollTo(0,0);
$(target).addClass('current');
你的背包 2025-01-01 10:45:13

解决方案的另一种变体是将文档宽度的大小增加 1px,然后立即撤消它。这样做的优点是不会创建更多元素,并且我没有经历过任何闪烁。

https://stackoverflow.com/a/11479118/43217

Another variation of a solution is to increase the size of the document width by 1px and then immediately undo it. This has the advantage of not creating any more elements and there isn't any flicker that I've experienced.

https://stackoverflow.com/a/11479118/43217

慕巷 2025-01-01 10:45:13

示例代码

if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) {
    $(document).on('focus', 'input, textarea', function() {
        $('header').css({'position':'static'});
    });
    $(document).on('blur', 'input, textarea', function() {
        $('header').css({'position':'fixed'});
    });
}

Example code

if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) {
    $(document).on('focus', 'input, textarea', function() {
        $('header').css({'position':'static'});
    });
    $(document).on('blur', 'input, textarea', function() {
        $('header').css({'position':'fixed'});
    });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文