The Function(JS) is specifically designed to only function within the topmost div or quote

Currently, I am facing an issue with a function I have implemented. This function adds a blur effect to words in a Blockquote when the page is loaded. However, I need this function to work for all Blockquotes and different divs on the page, not just the top one in the HTML. I have tried searching for solutions but haven't been successful in finding one that works or that I fully understand.

Can anyone provide guidance on how I can resolve this issue?

function splitWords() {
  let quote = document.querySelector("blockquote q");
  quote.innerText.replace(/(<([^>]+)>)/ig,"");
  quotewords = quote.innerText.split(" "),
  wordCount = quotewords.length;
  quote.innerHTML = "";
  for (let i=0; i < wordCount; i++) {
    quote.innerHTML += "<span>"+quotewords[i]+"</span>";
    if (i < quotewords.length - 1) {
      quote.innerHTML += " ";
    }
  }
  quotewords = document.querySelectorAll("blockquote q span");
  fadeWords(quotewords);
}

function getRandom(min, max) {
  return Math.random() * (max - min) + min;
}

function fadeWords(quotewords) {
  Array.prototype.forEach.call(quotewords, function(word) {
    let animate = word.animate([{
      opacity: 0,
      filter: "blur("+getRandom(2,5)+"px)"
    }, {
      opacity: 1,
      filter: "blur(0px)"
    }],
    {
      duration: 1000,
      delay: getRandom(500,3300),
      fill: 'forwards'
    }
   )
  })
}


splitWords();
.border {

 width:100%;

 height:300px;
 background-color:#b2800a;
 min-width:1200px;


}

.borderimg {
 width:100%;
 content:url("border.png");

 min-width:1200px;
}
.background

{

 width:100%;
 content:url("Background.png");

}
body {
 background-color:#b2800a;
 padding:0;
 margin: 0;
 min-width:auto;
}


.header
{
position:absolute;
font-size:70;
color:white;
left 1000px;



 opacity: 0.7;

}



*
{
  box-sizing: border-box;
}

blockquote {
  font-size: 3rem;

}

blockquote q {
  font-family: Georgia, serif;
  font-style: italic;
  letter-spacing: .1rem;
}
blockquote q span {
  will-change: opacity, filter;
  opacity: 0;
  filter: blur(0px);
}
q {

  quotes: "“" "”" "‘" "’";
}
q:before {
    content: open-quote;
    margin-right: .8rem;
}
q:after {

}
q:before, q:after {
  color: #ccc;
  font-size: 4rem;
}

.text1 {
font-size:80px;
top:160px;

color:white;
position:absolute;
opacity: 0.7;


}
<html>
<head>
<script type="text/javascript" src="javascript.js"></script>
<link rel="stylesheet" href="style.css" type="text/css">
<title>Name</title>
<body class="body">
</head>

<div  class="header"><blockquote><q>Creativity is my way to say hi</q></blockquote></div>
<div  class="text1"><blockquote><q>Welcome on my site</q></blockquote></div>




<script type="text/javascript">

splitWords();


</script>





<div class="background"></div>



<div class="borderimg"></div>

<div class="border"></div>


</body>
</html>

Answer №1

This section highlights the modifications I implemented,

  let quote = [ ] ;
  quote = document.querySelectorAll("blockquote q");
  for (let x = 0 ; x < quote.length ; x++) {

function splitWords() {
  let quote = [ ] ;
  quote = document.querySelectorAll("blockquote q");
  for (let x = 0 ; x < quote.length ; x++) {
  quotewords = quote[x].innerText.split(" "),
  quote[x].innerHTML = "";
  for (let i=0; i < quotewords.length; i++) {
    quote[x].innerHTML += "<span>"+quotewords[i]+"</span>";
    if (i < quotewords.length - 1) {
      quote[x].innerHTML += " ";
    }
  }
  quotewords = document.querySelectorAll("blockquote q span");
  fadeWords(quotewords);
}
}

function getRandom(min, max) {
  return Math.random() * (max - min) + min;
}

function fadeWords(quotewords) {
  Array.prototype.forEach.call(quotewords, function(word) {
    let animate = word.animate([{
      opacity: 0,
      filter: "blur("+getRandom(2,5)+"px)"
    }, {
      opacity: 1,
      filter: "blur(0px)"
    }],
    {
      duration: 1000,
      delay: getRandom(500,3300),
      fill: 'forwards'
    }
   )
  })
}


splitWords();
.border {

 width:100%;

 height:300px;
 background-color:#b2800a;
 min-width:1200px;


}

.borderimg {
 width:100%;
 content:url("border.png");

 min-width:1200px;
}
.background

{

 width:100%;
 content:url("Background.png");

}
body {
 background-color:#b2800a;
 padding:0;
 margin: 0;
 min-width:auto;
}


.header
{
position:absolute;
font-size:70;
color:white;
left 1000px;



 opacity: 0.7;

}



*
{
  box-sizing: border-box;
}

blockquote {
  font-size: 3rem;

}

blockquote q {
  font-family: Georgia, serif;
  font-style: italic;
  letter-spacing: .1rem;
}
blockquote q span {
  will-change: opacity, filter;
  opacity: 0;
  filter: blur(0px);
}
q {

  quotes: "“" "”" "‘" "’";
}
q:before {
    content: open-quote;
    margin-right: .8rem;
}
q:after {

}
q:before, q:after {
  color: #ccc;
  font-size: 4rem;
}

.text1 {
font-size:80px;
top:160px;

color:white;
position:absolute;
opacity: 0.7;


}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
<script type="text/javascript" src="javascript.js"></script>
<link rel="stylesheet" href="style.css" type="text/css">
<title>Yunus Gök</title>
<body class="body">
</head>

<div  class="header"><blockquote><q>Creativity is my way to say hi</q></blockquote></div>
<div  class="text1"><blockquote><q>Welcome on my site</q></blockquote></div>

<script type="text/javascript">

splitWords();

</script>

<div class="background"></div>
<div class="borderimg"></div>
<div class="border"></div>
</body>
</html>

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

Managing active dropdown menus in VueJS

I'm having trouble figuring out why my navigation menu and method to open subitems on click are not working correctly. [![dropdown_menu][1]][1] new Vue({ el: '#app', data: { //menu "menu_title": "a", "child_ro ...

Increase the date by one day in the minimum date field using the date picker

I've been struggling with adding one day to the minDate in my code. Despite trying multiple solutions from Stackoverflow, none of them have worked successfully. Here is the code I currently have: $('#cal_mulamhn').datepicker({ minDate ...

In React Router version 4, it is stated that each router is only allowed to have a single child element when using multiple routes

I'm currently working on implementing a sidebar alongside the main content area using react-router-dom. Instead of just rendering <Sidebar/> directly, I want to pass it the location prop due to another issue where clicking a <Link/> in the ...

Dynamic React animation with sliding elements

When jumping between the second and third "page" of content, I am unable to determine the reason why it is happening. The content is displayed as an absolute position. Check out the sandbox here: https://codesandbox.io/s/nostalgic-bhabha-d1dloy?file=/src ...

The footer covers the content when the content fills the entire screen

I'm having trouble getting my .content_pro to stick to the top of the footer, regardless of screen resolution. When I set the height to 100%, it ends up underneath the footer. I've been struggling with this for hours but can't seem to make i ...

Setting up Stylelint in a Vue 3 app with VSCode to automatically lint on save

I am looking to perform linting on my scss files and scss scope within .vue components. Here is what my configuration looks like in stylelint.config: module.exports = { extends: [ 'stylelint-config-standard', 'stylelint-config-rece ...

Creating a responsive layout with two nested div elements inside a parent div, all styled

I'm currently facing an issue with using padding in my CSS to make the two divs inside a parent div responsive at 50% each. However, when combined, they exceed 100%. I suspect this is due to the padding, but I'm unsure how to resolve it. .column ...

Revolutionizing Interaction: Unveiling the Power of Bootstrap 3

Would you be able to assist me in customizing buttons to resemble a typical dropdown link? <div class="dropdown"> <button class="btn dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">Dropdown <span class="caret"&g ...

What is the best way to dynamically disable choices in mat-select depending on the option chosen?

I was recently working on a project that involved using mat-select elements. In this project, I encountered a specific requirement where I needed to achieve the following two tasks: When the 'all' option is selected in either of the mat-select e ...

Struggling with implementing a grid layout using CSS

I am currently facing an issue with my code where I am attempting to set up a wrapper element as a grid. However, upon inspecting the page, I am receiving notifications that my inputs for display, grid-template-columns, and grid-template-area are considere ...

Refresh stock value in anychart without having to re-render the entire chart

I am currently experimenting with the Anychart stock candlestick chart and I must say, it is quite impressive. However, I have encountered an issue while trying to update the chart using a setInterval function. The problem is that it re-plots the entire ch ...

"Encountering a 500 internal server error with jQuery and WordPress

I'm having issues implementing ajax into my WordPress project to dynamically load videos based on their post ID. Whenever I click on the video link, a 500 internal server error occurs. I'm sending the post ID through ajax to a PHP script where I ...

How can I retrieve the HTML content of a ReactJS rectangle element saved in an array?

Within a loop, I am creating rectangle elements and adding them to an array: rectangles = []; render: function() { for (var i = 0 ; i < 10; i++) { rectangles.push (<Rectangle height={this.props.afm} width={this.props.afm} x={xpos} y={ypos} va ...

Error: Unable to locate the include file

Hello, I am currently a student working on a project where I am attempting to retrieve a list of books from the server and display them one by one using ejs. Here is an overview of my project structure: | |-----routes | |-----index.js |-----vie ...

What causes .obj files to not respond to directional light in three.js?

Can anyone explain why the .obj file is not displaying directional light similar to the box? Both have identical materials. You can find the code on GitHub: https://github.com/triple-verge/triple-verge-website/blob/master/src/js/modules/logo-3d.js#L52 H ...

Adding markers to a Leaflet map using coordinates retrieved from a Supabase database - a step-by-step guide

I am looking to incorporate markers on a map using coordinates stored in a Supabase database column. Below is my Vue code: <l-marker v-for="(marker, index) in markers" :key="index" ref="markersRef" :lat-lng="marker.po ...

Create HTML email content from a dynamic table data containing date columns in SQL

I am presenting a dynamic table data below region 01-May-2021 02-May-2021 INDIA 10 30 UAE 20 80 USA 300 10 Whenever executing the script, a new column is added automatically with the current date. I require to convert this table data into HTM ...

Transform the binary image data sent by the server into an <img> element without using base64 encoding

It's been a challenge trying to find a reliable method for adding custom request headers to img src, so I'm experimenting with manually downloading the image using ajax. Here is an example of the code I am working on: const load = async () => ...

Guide on attaching an onclick event to a button created with a string in Next.js?

<div onClick={(event) => this.addToCart(event)}> <ReactMarkdownWithHtml children={this.props.customButton} allowDangerousHtml /> </div> In my current situation, I am facing an issue with the code above. The button is being rendered ...

Vue 3 - Child Component Script Not Updating with Reactive Prop Changes

I am facing an issue where I am trying to pass a reactive data as a prop to a child component in Vue 3. The data updates correctly in the child component's template, but it does not reflect in the child component's script. In the parent component ...