JavaScript Cursor-Based Auto Typing Tool

I want to develop a straightforward Javascript auto writer within an HTML page. Below is the code I have written:

<html>

<head>
  <style>
    #type {
      display: inline-block;
    }
    
    #cur {
      display: inline-block;
    }
  </style>
</head>

<body>
  <pre>
<div id="type"></div><div id="cur">{cursor}</div>
</pre>
  <script>
    var string = "Write this string!\nNext Line!";
    var array = string.split("");
    var timer;

    function looper() {
      if (array.length > 0) {
        document.getElementById("type").innerHTML += array.shift();
      } else {
        clearTimeout(looper);
      }
      timer = setTimeout('looper()', 50);
    }
    looper();
  </script>
</body>

</html>

The value of "{cursor}" denotes the cursor position, which will be created later. The issue encountered is that when moving to a new line, the cursor does not return to the initial position on the line but instead remains at the last position, causing a sudden "jump" to the next line.

Answer №1

If you need some assistance, check out this helpful website

You can also experiment with jQuery by following these steps:

<p id="demo4"></p> 

$('#demo4').typeIt({
 strings: ["This is an amazing string.", "Here's another fantastic string for you."],
 speed: 50,
 autoStart: 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

Ways to resolve issues with resizing div elements while waiting for JavaScript to load

Apologies for the lack of a clear title to describe my issue. My problem involves this snippet of code, where I am creating a label to show time to users. <div class="content"> <div class="container"> <div class="card"> < ...

Ionic is experiencing issues with CORS

I've been attempting to send a JSON to a PHP script on a server, and even though I have added CORS headers in the PHP script, the console is still throwing an error. Error Message XMLHttpRequest cannot load . No 'Access-Control-Allow-Origin&a ...

Is it possible to incorporate a LINK within the CSS GRID layout?

Hey everyone, I've encountered an issue with my link placement in the grid. I'm looking to turn the entire box into a clickable link. * { padding: 0; margin: 0; } body { font-family: Hiragino Kaku Gothic Pro W3, Arial; } .title-conta ...

Angular animation triggered when a specific condition is satisfied

I am working on an animation within my Angular application @Component({ selector: 'app-portfolio', templateUrl: 'portfolio.page.html', styleUrls: ['portfolio.page.scss'], animations: [ trigger('slideInOut&apo ...

Unlock the Power of jQuery Hashing with the Addition of Additional Variables

Looking for a way to include an additional variable in a URL like the one above. I've experimented with different methods but I'm not certain which is the most effective. For example: Currently using JQUERY to detect the HASH value: if (window ...

Getting the 'MyContext' constant for use in other components within React.js involves creating a context using the 'React.create

Currently working on a new app that utilizes the latest Context API. I encountered an error in the MyProvider component: undefined Provider. I need some guidance from you all on how to establish this MyContext. I have created separate .js files, but I ...

Differences in <img> sizing behavior between Chrome and Firefox

Objective: Develop a scrollable image-gallery web component with layouting that functions without script intervention. Specifications: The size of the web component must be fully responsive and/or adjustable. The top main area of the widget is the galle ...

Insert a division into the table following every row

I'm working with a table that can be found here: https://codepen.io/anon/pen/bjvwOx Whenever I click on a row (for example, the 1st row 'NODE ID 1'), I want the div with the id #divTemplate to appear below that particular row, just like it d ...

Checking for similarities between two string arrays to determine if there are any matching values using JavaScript and jQuery

Hey there, I'm currently working on a project where I need to compare two arrays and hide a list element if any values match. The first array consists of tags attached to list items, while the second array is user input. I'm facing some difficu ...

Running webpack to compile a TypeScript project

Here's a question for you - is there a way to achieve multi-file compilation while maintaining the folder and file structure, without explicitly specifying each file in the entry configuration like this? entry: { index:'./src/index.ts', ...

Updating the image source through ajax by retrieving the location from the database

Is there a way to dynamically change the image source using AJAX? I have the location saved in my database and I want to set the img src from the value of something like data[0]['patient_photo']. Below is the HTML code for the image: <img id= ...

Disable HoverZoom feature for images on the website

Currently building a website that includes various images. I have Imagus (similar to HoverZoom) installed for automatic image enlargement on hover, but I do not want this function for my specific images. I've noticed it works for some images and not ...

Default Selection Issue with Radio Buttons in AngularJS

I am currently encountering an issue with the code snippet included in my directive template '<li ng-repeat="f in foos">' + '<input type="radio" ng-change="foo(f.key)" ng-model="selectedFoo" name="foos" id="{{f.key}}" value="{{f.ke ...

The values returned by screen.height and screen.width are not accurate

When a user clicks on a button, I want to enable an overlay. However, when the user minimizes the screen, the overlay does not cover the full page and buttons remain clickable. I have tried setting the screen.height and screen.width for the overlay div usi ...

Implementing Reverse Sorting Feature with a Second Click in JavaScript

I've implemented a function that successfully sorts a JSON array when a link is clicked (the function is triggered by an onclick event). Here's the current sorting function in action: function sortArch(a, b) { x = eval("a." + sort_type).to ...

Conceal the top section of the navigation bar as you smoothly scroll

Hello, I recently personalized a Bootstrap navbar with 2 rows - the upper section containing just the logo and social links, and the lower section with navigation links. I have been attempting to hide the upper section when scrolling, but so far, I have no ...

Tips for aligning thumbnail text to the right on a small viewport with Bootstrap

Here is a visual representation of the standard thumbnail layout Once the viewport reaches the small size, the layout should switch to this design: Bootstrap only shrinks the container by default, as demonstrated in this jsfiddle: http://jsfiddle.net/32 ...

What are some methods for utilizing the data received through this.props.history?

Whenever I need to navigate from one route to another using this.props.history.push("/"), I also want to pass along some extra data. For example: this.props.history.push('/postDetail', {data: item}). However, I am uncertain about where to define ...

Having trouble integrating the css and js animation files into my Django project

settings.py import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = '@6qt%i+0&_=z0#zl^+!u3bw6c7dmg4e3khboj%7s7439z9#ky(' DEBUG = True ALLOWED_HOSTS = [] INSTALLED_APPS = [ 'django.contrib.admin& ...

Mouseover feature for image is functioning, but having issues with alignment

I am currently working on displaying images upon mouse over actions. While the functionality is working perfectly, I am facing an issue where the displayed images appear below and the last image takes up space at the bottom. To rectify this problem, I woul ...