The height of iScroll4 becomes incorrect following the submission of an AJAX form. The height reverts back to its original value before

I have integrated a form within an iScroll4 scroller. The form is an ajax form created using the Gravity Forms plugin in WordPress.

After submitting the form, I noticed that the height of the iScroll remains the same as it was generated on page load. This causes an issue where if the form extends beyond the initial height, users are unable to scroll down completely.

Please find my code snippet 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);



I am seeking assistance to rectify this issue whereby the height of iScroll can refresh upon form submission.

The jQuery binded is to ensure that the form inputs function properly after the form is submitted, as iScroll4 encounters difficulties with form elements.

Thank you in advance.

Josh

Answer №1

To ensure iScroll adjusts to the new height, remember to call myScroll.refresh() after your AJAX request is complete.

The developer's page () explains this process:

iScroll relies on accurate dimensions of both the wrapper and scroller elements. These are initially calculated at start up, but any changes made to the elements require iScroll to be notified in order to update the DOM properly.

To accomplish this, make sure to call the refresh function at the right moment. Understanding this concept can save you from hours of frustrating scrolling issues.

Whenever you alter the height/width of elements or modify the HTML structure (e.g. using appendChild or innerHTML), the browser updates the page layout. Only after these changes have been applied by the browser can you access the updated DOM (and its properties) again through JavaScript. Keep in mind that this rendering process may not happen instantly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Automatically abbreviate the URL using JavaScript or Ruby on Rails

When using Twitter, posting a link in a tweet will result in the URL being automatically shortened. For example, the link http://stackoverflow.com/questions/8699459/get-title-content-via-link-in-rails will be shortened to: Here is the corresponding HTML c ...

Making a GET request using headers through an AJAX call

Is it possible to create a crossdomain AJAX query in order to receive a token and then display the data received, for example using alert ()? Here is a description of part of the API: Authorization Method properties: HTTP method: GET URI: / Input param ...

What is the process for transmitting data in JSON format generated by Python to JavaScript?

Utilizing Python libraries cherrypy and Jinja, my web pages are being served by two Python files: Main.py (responsible for handling web pages) and search.py (containing server-side functions). I have implemented a dynamic dropdown list using JavaScript w ...

The button is functioning properly on desktops using bootstrap, but is unresponsive on mobile devices

I have successfully created a bootstrap button with an embedded link. Here is how it appears: Upon hovering over the button: This is the code snippet for the button: <div class="s-8"><button type="button" onClick="javascript:location.href = &ap ...

Ways to widen the header to fit the entire page?

I'm having trouble stretching my header to fill the entire page. I've tried using margin-left and right, but it's not working as expected. My Header CSS: background: green; height: 70px; width: 100%; display: flex; just ...

What is the best way to convert a recordset to an array using React?

I'm attempting to create an array by retrieving data from a SQL recordset: +------------+------------+------------+ | start_type | field_name | start_text | +------------+------------+------------+ | 0 | Field1 | some text. | +----------- ...

Edit CSS attributes within Angular 2+ framework

When using jQuery, we have the ability to do the following: JQuery('.someStyle') .css({"background", "red"}) This allows us to directly change the CSS property in style. While working with Angular 2+, we can use [style.<property>] for ...

When the window size is minimized, containers are colliding with each other

On smaller window sizes or certain small screen phones, the buttons are overlapping the heading. Take a look at the code below: <style> body { font-family: Arial, Helvetica, sans-serif; } .x2 { position: absolute; left: 50%; top: 50%; tran ...

Using the JQuery `append()` method, I aim to generate a pair of Bootstrap columns by iterating through an associative array's keys

I've been struggling to design a form that includes labels and inputs. I have an associative array with labels as keys and corresponding values as array objects. My goal is to create a bootstrap horizontal form with two columns (col-6) each. However, ...

Woocommerce - On the Cart page, I would like the ability to transfer the total price when the quantities in the cart are updated

Hey there! I'm slowly navigating my way through this, so please bear with me. Let me explain what I'm working on here. I'm using Woocommerce with a theme called Flatsome, but the issue I'm facing seems to be related to how Woocommerce ...

Determine the value of an object by iterating through its keys

UPDATE: (for clarification) I currently have a table named modelCoa +----+----------+-------+--------------------+ | id | id_parent| code | name | +----+----------+-------+--------------------+ | 1 | 0 | 1 | asset ...

Issue encountered: The 'secp256k1-browserify' module could not be located when using browserify in conjunction with ethereumjs-lib

Trying to execute a basic script in the browser using the ethereumjs-lib library that has been installed. Utilizing browserify to produce the necessary javascript file for embedding into the html page. However, encountering an error related to missing modu ...

The 959th module loader in the internal node system, designated as node:

I am encountering the console error code: 'MODULE_NOT_FOUND' Below is the complete console error message: node:internal/modules/cjs/loader:959 throw err; ^ Error: Unable to locate module 'C:\Users\jerry\OneDrive\Des ...

Issue encountered when attempting to generate a mongoose schema using a JSON document

Can I define this JSON file structure as a mongoose schema? Mongoose lacks an object type, and I'm unsure how to proceed with it. { "Moutainbike": { "Cross": { "size": [ "395 mm", "440 mm", "480 mm", "535 mm" ], "color" ...

Does TweenJS consistently begin at 0?

I'm currently working on a threejs project and I have encountered an issue with rotating a plane using tween. The problem is that the tween always starts at 0, despite having the correct initial value (a) when checked in the console. For instance, W ...

Should I include JSX or JS when exporting ReactJS components as node modules to npm?

I've been busy developing React.js components and sharing them as modules on npm. My approach involves utilizing a gulp task to convert all jsx components into js, leveraging gulp-react: var react = require('gulp-react'); gulp.task(' ...

Play Framework: encountering "Action not found" error in GET route following an AJAX request to PUT or POST route

In the midst of enhancing my Play application with AJAX capabilities, I am following steps 5 (Adding some AJAX actions) and 6 (Invoking actions from Javascript) as outlined in the Zentask tutorial for Play Java. My current approach for initiating a specif ...

Trouble transferring $rootScope.currentUser between AngularJS profile and settings page

I am in the process of setting up a site using Angular, Express, Node, and Passport. Currently, I am configuring Angular to monitor the $rootScope.currentUser variable with the following code: app.run(function ($rootScope, $location, Auth) { // Watch ...

Setting up Karma configuration to specifically exclude nested directories

When unit testing my Angular 2 application using Karma, I encountered an issue with my directory structure: └── src/ ├── index.js ├── index.js.text ├── index.test.js ├── README.txt ├── startuptest.js ...

I have incorporated jquery-1.2.6.js into my project but I am encountering difficulties utilizing the live method

C# foreach (DataRow Row in oDs.Tables[0].Rows) { LitPreferances.Text += "<Li ID=LI_" + Row["pk_Preference_Branch_ID"].ToString() +"_"+ Row["pk_Preference_BranchType_ID"].ToString() +">" + Row["Branch_Name"].ToString() + "&nbsp;&nbsp;< ...