Modifying the appearance of a marquee tag with JavaScript: A step-by-step guide


I am trying to change the height of a marquee tag depending on a calculation using javascript.
I have tried this:

/*jslint devel: true */

function maths() {
    "use strict";
    var x = Math.floor((Math.random() * 1080) + 1);
    document.getElementByTagName("test").style.height = x;
}

window.setInterval(function () {
    "use strict";
    maths();
}, 1);
marquee{
    font-size: 40px;
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Test</title>
        <intercept-url pattern="/favicon.ico" access="ROLE_ANONYMOUS"/>
    </head>
    <body>
        <marquee id="test" scrollamount="30" height="">test</marquee>
    </body>
</html>

Any help would be appreciated

EDIT: I have successfully been able to change the height of a marquee tag using JavaScript. I am following the same strategy as before but instead of changing height, i want to change the scrollAmount (the scroll speed). It does not change.
Thanks

/*jslint devel: true */
var x = Math.floor((Math.random() * 1080) + 1);
var w = Math.floor((Math.random() * 40) + 1);
var section1= document.getElementById("test");
var section = document.getElementById("test");

function resize() {
    "use strict";
    let heightLet=x.toString() + "px";
    //var marqueStyle = window.getComputedStyle(section);
    section.style.height = heightLet; 
    marqueStyle = window.getComputedStyle(section);
}

function scroll() {
    "use strict";
    let speedLet=w.toString();
     //var marqueStyle = window.getComputedStyle(section);
    section.style.scrollAmount = speedLet; 
    marqueStyle = window.getComputedStyle(section);
}

function read(){
    console.log(x);
}

window.onload = function () {
    console.log("x="+ x);
    console.log("w=" + w);
    resize();
    scroll();
    read();
    
}
marquee{
    font-size: 40px;
    border: solid;
    position:  absolute;
    bottom: 0;
}

div{
    position: relative;
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Test</title>
        <intercept-url pattern="/favicon.ico" access="ROLE_ANONYMOUS"/>
        <link type="text/css" rel="stylesheet" href="css/marqueestyle.css">
    </head>
    <body onload="resize()">
        <div>
            <section id="test">

            <marquee>test</marquee>
            </section>
        </div>
        <script type="text/javascript" src="java.js"></script>
    </body>
</html>

Answer №1

Check out this solution that includes the addition of a "dev" and "section" element. By using JavaScript, you can dynamically change the height of the section, allowing for different scrolling points for the marquee text. Feel free to utilize the section within a div as an object dock. I hope this helps address your question.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Test</title>
        <intercept-url pattern="/favicon.ico" access="ROLE_ANONYMOUS"/>
        <link type="text/css" rel="stylesheet" href="style.css">
    </head>
    <body onload="resize()">
        <div>
            <section id="test">

            <marquee scrollamount="30" >test</marquee></section></div>
        <button id="btn">Click Me!</button>
        <script type="text/javascript" src="script.js"></script>
    </body>
</html>

//CSS File (style.css)

marquee{
    font-size: 40px;
    border: solid;
    position:  absolute;
    bottom: 0;
}

div{
    position: relative;
}

//JS file (script.js)

/*jslint devel: true */

function resize() {
    "use strict";
    var x = Math.floor((Math.random() * 1080) + 1);

    let heightLet=x.toString() + "px";


var section= document.getElementById("test");

     //var marqueStyle = window.getComputedStyle(section);
        section.style.height = heightLet; 
        marqueStyle = window.getComputedStyle(section);

}

window.onload= resize;

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

Transforming a flow type React component into JSX - React protocol

I have been searching for a tooltip component that is accessible in React and stumbled upon React Tooltip. It is originally written in flow, but I am using jsx in my project. I am trying to convert the syntax to jsx, but I'm facing difficulties with t ...

Extract time value from html datetimepicker input

Recently, I've been utilizing a datetime_picker that I found on the web to create a value for an html text input. However, I encountered a problem in separating the value into distinct date and time components. When using the date_picker, the TEXT inp ...

Once lerna has the ability to handle monorepos, what benefits does Rush provide?

After thoroughly reviewing multiple datasets, it appears that Rush has a clear advantage in supporting pnpm due to its timeliness. However, it is worth noting that lerna can also offer support for pnpm: Despite this, lerna's earlier release gives it ...

What can I do to ensure that the selectInput choices in Shiny are easily accessible and visible to the user?

When running the code provided below, I encountered an issue where the options in the selectInput() were partially blocked by the bottom edge of the wellPanel(). This problem is illustrated in the image below. Users had to adjust the mouse wheel to see all ...

What is the best way to shift a text element within the footer section?

I have arranged two columns within the container, but I am looking to position the .company and .copyright text at the bottom left of the footer column. The Follow Us heading should be on the right side with the .justify-text below it, followed by social m ...

Is there a way to determine whether a number is lesser, greater, or falls within a specific range of values

Is there a more concise and readable way to write a function that checks if a given number is smaller, larger, or between two other numbers? The function should return NaN if any of the input parameters are not numbers. function order(num, a, b) { if ...

React treats flat arrays and nested arrays in distinct ways

After some experimentation, I discovered an interesting behavior in React when passing nested arrays. Surprisingly, React renders the items properly without complaining about missing keys on the elements. const stuff = 'a,b,c'; // Nested Array ...

Is there a way to incorporate a deletion feature within a list of items using JavaScript?

When adding a new item, I want to include a delete button next to it so I can easily remove the item by clicking on the button. However, I am having trouble figuring out how to implement this functionality using JavaScript. You can view my code snippet he ...

Positioning an individual element to the right side of the navigation bar in Bootstrap 5

I've been attempting to shift a single nav-item to the right side of the navbar, but I'm having trouble. My navbar is fairly basic, without a search tool or dropdown menu, as seen below: <nav class="navbar navbar-expand-lg bg-body-tertiar ...

When using dynamic handler assignment within useEffect, the updated state is not reflected in the handler

Check out this code snippet: const App = () => { const [items, setItems] = useState<{ text: string; onClick: () => any }[]>([]) useEffect(() => setItems([ { text: 'Click me', onClick: handleButtonClick, } ...

Retrieve a specific value in HTML <a> tag using JavaScript-Ajax in Django

I am currently working with Python 3 and Django. Within my HTML code, I have the following: {% for category in categories() %} <li class="c-menu__item fs-xsmall"> <a href="#" id="next-category"> {{ category}} & ...

Mastering the art of Promises and handling errors

I've been tasked with developing a WebApp using Angular, but I'm facing a challenge as the project involves Typescript and asynchronous programming, which are new to me. The prototype already exists, and it includes a handshake process that consi ...

Using Javascript, load a URL by making a JQuery ajax GET request and specifying custom headers

I currently have a small single-page application (SPA) using JQuery/Ajax for the frontend and Node/Express for the backend. The user authentication and authorization are handled with JSON-Webtoken, but I encountered an issue. If someone tries to access the ...

Concealing tooltip when button is clicked using jQuery

I am facing an issue where the tooltip does not hide on button click. Below is the code for the button in question: <button class="btn btn-outline-inverse ajax_addtocart additems ...

Create masterpieces on HTML5 Canvas with the stroke of your mouse

Is there a way to create drawings on an HTML Canvas using a mouse, such as signing or writing a name? Can you provide guidance on how I can achieve this functionality? ...

Fetching data from MongoDB, loading over 3000 entries and implementing pagination

I'm facing a challenge where I need to display more than 3000 results in an HTML table by fetching MachineID, Username, and Data from my MongoDB. However, I am encountering difficulties when trying to render this data using datatables. The MachineID ...

There seems to be an issue with the import class for React PropTypes. The prop

I have multiple oversized items that are utilized in numerous components, so I created a PropTypes file for each item. For example: PropTypes/PropLargeObject.js This file contains: import PropTypes from "prop-types"; const PropLargeObject = Prop ...

Include an additional feature to an already established design

I have been attempting to move an element to the left using the transform property. However, there is already a pre-existing style with transform, which appears as: transform: translate3d(tx, ty, tz) What I am aiming for is to incorporate another property ...

Combining TypeScript and JavaScript for efficient mixins

I came across an article on MDN discussing the usage and creation of mix-ins (link). Intrigued, I decided to try implementing it in TypeScript: type Constructor = new (...args: any) => any; function nameMixin(Base: Constructor) { return class extends ...

placing an image within a frame

I am having trouble aligning two divs side by side. I want to create a white background box with the date displayed in the top right corner, and I want the image to be at the same height as the date. Below is the code I have written: #boxx { background-c ...