Is your webpage slow to respond after a page-refresh? (Delayed HTML rendering causing lag)

Whenever I adjust the screen size to that of a phone or any device smaller than 768px, the search bar doesn't display in its proper position until the page is refreshed. It should be correctly placed right from the start. Furthermore, when I resize the screen back to full width, the search bar goes missing unless the page is refreshed. You can observe this behavior [link deleted] by switching to a phone screen in the browser console.

The JavaScript code responsible for this behavior is as follows:

function searchwidget(){

if ($(document).width() <= 767)
{
    $('#search_widget').appendTo('.hidden-md-up.text-xs-center.mobile');
}
else if($(document).width() >= 768)
{
    $('.header-top #search_widget').prependTo('.right-nav');
}

This snippet shows the template code structure:

{block name='header_nav'}
   <nav class="header-nav">
   <div class="container">
    <div class="row">
      <div class="hidden-sm-down">
       <div class="col-md-4 hidden-sm-down" id="_desktop_logo">
            <a href="{$urls.base_url}" class="header-logo">
              <img class="logo img-responsive" src="{$shop.logo}" alt="{$shop.name}">
            </a>
        </div>
        
        <div class="col-md-5 col-xs-12 left-nav">
          {hook h='displayNav1'}
        </div>
      
        <div class="col-md-3 right-nav">
            {hook h='displayNav2'}
        </div>
      </div>
      <div class="hidden-md-up text-xs-center mobile">
       
        <div class="pull-xs-right" id="_mobile_user_info"></div>
        <div class="pull-xs-right" id="_mobile_cart"></div>
        <div class="pull-xs-left" id="menu-icon">
          <i class="material-icons d-inline">&#xE5D2;</i>
        </div>
        <div class="top-logo" id="_mobile_logo"></div>
        <div class="clearfix"></div>
        
      </div>
    </div>
</div>
{/block}

How can this issue be resolved?

Answer №1

Special thanks to @CBroe for the helpful contribution:

Here is a snippet of code that addresses the search widget functionality when resizing:
    
function searchwidget(){
    
window.addEventListener('resize', function(event) {
if ($(document).width() <= 767)
{
        $('#search_widget').appendTo('.hidden-md-up.text-xs-center.mobile');
    }
    else if($(document).width() >= 768)
    {
        $('.header-top #search_widget').prependTo('.right-nav');
    }
}, true);
}

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

Having trouble getting the "save adjustments" button to become enabled after using the jQuery datepicker

It's puzzling that my code doesn't respond to the selection of a date using the jQuery date picker to re-enable the "save changes" button. Interestingly, changing values in other input boxes seems to work perfectly fine. I'm struggling to gr ...

Tips for getting the setTimeout() function to behave like a for loop

Is there a way to achieve the setTimeout() function's behavior in a for-loop? Take a look at this code snippet: function hello() { for (let index = 0; index < 3; index++) { setTimeout(function () { console.log('What&bs ...

What is the best way to position <div> elements?

I'm having trouble aligning two elements to create columns and adding a footer. Currently, the elements are stacked horizontally and the footer is inline with them. How can I adjust the formatting of the page? h1 { color: #225522; margin: 0px ...

Display images that have been uploaded on the page either as a grid view or a list of

In my Reactjs application, I am uploading multiple images to Azure Blob Storage. On a page, there is a button to open the upload form. Once the upload completes, I want to display all these images on the same page. Since the images have different aspect ...

My HTML document is not displaying the JavaScript variable as expected

I have created a JavaScript function with several variables and attempted to test it to display the variables in my HTML document. However, I am facing an issue where the variables do not appear as expected. Specifically, I am trying to insert the variable ...

Navigating through different sections of your Angular app can be easily accomplished using

My current project structure is set up like this: The application I am working on is hosted in a subdirectory called /my-scripts/vk.plants. This means that when I request this URL, it loads layout.html and returns it to the user. layout.html contains the ...

Efficiently managing multiple database updates with PHP and JQuery

Having trouble processing multiple mySQL updates simultaneously? I have 4 select/option boxes fetching data from a db table and I want to update the database onChange using JQuery. It's working with one select module, but adding more causes issues. Th ...

handle an exception within the initializer of its object

I'm currently working with an Ajax object that is utilized in various other objects to load 'Json' files. One issue I'm facing is trying to catch the 404 'Not found' exception thrown in the initializer object. However, every ...

The header and navigation bar are both set to stay in place, but unfortunately my div element is not displaying beneath

After setting both the Nav and Header to fixed, everything seems to start out well. I adjust the Nav margin-top so that it appears below the header, which works fine. However, things take a wrong turn when I try adjusting the div. The div ends up behind th ...

"Combining the power of JavaScript countdown with PHP date functionality

I have a JavaScript code that generates countdowns based on the user's PC date. I'm looking for a way to modify the script to use a specific timezone like: <?php date_default_timezone_set('Ireland/Dublin'); $date = date('m/d/Y ...

Display the source code of an HTML element when clicked

Is there a way to show the source code of an element on a webpage in a text box when that specific element is clicked? I am wondering if it is feasible to retrieve the source code of an element upon clicking (utilizing the onClick property), and subseque ...

Pause and wait for the completion of the Ajax call within the function before assigning the object to an external variable

In my quest to leverage JavaScript asynchronously to its full potential, I am looking for a way to efficiently handle received data from API calls. My goal is to dynamically assign the data to multiple variables such as DataModel01, DataModel02, DataModel0 ...

What will be provided as the outcome?

I have recently started learning express.js. The following code snippet is taken from the router library of express.js. var proto = module.exports = function(options) { options = options || {}; function router(req, res, next) { router.handle(req, ...

Please refrain from clearing the text field as it will delete the input value

I feel like I must be overlooking something really minor because I just can't seem to find it! I've been attempting to sanitize the text input by setting the state to ('') and while it clears the variable, the HTML input keeps displayi ...

The functions getFiles and getFolders will consistently retrieve a single file or folder each time they are

When attempting to fetch all files and folders from my Google Drive, the function .getFiles() is only returning one file, while .getFolders() is only returning a single folder. However, I can confirm that there are multiple folders and files in my drive. ...

What is the best way to use CSS to evenly lay out a group of dynamically generated buttons?

My Vue-generated buttons need to be evenly laid out on the bottom of the page, with equal space on the left and right. The mdui button style I am using has fixed width and height, so I have to decide between a single row for fewer buttons (less than three ...

Troubleshooting Key Press Issues with Bootstrap 5 Dropdown and Collapse Feature

Exploration In my quest to create a dynamic Bootstrap (5) Navigation bar/menu with animated sub-menus, I stumbled upon a solution that seems to fit the bill perfectly. By employing data-bs-toggle="collapse" instead of 'dropdown', I dis ...

Updating the DOM after every click event to keep content fresh

When the #undoAll button is clicked, it triggers individual click events using the following code: $('#undoAll').click(function(){ $('#prospectTable tbody tr td a:not(.invisible)').each(function(){ $(this).trigger('cli ...

Troubleshooting HTML/CSS and JavaScript Issues with Dropdown Menus

I'm having trouble getting my dropdown menu to work properly and I can't figure out why. The JavaScript code should toggle a class that hides the language options and slides up the other tabs like "Contact". However, when I click the button, noth ...

What are the steps to resolve an invalid token error when receiving it? (repl.it)

Today marks my introduction to node.js, recommended by a friend. Due to limited resources, I have opted to utilize repl.it for hosting. However, I am faced with an error in my first attempt at using it. The purpose of my current script is to make my user ...