JavaScript Animation: Enhancing TextBox Borders

I'm exploring an idea for a loading animation, but I'm feeling a bit lost on where to begin. Basically, I have a text box that gets populated automatically with JavaScript on the page, however, it takes some time to load. I want to create something similar to the infinite-time progress bar in IE11 to display inside the box. It would be like a thin bar covering half of the width of the box and moving slowly across it. Here's an example:

How can I achieve this in a cross-browser compatible way, including mobile browsers?

Answer №1

Here is a solution that may guide you in the right direction (and I hope you're open to using jQuery for this):

Incorporate the following HTML code:

<div id="wrapper">
    <div id="loading_progress"></div>
    <input type="text" value="" id="user_input">
</div>

Styling in CSS:

#user_input { 
    width:296px; 
    padding:2px;
    position:absolute; 
    top:0; 
    left: 0;
    border:1px solid #ddd; 
    margin:0; 
    z-index:1;
}

#wrapper { 
    position:relative;
    background:#ddd;
}

#loading_progress { 
    width:0; 
    padding:0;
    margin:0;
    background:#00f; 
    height:4px;
    position:absolute;
    top:2px;
    left:0;
    z-index:2;
}

Implementation with jQuery:

function resetProgressBar(){
    $("#loading_progress").css({'width':'0'});
}

function fillProgressBar(){
    $("#loading_progress").animate({'width':'300px'}, 2000);
}


setInterval( function(){resetProgressBar(); fillProgressBar(); }, 2200);

View DEMO

Answer №2

Web browsers display borders in a fixed manner;

Trying to animate the border of a TextBox (such as input:text or textarea) universally across different browsers and platforms is nearly impossible. In more modern browsers, like those that support css-level3 with border-image, it can be done.

However, it can be quite challenging.

Creating a progress bar above a TextBox, on the other hand, is much simpler, especially when loading content through AJAX. It involves positioning a container absolutely at the top left corner. Then, CSS animations are used on the container.

For examples, you can look into jquery-ui or search online for 'animated progress bar'

Answer №3

My go-to method has always been using 2 spans for this. The first span acts as the wrapper, set to a width of 100 pixels. Then, I adjust the second span's width based on the percentage of loading.

To create an animated effect, you can implement a setTimeout function that gradually increases the width of the inner span until it matches the width of the wrapper span.

By utilizing this approach, the loading time should be significantly fast.

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

Using the 'useMediaQuery' function from Material UI in a class component

Currently experimenting with Material UI's useMediaQuery feature to adjust the styles of a specific component, in this case the Button component. The objective is to eliminate the outline surrounding the button when the screen size decreases. The atte ...

In the realm of JavaScript, "this" is a key player when referring to an object within a factory

I created some JavaScript classes and FunctionFactories for them, but I believe there are errors in my implementation. To make the code more understandable, I decided to rename certain parts of it. The main class is called the "root"-class, which has chi ...

How to shuffle and restrict ngFor elements in an HTML list

I have a rather extensive JSON file that I'm looking to randomize and display in limited quantities within an HTML list item. The file contains over 100 items, but I only want to showcase ten at any given time. While I acknowledge that implementing pa ...

Is the existence of the file also verified by JavaScript's realpathSync() function?

I want to utilize node.js FileSystem realpathSync() to find the actual path of a file. Does realpathSync() also verify if the file exists? Would this code be sufficient: try { res = fs.realpathSync(path); } catch (err) { ...

Retrieve all HTML components with LXML

I have a large div element in my HTML document that I need to parse in order to retrieve all of its HTML content as well as any nested tags. Here is the code I am currently using: innerTree = fromstring(str(response.text)) print("The tags within the speci ...

Disarrayed image in absolute position on my webpage

I have a website with an auto-resizing background, but I am struggling to have a fixed black bar at the bottom of the page. Everything looks good when the browser window is maximized, but as soon as you scale it down and start scrolling, the black bar alm ...

Capture any clicks that fall outside of the specified set

I am facing an issue with my navigation drop down menu. Currently, the pure CSS functionality requires users to click the link again to close the sub-menu. What I want is for the sub-menu to close whenever a click occurs outside of it. I attempted a solu ...

Choosing the subsequent div after the current one using Jquery

I am currently in the process of creating a drop-down menu button that, when clicked, reveals the previously hidden div underneath it. The code is functioning properly without the use of $(this).next, but it is displaying all divs with the class .menudrop ...

Creating a functional dropdown form in Ruby On Rails: A Step-by-Step Guide

Having an issue with implementing a dropdown form in the navigation bar of my Rails application. The problem arises randomly - sometimes it works smoothly, while other times I have to refresh the page for it to function properly. The Rails version being u ...

Tips for utilizing getServerSideProps with a series of consecutive fetch() promises?

I've encountered a CORS issue while working on my project, particularly with the second fetch (fetchURL2) being blocked due to the absence of the 'Access-Control-Allow-Origin' header. How can I resolve this CORS policy error using next.js ge ...

What is the reason for the new page rendering from the bottom of the screen in React?

Whenever I navigate between pages in my React project, the page always starts at the bottom instead of staying at the top after rendering. I am using router v5 and have been unable to find a solution specifically for this version. I have attempted differe ...

Error Uploading File - Functioning in Postman but not on website interface

I'm currently pursuing the full stack certification on devchallenges.io and tackling the authentication app challenge. So far, I've successfully implemented the login and register functionality, as well as fetching the logged-in user's infor ...

Is there a way to customize jqwidgets jQuery grid cell classes/styles based on row ID and column name?

{ text: 'sell', datafield: 'Sales', width: '3%', columntype: 'button', filterable: false, cellsrenderer: function(row, columnfield, value, defaulthtml, columnproperties) { return &apos ...

Using JQuery to hide elements by setting CSS display as none instead of block

Is there a way to change the display of a content div to block when a specific tab is selected by the user, while hiding all other content divs? Here is the JQuery code I have tried so far: $(document).ready(function() { function resetTabs() { $("# ...

Simultaneous activation of CSS classes by multiple RouterLinkActive components

Using multiple <a> tags with routerLink presents a unique behavior. Upon loading the home page, the home icon in aMenuItems is correctly given the active class through routerLinkActive, while the remaining elements in the array do not have this class ...

Display or conceal a div depending on whether the user is on a mobile or desktop browser

In order to optimize the display on different devices, I organized my content into two divisions. The left division contains quantity, price, and item name, while the right division includes product names. For mobile browsers, I would like to hide the pro ...

What is the best way to check the difference between the current date and time with another date and

Seeking assistance in comparing 2 dates using JavaScript has been a bit challenging for me. I haven't found the exact solution on this platform yet. As a beginner in JavaScript, I initially assumed that obtaining the current date and time would be a s ...

Align the positioning of the dropdown menu and the input field

I'm having trouble with css and ng2-completer. I am attempting to line up the dropdown section with the input field. Unfortunately, there is no demo example provided on the page showing how to target elements using css. I've tried selecting the ...

Code functioning properly on JS Fiddle, experiencing difficulties when running directly in browser

Hey there, I have this vertical jquery tabs example working on JSFiddle, you can check it out here: https://jsfiddle.net/tj_vantoll/nn2Qw/ I've been trying to replicate it in an HTML file but so far I haven't had any luck... Can someone help me ...

Display Vue component depending on specified attribute

I have a block of code that I am working with: <div> <b-card no-body> <b-tabs pills card vertical no-key-nav v-model="step"> <b-tab title="Subject" v-for="animal in animals" :key="animal&q ...