How to reset CSS transitions on navigation

I have been trying to figure out the best way to reset my CSS transitions for my website’s navigation on mobile. The transitions only work the first time the page is loaded and after some research it seems that I need to reset them on click with Javascript or jQuery (I’m unfamiliar with both, hence why this has become an issue.) Any ideas would be appreciated. As a side note, I am using Divi for this website which is the reason for the overcomplicated class names and hierarchy.

Link to website: https://penmenwriting.com/

CSS below:

/* Mobile Navigation */


#mobile_menu1,  .opened #mobile_menu1 {
    position: fixed;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100%;
    max-height: 100%;
    z-index: 10;
    top: 0;
    border: none;
    overflow-y: auto;
    max-width: 100%;
    float: left;
    transition: all cubic-bezier(0.5, 0, 0, 1) 800ms;
    background-color: rgba(0,0,0,1);
    background-size: cover;
    background-repeat: no-repeat;
}

.opened #mobile_menu1 {
    transform: none;
}
.opened #mobile_menu1 a {
    transform: none;
    opacity: 1;
}
.opened #mobile_menu1 .menu-item:nth-child(1) a, .closed #mobile_menu1 .menu-item:nth-last-child(1) a {
    transition-delay: 200ms;
}

.opened #mobile_menu1 .menu-item:nth-child(2) a, .closed #mobile_menu1 .menu-item:nth-last-child(2) a {
    transition-delay: 300ms;
}

.opened #mobile_menu1 .menu-item:nth-child(3) a, .closed #mobile_menu1 .menu-item:nth-last-child(3) a {
    transition-delay: 400ms;
}

.opened #mobile_menu1 .menu-item:nth-child(4) a, .closed #mobile_menu1 .menu-item:nth-last-child(4) a {
    transition-delay: 500ms;
}

.opened #mobile_menu1 .menu-item:nth-child(5) a, .closed #mobile_menu1 .menu-item:nth-last-child(5) a {
    transition-delay: 600ms;
}

.opened #mobile_menu1 .menu-item:nth-child(6) a, .closed #mobile_menu1 .menu-item:nth-last-child(6) a {
    transition-delay: 700ms;
}
.mobile_menu_bar {
    z-index: 100;
}
.mobile_nav.opened .mobile_menu_bar:before {
 content: '4d';
    color: #262626;
    transition: all ease-in-out 500ms;
    z-index: 100;
}

.mobile_nav.closed .mobile_menu_bar:before {
    transition: all ease-in-out 300ms;
}
/* Menu animations */

.closed #mobile_menu1 {
    opacity: 0;
    pointer-events: none;
    transform: translatex(-100%);
    width: 0px;
    transition-delay: 600ms;
}

/* Link animations */

#mobile_menu1 a {
    transform: translatex(-90px);
    opacity: 0;
    transition: all cubic-bezier(0.5, 0, 0, 1) 800ms;
    text-align: left;
}

/* Stop body from scrolling while in nav */
body.noscroll {
    overflow-y: hidden;
}

images sequence animation on scroll with canvas

I want to develop an images sequence inside a canvas based on mouse scrollin:
when the sequence ended the canvas has to stop being fixed restoring a standard scroll
that reveils the content under the sequence, how can do that?

this is the pen
https://codepen.io/balestra78/pen/rNGqyyE

this is the code

— HTML —

<canvas id="hero-lightpass"></canvas>
  <div id="lipsum">... content after sequence ...</div>

— CSS —

body {
  padding: 0;
  margin: 0;
}

canvas {
  position: fixed;
}

#lipsum {
  padding-top: 900px;
  height: 200vh;
}

— JS —

const html = document.documentElement;
const canvas = document.getElementById("hero-lightpass");
const lipsum = document.getElementById("lipsum");
const context = canvas.getContext("2d");

const frameCount = 49;
const currentFrame = index => (
  `https://calcionapp.it/test/AdobeStock_320972514_Video_HD_Preview${index.toString().padStart(4, '0')}.jpg`
)

const preloadImages = () => {
  for (let i = 1; i < frameCount; i++) {
    const img = new Image();
    img.src = currentFrame(i);
  }
};

const img = new Image()
img.src = currentFrame(1);
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
img.onload = function () {
  scaleToFill(this)
}

const updateImage = index => {
  img.src = currentFrame(index);
  scaleToFill(img)
}

window.addEventListener('scroll', () => {
  const scrollTop = html.scrollTop;
  const maxScrollTop = html.scrollHeight - window.innerHeight;
  const scrollFraction = scrollTop / maxScrollTop;

  const frameIndex = Math.min(
    frameCount - 1,
    Math.ceil((scrollFraction * frameCount))
  );
  requestAnimationFrame(() => updateImage(frameIndex + 1))
  if (frameIndex > 47) {
    canvas.style.position = 'relative';
  } else {
    canvas.style.position = 'fixed';
  }
});

function scaleToFill(img) {
  // get the scale
  var scale = Math.max(canvas.width / img.width, canvas.height / img.height);
  // get the top left position of the image
  var x = (canvas.width / 2) - (img.width / 2) * scale;
  var y = (canvas.height / 2) - (img.height / 2) * scale;
  context.drawImage(img, x, y, img.width * scale, img.height * scale);
}

preloadImages()

Add Text at Cursor and Set Headings using Google Apps Script in Docs

Trying to insert specific text at my cursor to a Google Doc via a custom menu created via Google Apps Script. I am then trying to format that text to specific headings, body, etc. The below code is not working and is inserting all text with the same format as the surrounding text within the Google Doc. I have tried a number of different methods to accomplish this but am hoping for some help or tips!

function menuItem2() {
 var cursor = DocumentApp.getActiveDocument().getCursor();

 var headerAttr = {}
 headerAttr[DocumentApp.Attribute.HEADING] = DocumentApp.ParagraphHeading.HEADING2;

 
 var goLiveHeader = cursor.insertText("Go Live Process");
 goLiveHeader.editAsText().setAttributes(0, goLiveHeader.getText().length, headerAttr);

 DocumentApp.getUi().alert('Resources added.');
 
 }

Embedded Java Script in HTML

I’m trying to scrap off a website and I’m able to extract the HTML portions but I can’t convert the java script that’s embedded . Any suggestions? I’m fairly new to this so excuse the stupid question 🙂

Rails API returns numeric as string

In my Rails 6 app I have a sales database with a value column. Since this is a 2 decimal number I changed the type to

change_column :sales, :value, :decimal, precision: 10, scale: 2

This app has an API where I render a sales object to json. When I read this API with my angular object and do:

console.log(typeof this.sale.id)

I get string. And when I log the value I get:

value: "40.0"

Why does this happen? Before, when the columns was simples numeric this did not happen.
I know that I can convert the variable in JS to a float but I would like to know the reason and avoid converting the variable type.

Trying to read input events from /dev/input/event0

I’m trying to use this package (or any method) https://www.npmjs.com/package/input-event to read key events using Node.

I use this example code:

const InputEvent = require('input-event');
 
const input = new InputEvent('/dev/input/event0');
 
const keyboard = new InputEvent.Keyboard(input);
 
keyboard.on('keyup'   , console.log);
keyboard.on('keydown' , console.log);
keyboard.on('keypress', console.log);

But I see no output.

Accessing array element from response data using react-query

I am using react-query to make a GET request to my API in which the response is an array of objects. Each object has 1 property which is the name that I want to access. When I log the response to the console, it appears like the image listed at the bottom. However, when I try to access an element of the response, it says “cannot read properties of undefined”.

Here is the code which displays the data as shown in the image:

const { isLoading, error, data } = useQuery('cat_names', () =>
        fetch('<api-link>').then(res =>
            res.json()
        )
    )
console.log(data)

Here is the code I used to try accessing the first element of the array.

const { isLoading, error, data } = useQuery('cat_names', () =>
   fetch('<api-link>').then(res =>
       res.json()
   )
)
console.log(data[0])

I have also tried mapping data, with no luck:

const mapped_data = data.map(element => element.name)
console.log(mapped_data)

enter image description here

IF Statment Logic Meaning

I am working on a project but I was stumped to see this piece of code
if ((array.length – 1 – i) % 2 === 1) I am just curious as to how it works?

const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8];

const validateCred = (array) => {
  let total = 0;
  for (var i = array.length - 1; i >= 0; i--) {
    // console.log(array[i]) 
    if ((array.length - 1 - i) % 2 === 1) { /*I would like to know what does this do when put in a if statment array.length - 1 - i  */
      array[i] *= 2;
      // console.log(array[i]) 
      if (array[i] > 9) {
        array[i] -= 9;
      }
    }
    total += array[i]
    console.log(total)
  }
  return total % 10 === 0;

};
console.log(validateCred(valid1))

update a HTML input field with the data coming from a external Javascript Websocket

I am new to JavaScript, not sure if this very basic question. I’ve created a Bitcoin Price update dashboard using the data fetched from the external WebSocket. I managed to get the data from the WebSocket and display it on the console tab and display the data in a h1 tag. The price updates every seconds. Now i need to show the price in a html field. i tried but it’s kinda hard for me.

I have provided the code snippets below as well as external Websocket from where I am pulling the data.

Please let me know how should I insert the row dynamically into a HTML input field. Thank you so much in advance

                                <input type="text" class="form-control" id="btcpricenow" readonly>
                                  <script>
                                      
                         var priceSocket = new WebSocket("wss://stream.binance.com:9443/ws/btcusdt@trade"),
                          liveprice = document.getElementById("btcpricenow");
                          priceSocket.onmessage = function (event) {
                           var liveprice = JSON.parse(event.data);
                           liveprice.innerText = parseFloat(liveprice.p).toFixed(2);
                          }
                                  </script>

How do I check for a word in a message, in discord js?

I’m trying to make a simple discord bot. How can I make it so it checks for a word inside a message? For example if somebody says “i love bananas” and the trigger word is banana, the bot responds with “same”. All I could figure out is how to make it reply to a specific message (like only “banana”), how do I make something like the example I made?

How do I fetch same type of data which I want in table for Puppeteer

I’m trying to learn and scrape CSS selectors in Puppetter. There is a simple table and I want to fetch all of prices with DOM. When I try document.querySelectorAll("span")on the console,
it selects all of span tag.I need only prices, and I want to select first two h3 tags which includes 1 and 2 in Number column.

Here is a simple table for my question.

<html
<body>
   <div class="example">
<table class="table" border="1" cellpadding="10">

<thead>
<td>Number</td>
<td>Content</td>
<td>Price</td>
<td>Piece</td>
</thead>

<tbody>
<tr data-type="data">
   <td class="price"><h3>1</h3></td>
   <td>4 Point</td>
   <td><span style="font-size: 16px;font-weight: 600;"> 14$</span></td>
   <td>1</td>
</tr>

<tr data-type="data">
   <td><h3>2</h3></td>
   <td>5 Point</td>
   <td><span style="font-size: 16px;font-weight: 600;">15$</span></td>
   <td>1</td>
 
</tr>

<tr data-type="data">
   <td><h3>3</h3></td>
   <td>6 Point</td>
   <td><span style="font-size: 16px;font-weight: 600;">16$</td></span>
   <td>1</td>
</tr>

<tfoot>
<tr>
  <td style='text-align:center' colspan="4"> <span style="font-size: 16px;">Footer</span></td>
</tr>
</tfoot>

</tbody>
</table>
</div>
</body>
</html>

How to return array of references from mongodb?

I’ve got json like below, stored in mongodb:

{
  createdAt: 1641840199,
  name: 'hello'
  projects: [ new ObjectId("61dc99b2fdfbd72f33d4d699") ]
}

in projects array i’ve got an reference to the documents with project. And now i’ve got a question, how to return an array of this objects (full objects, not only it reference id).

PS. I’m using mongodb library, i do not like moongose.

Thanks for any help!