Adjusting scroll position delay for a fixed element when using an Android device

I am experiencing an issue with an element that is supposed to become fixed when scrolling past 145px and then unfixed when scrolling back up. While this functionality works smoothly on desktops, there seems to be a delay on mobile devices, particularly on Android. On Android, the fixed element remains in place all the way to the top of the page before the browser realizes it should no longer be fixed.

How can I eliminate this delay?

Using jQuery

$(window).scroll(function () {
    if ($(this).scrollTop() > 145) {
        if ($("#latestWrapper").css('position') !== 'fixed') {
            $("#latestWrapper").css("position", "fixed");
            $("#latestWrapper").css("top", "0px");
        }
    } else {
        if ($("#AddFixedLatest").css('position') !== 'static') {
            $("#latestWrapper").css("position", "absolute");
            $("#latestWrapper").css("top", "145px");
        }
    }
}); 

CSS Solution

div#latestWrapper {
    height:50px;
    top:145px;
    width:100%;
    pointer-events:none;
    text-align:left;
    z-index:1;
    position:absolute;
    -webkit-transform: translateZ(0);
    -webkit-perspective: 1000;
    -webkit-backface-visibility: hidden;
}

Your assistance in resolving this issue would be greatly appreciated.

Answer №1

Consider this potential solution. While it may not be foolproof, implementing a periodic check for resizing could help. Feel free to try it out and see if it works for your needs.

var delay = (function(){
  var timer = 0;
  return function(callback, ms){
  clearTimeout (timer);
  timer = setTimeout(callback, ms);
  };
})();

$(window).scroll(function () {
   delay(function(){
if ($(this).scrollTop() > 145) {
    if ($("#latestWrapper").css('position') !== 'fixed') {
        $("#latestWrapper").css("position", "fixed");
        $("#latestWrapper").css("top", "0px");
    }
} else {
    if ($("#AddFixedLatest").css('position') !== 'static') {
        $("#latestWrapper").css("position", "absolute");
        $("#latestWrapper").css("top", "145px");
    }
}
 }, 100);
}); 

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

Where should the live() method be implemented to ensure the successful functioning of this jQuery crossfade transition

My jQuery crossfade is mostly working, but I believe I need to use the live() function because the class "active" is added to a list item element via the code. I'm unsure of where to include the live() function in my code for it to work properly. He ...

What is the method to showcase every single word?

Can someone help me with my assignment? I am tasked with creating a small user interface that searches a list of words using HTML, CSS, and Javascript. The design is provided, but I need to implement it. I have written the code, but I would like all wor ...

What could be causing disparities in the padding of certain table cells compared to others?

If you're interested, I created a photo gallery over at Take a look around and feel free to download any wallpapers that catch your eye! The issue I'm encountering is with the padding of the columns - specifically, the first and last columns ha ...

Ensuring that a header one remains on a single line

Within this div, I have set the width and height to be 250px. Specifically, the h1 element inside the div has a height of 50px. Users who are updating content on my website can input any text they desire within this box. However, when the text within the ...

Vuetify displaying incorrectly following deployment

After creating a spa with vue.js for the frontend, I utilized the vuetify library for various components and layout. While everything looked great locally, upon deploying to Azure, all vuetify styling seemed to disappear. My custom css was still applying ...

Utilizing AngularJS for enhanced data management in DataTables with a customized

I am currently working with AngularJs+DataTable library and I have a specific need to create a custom control that can utilize the exact search function from DataTable, but with a customized user interface. However, when using the search() method, it retur ...

What is the best way to extract the first td value (id) from a table?

I am facing an issue where I have attempted to retrieve an ID from , but it is not working as expected... I have tried using a hidden field and the ID in ... Can someone provide assistance? I have commented on the site where I believe the problem lies ...

Using jQuery to retrieve the ID from a <td> element

There is a piece of HTML code: <td id="checkb1" class="checkba"> I am trying to retrieve the ID value when I click on it. $('.checkba').click(function() { var my_var = $('.checkba').attr('id'); alert(my_var); ...

Discovering methods to store browser credentials securely in jQuery

I need to prevent the login button from being enabled when either the username or password fields are empty. Check out the code snippet below: $(document).ready(function(){ $('input').on('keyup blur mouseenter', function(e) { ...

Placing a button at the bottom of a bootstrap well

Hey there, I'm facing an issue with the button positioning. I really need the button to be placed at the bottom of the well, but for some reason, it keeps showing up next to the image instead. This is what's happening: the button is ending up be ...

Complications arising from IE when using strict doctype with CSS and jQuery

Here's the code I'm using for a sliding caption effect on my gallery site: I specifically implemented the last effect which is the Caption Sliding (Partially Hidden to Visible). $('.boxgrid.caption').hover(function(){ $(".cover", th ...

Leverage the power of jQuery datetime picker in an ASP.NET content page with a repeater control

Can anyone help me with adding a javascript tag to a content page of my asp.net application? The script is working fine with html tags, but it's not functioning properly within the content. Here is the code snippet that displays a datetime picker: &l ...

Emphasizing the content of the text file with the inclusion of span tags

I am relatively new to working with angular js and javascript. I have a document or text file that looks something like this: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dumm ...

What is the best method to update the content of one div with content from another page using AJAX?

Having trouble achieving smoother page loads? My goal is to utilize AJAX to specifically fetch a certain div from another page and then swap out the content of a div on this current page with the response. Below is my JavaScript script that uses AJAX to r ...

Using the parent id in knockoutJs to create a nested menu

I'm currently attempting to create a nested menu using the JSON data provided by the client. Here is the data: var serverData = [ { Id: "menuColorSearch", Text: "Color search" }, { Id: "menuAncillaryProductM ...

Hide dynamic jQuery UI tabs that are not selected

About My Project: Currently, I am developing a chat system that utilizes websockets. In order to enhance the user experience, I have integrated jQuery UI tabs for the design. These tabs will facilitate communication in various chatrooms and private setti ...

Converting data to JSON format using PHP version 4.4.1

Currently, I am working on a jQuery login form which utilizes the $post function to send user credentials to a php script. This php script then checks the credentials against users in the database. Up until now, I have been using PHP 5.2 without any issue ...

Extract PHP variable and incorporate it into JavaScript code

After doing some research online, I was unable to find a solution to my issue. Can anyone provide assistance with this problem? I currently have a javascript variable that contains the name of a PHP session address. I am trying to access this session valu ...

Utilizing CSS to Properly Position HTML Elements

Check out my code on jsFiddle I'm facing some challenges in positioning HTML elements using CSS. While I grasp the fundamental concepts of block and inline elements, implementing them in real coding scenarios can be confusing. I've shared my HTM ...

Integration of jQuery on Squarespace platform

Has anyone had success implementing jQuery in a Squarespace site? I'm working with a template-based website and wondering if there's a simple way to include it using <script type="text/javascript" src="jquery.js"></script>. Despite tr ...