ajax表单提交后iScroll4高度错误。高度为表单提交前的原始高度

发布于 2025-01-04 00:29:59 字数 1693 浏览 2 评论 0 原文

我已将一个表单嵌入到我的 iScroll4 滚动条中。该表单是一个ajax表单,由wordpress Gravity forms插件生成。

当我在表单上点击“提交”时,iscroll(在页面加载时生成)的高度保持不变,这意味着如果按下“提交”按钮后表单变大,则无法一直向下滚动。

请参阅下面的代码...

var myScroll,
    myScrollSidebar;

function loaded() {
    myScroll            = new iScroll('wrapper');
    myScrollSidebar     = new iScroll('sidebar-wrapper');
}

var formInputs = [
  document.getElementById('gform_submit_button_1'),
  document.getElementById('input_1_1'),
  document.getElementById('input_1_2'),
  document.getElementById('input_1_3'),
  document.getElementById('input_1_4'),
  document.getElementById('input_input_1_5')
];

for(var i = 0; i < formInputs.length; i++) {
  formInputs[i].addEventListener('touchstart' /*'mousedown'*/, function(e) {
    e.stopPropagation();
  }, false);
}

jQuery(document).bind('gform_page_loaded', function(){

    var formInputs = [
      document.getElementById('gform_submit_button_1'),
      document.getElementById('input_1_1'),
      document.getElementById('input_1_2'),
      document.getElementById('input_1_3'),
      document.getElementById('input_1_4'),
      document.getElementById('input_input_1_5')
    ];

    for(var i = 0; i < formInputs.length; i++) {
      formInputs[i].addEventListener('touchstart' /*'mousedown'*/, function(e) {
        e.stopPropagation();
      }, false);
    }

});

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);



谁能帮我解决这个问题,以便当表单提交时,iScroll 的高度可能会刷新?

绑定的 jquery 使得表单输入在表单提交后起作用。这是因为 iscroll4 难以处理表单元素。

提前致谢。

乔什

I've embedded a form into my iScroll4 scroller. The form is an ajax form, generated by wordpress Gravity forms plugin.

When I hit submit on the form, the height of iscroll (generated on page load) stays the same, which means if the form is bigger after the submit button is pressed, you can't scroll all the way down.

See my code below...

var myScroll,
    myScrollSidebar;

function loaded() {
    myScroll            = new iScroll('wrapper');
    myScrollSidebar     = new iScroll('sidebar-wrapper');
}

var formInputs = [
  document.getElementById('gform_submit_button_1'),
  document.getElementById('input_1_1'),
  document.getElementById('input_1_2'),
  document.getElementById('input_1_3'),
  document.getElementById('input_1_4'),
  document.getElementById('input_input_1_5')
];

for(var i = 0; i < formInputs.length; i++) {
  formInputs[i].addEventListener('touchstart' /*'mousedown'*/, function(e) {
    e.stopPropagation();
  }, false);
}

jQuery(document).bind('gform_page_loaded', function(){

    var formInputs = [
      document.getElementById('gform_submit_button_1'),
      document.getElementById('input_1_1'),
      document.getElementById('input_1_2'),
      document.getElementById('input_1_3'),
      document.getElementById('input_1_4'),
      document.getElementById('input_input_1_5')
    ];

    for(var i = 0; i < formInputs.length; i++) {
      formInputs[i].addEventListener('touchstart' /*'mousedown'*/, function(e) {
        e.stopPropagation();
      }, false);
    }

});

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);

Can anyone please help me fix it so when the form submits, iScroll's height refreshes perhaps?

The binded jquery is so the form inputs work after the form has be submitted. This is because iscroll4 struggles with form elements.

Thanks in advance.

Josh

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

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

发布评论

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

评论(1

耶耶耶 2025-01-11 00:29:59

您需要使用 myScroll.refresh() 让 iScroll 计算新的高度(在 AJAX 之后)。

这是来自开发者页面 (http://cubiq.org/iscroll-4):

iScroll 需要知道包装器和滚动条的正确尺寸。它们是在启动时第一次计算的,但如果您的代码更改了元素大小,则需要警告 iScroll 您正在弄乱 DOM。

这是通过在正确的时机调用刷新函数来实现的。请密切关注我,理解这一点将为您节省数小时的滚动挫败感。

每次更改元素高度/宽度或以任何方式修改 html 结构(例如:appendChild 或innerHTML)时,浏览器渲染器都会更新页面。一旦浏览器应用了更改,您就可以再次从 JavaScript 访问新的 DOM(和属性)。有时这个过程不是即时的。

You need to make iScroll compute the new height by using myScroll.refresh() (AFTER your AJAX).

This is from the developer's page (http://cubiq.org/iscroll-4):

iScroll needs to know the correct dimensions of both the wrapper and the scroller. They are computed the first time at start up but if your code changes the elements size, iScroll needs to be warned that you are messing with the DOM.

This is achieved by calling the refresh function with the right timing. Please follow me closely, understanding this will save you hours of scrolling frustration.

Every time you change elements height/width or you modify the html structure in any way (eg: appendChild or innerHTML) the browser renderer updates the page. Once the browser applied the changes you can access the new DOM (and properties) from javascript again. Sometimes this process is not instant.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文