automatically adjusting the font size

There are 3 paragraphs of text on a page...I am looking to dynamically change the font size of these paragraphs every 3 seconds....is that feasible?
Specifically, I want paragraph 1 to be initially displayed at 10px and paragraph 2 at 8px. Then, after 3 seconds, I would like paragraph 2 to switch to 10px while paragraph 1 switches to 8px.

Is there a way to achieve this using an update panel or JavaScript? Any suggestions?

Answer №1

To automate the execution of a function periodically, utilize the setInterval method:

CSS:

#para1 { font-szie: 10px; }
#para2 { font-szie: 8px; }
#para3 { font-szie: 8px; }

HTML:

<p id="para1">asdf</p>
<p id="para2">asdf</p>
<p id="para3">asdf</p>

Javascript:

window.onload = function(){
  var current = 0;
  var ids = ['para1', 'para2', 'para3'];
  window.setInterval(function(){
    current = (current + 1) % 3;
    for (var i = 0; i < ids.length; i++) {
      document.getElementById(ids[i]).style.fontSize = (i == current ? '10px' : '8px');
    }
  }, 3000);
};

Answer №2

Give this a try:

<div>
<p id="p1">Paragraph 1  </p>
<p id="p2">Paragraph 2  </p>
</div>


 $(function() {
        var size1 = 20, size2 = 8, tempSize;
        $('#p1').css('fontSize', size1);
        $('#p2').css('fontSize', size2);
        function changeFontSize() {
                tempSize = size1;
                size1 = size2;
                size2 = tempSize;
                $('#p1').css('fontSize', size1);
                $('#p2').css('fontSize', size2);
                            }
            setInterval(changeFontSize, 3000);
        });

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

Issues arise with tabbed content as default content fails to display and classes are not added upon clicking

I'm currently working on a tabbed module that consists of three tabs. Here's how it operates: When the user clicks on a carousel_element, it reveals carousel_hidden-text within that div and displays it in another div called carousel_quote. I&ap ...

What is the best way to retrieve multiple elements within a handlebars helper block in a node.js application?

I am working with an object structured like this: object = { "group_1": [ { "name": "Foo" } ], "group_2": [ { "name": "Bar" } ] } In my Handlebars view, I currently have the following setup: {{#each group_1}} <p>{{name}}</p&g ...

Can the `await` keyword spawn a new thread?

After studying the documentation provided by Microsoft on async and await, I came across this statement: The async and await keywords do not lead to the creation of additional threads. However, upon executing the following code snippet: using System; ...

The `webkit-animation-fill-mode` property does not seem to be functional in Firefox

I attempted to create a progress bar design using webkit animation fillmode, but unfortunately, it is not compatible with Firefox. I also tried converting % values to pixels, but the issue persisted. <!doctype html> <html> <head> < ...

Error code 0 occurs in jQuery AJAX when there is an issue with the communication between the client

Currently delving into the world of ASP.NET and wanted to create a basic website utilizing ajax to retrieve a simple string from the server. Upon running the ajax request, an error message pops up stating An error occurred: 0 error Here's a glimpse ...

Differentiate two groups in a linear fashion

I am working with three arrays in C, but the language is not important in this context: float x[] = { 0.72, 0.91, 0.46, 0.03, 0.12, 0.96, 0.79, 0.46, 0.66, 0.72, 0.35, -0.16, -0.04, -0.11, 0.31, 0.00, -0.43, 0.57, -0.47, -0.72, -0.57, -0 ...

Navigating to the index page with a specific identifier using ASP.NET MVC 4

Is there a way to maintain ASP.NET MVC 4's current controller/action/id routing with the default controller set to Home and default action set to Index, all while allowing controller/id to route to the controller's index method if the second item ...

Send an API call for every item in a given list

There is a function that I am working with: updateCustomers = (input) => { //let urls = input; let urls = [{ name: "localhost:8081", url: "http://localhost:8081" }, { name: "localhost:8082", url: "http://localhost:8081" }, { ...

verification tool for a less file's syntax

Searching for a tool to validate a specific less file at the syntax level. The issue lies in the validator not recognizing dependencies or detecting declared mixins. Many existing less processors do not work due to missing dependencies that cannot be prov ...

Overlay displayed on top of a single div element

Trying to implement a loading overlay in an Angular project within a specific div rather than covering the entire page. Here's a Fiddle illustrating my current progress: #loader-wrapper { top: 0; left: 0; width: 100%; height: 100%; ...

Prevent the line break from going beneath the ::before pseudo element

p::before { content: "1. "; } p { width: 200px; } <p>This is an example of a long text that requires a line break: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam ...

Querying the api for data using Angular when paginating the table

Currently, I have a table that retrieves data from an API URL, and the data is paginated by default on the server. My goal is to fetch new data when clicking on pages 2, 3, etc., returning the corresponding page's data from the server. I am using an ...

Using AJAX to fetch an object and then comparing the JSON string data with the existing value

When my function receives an array object from an external API, I am able to convert it to JSON. Here is an example of how the JSON objects look: { "id": 99, "title": null, "author": "user", "content": "content", "u ...

Navigate through an unidentified variable in a different scope from its origin

Currently, I am working on writing a unit test for an MVC web application. The purpose of this test is to validate whether the returned list of anonymous variables in a jsonresult is accurate. However, I am facing difficulty in iterating through this list. ...

Looking for results using similar to

When searching through my datagrid, I always have to type the first word. If I type the next word or any consecutive letters, nothing shows up. For example: If I search for "Welcome Back" and type "Elcome" or "back", it won't display anything. Below ...

Switching sub components based on routing through navigation links after logging in

I'm having an issue with my routing setup while transitioning from the login page to the main page. Here's how my Routes are structured: App.jsx <BrowserRouter> <Routes> <Route path="/main/" element={<Main ...

Tips for deploying an Angular application with Node.js

Currently, I've set up a nodejs backend by following a tutorial to integrate tweets into the frontend of my application. As I prepare to deploy to a development server, I have successfully built the frontend using ng build --prod. However, I am facin ...

Having trouble displaying information in a table using React JS

I devised a feature to display one column of a table and one column for checkboxes (each row should have a checkbox). I stored this file in a component folder with the intention of creating a page where the user selects an account type, and then a new tabl ...

Struggling to get troika-three-text installed via npm?

I'm having trouble integrating Troika with my three-js scene. While others seem to have no issue, I am struggling to call the module and encountering problems with references. It's frustrating because I can't seem to find any resources to he ...

How can I show the total sum of input values in a React.js input box?

Is there a way to dynamically display the sum of values entered in front of my label that updates automatically? For example, you can refer to the image linked below for the desired output Output Image I have initialized the state but I'm struggling ...