Loop SVG text animation around rectangle path

I am using SVG to animate text around the path of a rounded rectangle. The idea is to have a stream of text that is constantly moving around the rectangle.

Here’s an example of the rectangle animation in this tutorial video for After Effects

But when closing the SVG path for the text, the animation does not run at all and if I leave the path open the text disappears as it reaches the end as in this code snippet:

html, body {
  background: black;
  margin: 0 auto;
}

.container {
  widht: 100%;
  background: red;
}

.svgwave {
  margin-left: calc(50% - 150px);
  margin-top: 100px;
}
<div class="wrapper">
            <svg class="svgwave" xmlns="http://www.w3.org/2000/svg" width="301" height="301" viewBox="0 0 301 301" style="width:auto; height: auto; overflow: visible;">
                <path id="wavepath" d="M145.5 301.5H13C6.09645 301.5 0.5 295.904 0.5 289V13C0.5 6.09645 6.09644 0.5 13 0.5H289C295.904 0.5 301.5 6.09644 301.5 13V289C301.5 295.904 295.904 301.5 289 301.5H156.5" style="fill: transparent; stroke: transparent; stroke-width: 1px;"></path>

                <foreignObject x='6' y='6' width='300px' height='300px'>
                    <div
                    style="width: 282px; height: 282px;
                            border-radius: 8px;
                            background-size: contain;
                            border: 4px solid white;
                            display:inline-block; "
                    ></div>
                </foreignObject>
                <text text-anchor="middle" style="text-transform: uppercase; font-family: Arial; font-size: 20px; fill: white;">
                    <textPath style=" fill-opacity: 1" href="#wavepath" side="left" startOffset="0%">
                    <animate attributeName="startOffset" from="30%" to="42%" begin="0s" dur="4s" repeatCount="indefinite"></animate>
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    First <tspan style="fill: #DED279;">Second</tspan> 
                    </textPath>
                </text>
            </svg>

        </div>
  • What would be the best way to achieve this animation using SVG?
  • Would there be any alternative way to achieve this with Javascript?

create a unique key from 3 Alphabet

I’m trying to create a unique key using the alphabets;
I’ve managed to work it out but I don’t really like the approach I took. and I believe someone out there might be able to help me get a better way to do this code. Please let me know if you think of a better idea? or whatever your idea to compare with mine?
I think this might be a good way to share knowledge .. Thanks in advance

let string = 'AAA';
let ar1 = ["A", "B", "C", "D", "E"];
string = string.split('');

if (string[2] !=='E') {
  for (let i = 0; i < 5; i++) {
        if (string[2] === ar1[i]) {
          i = i+1;
          string[2] = ar1[i]
        }
    }
    string = string.toString().replace(/,/g, '');
    console.log("case 1", string);

} 

if (string[1] !=='E' && string[2] ==='E') { 
    string[2] ='A';
    for (let i = 0; i < 5; i++) {
        if (string[1] === ar1[i]) {
          i = i+1;
          string[1] = ar1[i]
        }
string = string.toString().replace(/,/g, '');
    console.log(string);
    }
} 

if (string[1] ==='E' && string[2] ==='E') { 
    string[1] ='A';
    string[2] ='A';
    for (let i = 0; i < 5; i++) {
        if (string[0] === ar1[i]) {
          i = i+1;
          string[0] = ar1[i]
        }
    }
string = string.toString().replace(/,/g, '');
    console.log("case 3", string);
}

VBScripting: How to use VBScript variables within a script tag inside html?

I am trying to display some information inside a custom window with a vbs script,
that compares two variables and inserts them into a css stylized window.
If the two variables match then the color is green, if not then it is red.

myVar_A is assigned a custom string,
myVar_B gets the version of a custom file in the system.

I then want to compare the two variables and change the css styling.
Right now it shows that they are not equal but mostly because they are not called properly.

If I set an alert for the variables with a script tag, I get “undefined”.
So their value are not passed within the html tags.

How can I use these variables and their values to compare them? Is this possible?

Thank you!

VersionStyle.vbs

myVar_A = "1.85.72.1"

Set objFSO = CreateObject("Scripting.FileSystemObject")
myVar_B = objFSO.GetFileVersion("C:\Program Files\myFile.dll")

'.............................................................................................

Set win = New Window

'Add CSS styling
win.AddStyles = "body{text-align:left;}div{font-size:11pt;}"
win.AddStyles = "input{border:0;border-radius:2px;padding:2px 2px;margin:2px;background- 
color:#e2e2e2;}"

'Add HTML content to the body tag
win.AddContent = "<div><p><strong>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; Current Version &emsp; 
System Version</strong></p></div>"

win.AddContent = "&emsp;&emsp;"
win.AddContent = "myFile"

win.AddContent = "&emsp;&emsp;"
win.AddContent = myVar_A
win.AddContent = "&emsp;&emsp;&emsp;&emsp;"
win.AddContent = "<color_tag id='color_id'>"
win.AddContent = "<script>if (['myVar_A'] === ['myVar_B']) 
{document.getElementById('color_id').style.color = 'green';} else 
{document.getElementById('color_id').style.color = 'red';}</script>"
win.AddContent = myVar_B 
win.AddContent = "</color_tag>"

answer = win.Create()

'.............................................................................................
Class Window
'@description: Create a custom window with MSHTA. 
End Class

ImageOutput

Adding data to an array and accessing the data inside the array outside the function Javascript

I’m new to Javascript and I’m not understanding how to persist data in an array. In my function I’m reading a file line by line and saving it in an array. I figured that because the array is declared outside the function that data would remain in it, but that’s not what happens. I would like to understand how to do when printing the values ​​of the array outside the function that data still remain.

My code:

const fs = require('fs');
const readline = require('readline');
  
var array = [];


async function processLineByLine() {
  const fileStream = fs.createReadStream('data.txt');

  const rl = readline.createInterface({
    input: fileStream,
    crlfDelay: Infinity,
  });

  for await (const line of rl) {
    
      array.push(line);
    }
 

  //console.log(array.toString();
}

processLineByLine();
console.log(array.toString();

The expected output would be to have the data inside the array:

288355555123888,335333555584333,223343555124001,002111555874555,111188555654777,111333555123333

cannot set propperties of null javascript

how do i get rid of this stupid error. i try’d to fix it for a day but with no effect.

    <h1>0</h1 id='clickCounter'> 
    <input type="button" class="mainButton" onclick="buttonPressed()"> 

    <script>

        let totalClicks = 0; // variabele voor het bijhouden van de keren dat er op de mainbutton is geklikt

        function buttonPressed(){ // wat er moet gebeuren als er op de de mainbutton word geklikt

            totalClicks = totalClicks + 1;
            document.getElementById('clickCounter').innerText = totalClicks;
            console.log(totalClicks)

        }

    </script>

   

which one is faster objects or if statments?

I am making chess engine as a project I noticed that I had to use a lot of if statments because of that code was hard to read I came up with this solution for example when changing turns instead of writing

if(turn=="white"){
    turn="black"
}else{
    turn="white"
}

I did this

const switchTurns={
   "white":"black",
   "black":"white"   
}
turn=switchTurns[turn]

it looks like I am making my job harder with this objects but it helped a lot when I had to check way more things to get value like pisce, pisce index,is it middlegame or not and change tham based on other stuff I am 17year old I learned on my own and I don’t know exactly how everything works behind programming languages I am wondering does this method makes program slower or it is same? also is this good practice or not and why? thanks in advance

why is pagination not displaying properly?

I am using antdesign to displays cards in a component. As I have quite a bit of data I am using pagination to go through the cards. It seems to work for the most part however if the user clicks to go back when they’re on the 3rd page it doesnt display any cards. But if the user clicks to go forward from the 1st page it displays cards and if the user types 2 in the box it will display the cards. I’m very confused as to why this is happening. I’ve inserted photos here. 2nd page when clicked after first page or when 2 is typed in the pagination box
2nd page if you use the back button when youre on 3

this my component

import React, { useEffect, useState } from 'react'
import { Container } from 'semantic-ui-react';
import authService from '../../services/auth.service'
import authHeader from '../../services/auth-header';
import Axios from 'axios';
import { Card, Avatar, Space, Pagination } from 'antd';

const { Meta } = Card;


//pagination on 2nd

const SentimentComponent = (props) => {
  const currentUser = authService.getCurrentUser();
  const [reviewList, setReviewList] = useState([]);
  const [minValue, setMinValue] = useState(0)
  const [maxValue, setMaxValue] = useState(4)

  const handleChange = (value) => {
    if (value <= 1) {
      setMinValue(0)
      setMaxValue(4)
    }else {
      setMinValue(maxValue)
      setMaxValue(value * 4)
    }
 }

  // console.log(currentUser.id)

  useEffect(() => {
    Axios.post('http://localhost:8080/api/review/getUserReviews', { data: currentUser.id }, { headers: authHeader() })
      .then(response => {
        if (response.data.success) {
          console.log('Users Reviews', response.data)
          setReviewList(response.data.reviews)
        } else {
          alert('Error')
        }
      })
  }, [])



  return (
    <Container>
      <Space direction="vertical" size="middle" style={{ display: 'flex' }}>
        {reviewList && reviewList.slice(minValue, maxValue).map((review, index) => {
          return <Card key={index} review={review} style={{ width: 700 }}>
            <Meta
              avatar={<Avatar src="https://joeschmoe.io/api/v1/random" />}
              title={review.movieTitle}
              description={review.content}
            />
            <div className="emoji">
              {review.sentimentScore ? review.sentimentScore === 0 ?
              <img
              width={50}
              src="https://images.emojiterra.com/twitter/v13.1/512px/1f610.png"
              align="right"
              alt="neutral"/> 
              :  review.sentimentScore > 0 ? 
              <img
              width={50}
              src="https://as1.ftcdn.net/v2/jpg/02/15/08/80/1000_F_215088044_Ow0pypSekAamu3jZJnkRtfAyKj6KVlKj.jpg"
              align="right"
              alt="positive"/> 
              : <img
              width={50}
              src="https://www.pinclipart.com/picdir/middle/82-822786_cartoon-angry-emoji-pictures-to-pin-on-pinterest.png"
              align="right"
              alt="negative"/> 
            : ''}
            </div>
          </Card>
        })}
      </Space>
      <Pagination
          simple defaultCurrent={1}
          defaultPageSize={4}
          onChange={handleChange}
          total={reviewList.length}
        />
    </Container>
  )
}

export default SentimentComponent;

Image is not displaying when adding position property of css

I’m trying to unblur an image when scrolling. But when I add position: fixed; property to my CSS class the image is not getting displayed.Also the JS is giving an error saying ‘scrollPercent not defined’.
My inspiration to this code is :enter link description here

$(document).ready( function() {
  
  $(window).scroll(function() {
    
    var s = $(window).scrollTop(),
        d = $(document).height(),
        c = $(window).height();
        scrollPercent = (s / (d-c)).toFixed(2);
        
    // opacity value 0% to 100%
    $('.clear-img').css('opacity', scrollPercent);
    
  });
  
});
.imgsrc {
  position:fixed;
   background-position: center;
  webkit-background-size: cover;
  width:100%;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: -1;
}

.clear-img { opacity: 0; }
<div id="blurred-image-container">
      <div
        class="imgsrc">
      <img src= "https://cdn.glitch.global/ea44df9f-5322-47c9-83ba-4f453113a115/blur.png?v=1651333241542"/>
    </div>
      <div
        class="imgsrc clear-img">
      <img src="https://cdn.glitch.global/ea44df9f-5322-47c9-83ba-4f453113a115/unblur.png?v=1651333316753"/>
      </div>
    </div>

element.computedStyleMap is not a function

I’m messing around with hover effects and try to use: computedStyleMap().get() to detect css changes. It works well in chrome, but is there any firefox alternative that can be used and what is it?

let actualStyle = document.querySelector('.myDiv').computedStyleMap().get('cursor');
actualStyle == 'pointer' ? true:false;

It would be great to create something like a ‘mouseover’ without problem with passing the borders of child elements

HTML Tempalte Literal with TailwindCSS coming from database has weird styling in React

I have a project built with React, NextJS, and TailwindCSS. On this website, I get some HTML data from a supabase database that gets returned as a string. However, when the HTML is displayed it has some weird styling, some of the TailwindCSS classes work but some don’t. I’m using the eval() function to convert the HTML string to a template literal and then I display the content on the frontend with dangerouslySetInnerHTML:

const Edit = ({ template }: Props) => {
  ...
  const htmlContent = eval('`' + template.html + '`');
  ...
<div
  dangerouslySetInnerHTML={{
    __html: htmlContent
  }}
/>

Also, in the browser inspector I can see that the classes are there, but they don’t work.

This is what the frontend should look like

This is how it gets displayed

window.addEventListener(‘load’, function) not working in angular application

I have a subscription in a component of angular app where I need to download PDF file from response.

I am downloading PDF file after window.open() method has been called and later need to close current(new opened) tab via window.close() method.

window.close() method should run only after load event of window object is completed and PDF file is downloaded, but load event is not firing.

Here is code:

.subscribe(
    (res: any) => {
        if (response) {

                const formData: string = response.replace(/n/g, '');
                const win: any = window.open('', '_blank'); // open new tab
                win.document.write(formData); 
                // NOT FIRED
                window.addEventListener('load', () => {
                    // submit form received in response
                        win.close();         // NOT CALLED
                    },
                    false
                    );
                    
                }
            }
        );
        

Note: I don’t want to use setTimeout() function and call window.close() there since
the time for downloading might vary based on different factors (such as browser environment, file size and et.c.),
otherwise it’s possible to solve this issue by using:

    win?.setTimeout(() => {
        win?.close();
    }, 3000);

So, what is wrong here? Any help is appreciated.

State not being set, react useState

I am posting an image to my cloudinary account and want to save the URL from the response in the imageUrl variable. When console logging the response URL, it shows me the cloudinary URL correctly but the setImageUrl doesn’t seem to be working.

I have changed my cloudinary details to ‘dummy’ for security

import React, { useState } from 'react';
import './image.css';

function Image() {
  const [image, setImage] = useState('');
  const [imageUrl, setImageUrl] = useState('');
  const postDetails = async () => {
    const data = new FormData();
    data.append('file', image);
    data.append('upload_preset', 'harmony');
    data.append('cloud_name', 'mattglwilliams');
    const settings = { method: 'POST', body: data };
    try {
      const fetchData = await fetch('https://api.cloudinary.com/v1_1/mattglwilliams/image/upload', settings);
      const resData = await fetchData.json();
      console.log(resData.url);
      if (resData) {
        setImageUrl(resData.url);
        console.log('imageUrl', imageUrl);
      }
    } catch (e) {
      console.log(e);
    }
  };
  return (
    <>
      <div className="file-field input-field">
        <div className="btn #64b5f6 blue darken-1">
          <span>Uplaod Image</span>
          <input type="file" onChange={(e) => setImage(e.target.files[0])} />
        </div>
        <div className="file-path-wrapper">
          <input className="file-path validate" type="text" />
        </div>
      </div>
      <button className="btn waves-effect waves-light #64b5f6 blue darken-1" onClick={() => postDetails()}>
        Submit post
      </button>
    </>
  );
}

export default Image;

NestJs: How can I add options for my Custom Validation Pipe?

I created a custom validation pipe where I want to add some custom logic.I want to know how can I extend it so that I can call it with the below options

new ValidationPipe({ transform: true, whitelist: true })

validation.pipe.ts

import { PipeTransform, Injectable, ArgumentMetadata, BadRequestException, Logger } from '@nestjs/common';
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';


@Injectable()
export class ValidationPipe implements PipeTransform<any> {

    private readonly logger = new Logger(ValidationPipe.name);


    async transform(value: any, { metatype }: ArgumentMetadata) {
        if (!metatype || !this.toValidate(metatype)) {
            return value;
        }
        const object = plainToClass(metatype, value);
        const errors = await validate(object);
        if (errors.length > 0) {

            for (let error of errors) {
                for (let key in error.constraints) {
                    this.logger.error(`${error.target.constructor.name}:${error.constraints[key]}`);
                }
            }
            throw new BadRequestException('Invalid Input Parameters');
        }
        return value;
    }

    private toValidate(metatype: Function): boolean {
        const types: Function[] = [String, Boolean, Number, Array, Object];
        return !types.includes(metatype);
    }
}

How to fix the CORS and unblock the load of my JS File?

Im new to JS Web and i wanted to add import import { hash } from "crypto"; but i get a error telling me this:

Access to script at ‘js file here‘ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, brave, chrome-untrusted, https.