Scroll listener for WordPress

I am working on a journal website, and want to have the article image and a text below it, which is on the left side of the page, to stick when the user scrolls.

So far so good, yet what i want to do is that rather than having two titles (one on the top of the page and other the text I’ve talked about) i want the text to only be visible when a user scrolled down enough so that the sticky ability gets activated.

I would be equally contend finding any other workaround that would bring me to a similar result, as i dont think it is possible to achieve this with mere CSS.

object[element] works properly in forEach cycle, but does not save the value into the object’s property itself. What do I do?

function getEl(dce) {
    dce = document.getElementById(dce);
  }
  
  getEl(name91);
  getEl(age91);
  getEl(group91);
  getEl(button91);
  getEl(res91);
  getEl(div91);

  getEl(name92);
  getEl(age92);
  getEl(lesson92);
  getEl(button92);
  getEl(res92);
  getEl(div92);

  res91.textContent = "Данные ученика:";
  res92.textContent = "Данные учителя:";

  function ST(name, age, groupOrLesson, res, string) {
    this.name = name;
    this.age = age;
    this.groupOrLesson = groupOrLesson;
    this.res = res;
    this.string = string;

    this.showAll = function () {
      this.res += ` имя - ${this.name}, возраст - ${this.age}, ${this.string} - ${this.age}`;
    };
  }

  let student91 = new ST(
    name91.value,
    age91.value,
    group91.value,
    res91.textContent,
    "группа"
  );
  let array91 = [];
  for (let i = 0; i < div91.children.length; ++i) {
    array91.push(div91.children[i]);
  }

  array91.forEach((element) => {
    switch (element) {
      case "res":
        break;
      default:
        element.addEventListener("change", () => {
          student91[element] = element.value;
          console.log(student91[element]);
        });
    }
  });
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
  <h2>Задание 9</h2>
  <p>Ученик</p>
  <div id="div91">
    <input type="text" id="name91" placeholder="Имя" />
    <input type="text" id="age91" placeholder="Возраст" />
    <input type="text" id="group91" placeholder="Группа" />
    <button id="button91">Показать данные ученика</button>
    <p id="res91"></p>
  </div>
  <hr />

  <p>Учитель</p>
  <div id="div92">
    <input type="text" id="name92" placeholder="Имя" />
    <input type="text" id="age92" placeholder="Возраст" />
    <input type="text" id="lesson92" placeholder="Урок" />
    <button id="button92">Показать данные учителя</button>
    <p id="res92"></p>
  </div>
</html>

the title pretty much says it all. All works fine in console, but object[element] does not save the value into the object’s property;

p.s stackoverflow will not allow me to poast it unless I add some more text, wow, cool right? I write and write, so awesome.
p.s stackoverflow will not allow me to poast it unless I add some more text, wow, cool right? I write and write, so awesome.
p.s stackoverflow will not allow me to poast it unless I add some more text, wow, cool right? I write and write, so awesome.
p.s stackoverflow will not allow me to poast it unless I add some more text, wow, cool right? I write and write, so awesome.
p.s stackoverflow will not allow me to poast it unless I add some more text, wow, cool right? I write and write, so awesome.
p.s stackoverflow will not allow me to poast it unless I add some more text, wow, cool right? I write and write, so awesome.
p.s stackoverflow will not allow me to poast it unless I add some more text, wow, cool right? I write and write, so awesome.

ArrowJS state updates are not reflected in the template

I am trying to build a chrome extension using arrowjs,
One of my components has state which looks like this:

const state = reactive({
  loading: false,
  current_note: null,
});

I am using the loading property from the state to conditionally renders a loading indicator using another Arrowjs component:

${() =>
  state.loading &&
    html`
      <div class="ctnn-loading-placeholder ctnn-mb-1_5">
        ${LoadingIcon({ width: 35, height: 35, color: "hsl(0, 0%, 50%)" })}
      </div>
    `
}

This is how i update the state:

async function findOneNote(selected) {
  try {
    state.loading = true;

    const note = await fetchFindOneNote();

    state.current_note = { ...note };
  } catch (error) {
    console.log("Couldn't fetch note", error);
  } finally {
    state.loading = false;
  }
}

Using $on method, i can see that the state is indeed updated:

state.$on("loading", () => console.log("loading", state.loading));
state.$on("current_note", () => console.log("current_note", state.current_note));

However, the dom is not updating at all, i have other components that implement this pattern, but this is the only one which doesn’t work.

Example:

${() => modalState.menu === MODAL_MENUS.CREATE_NOTE && NoteForm(createNote)}

My questions are:

  1. Is there any special conditions that cause the template to ignore updates in the state ?
  2. Am i using the nested html function correctly ?

Thanks

CORS policy using TomTom API

I’m using TomTom API making an axios call to get latitude and longitude starting from an address. The problem is that CORS policies are blocking the call and I dunno how to solve this. The type of message I get is the following: credentials are not supported if CORS header ‘Access-Control-Allow-Origin” is “*” and CORS request failed Status code null. I’m using Vue 3 and Laravel. Thanks for your help …

The API call is something like https://api.tomtom.com/search/2/geocode/De Ruijterkade 154, 1011 AC, Amsterdam.json?key={my API Key}, obviously working on Postman …

Button stops after first click

const btnEl = document.getElementById("btn")
var taraEl = document.getElementById("tara")
var capitalaEl = document.getElementById("capitala")
const rezultatEl = document.getElementById("rezultat")

let randomNr;

randomNr = Math.floor(Math.random() * 251)

btnEl.addEventListener("click", async function(){
    try {
        const response = await fetch("https://restcountries.com/v3.1/all");
        const data = await response.json();
        rezultatEl.style.display = "block"
               
        taraEl.innerText = data[randomNr].name.common;
        capitalaEl.innerText = data[randomNr].capital;
        
    } catch (error) {
        console.log("error");
    }
})

Any idea how can I made the button brings another’s data, without refreshing the page?
Now after I press the button, one time, the generator button is inactive.

I want to press the button and get another country, also capital, but without refreshing the page.

Prototype Pollution in JSON5 via Parse Method on React native

Hello i ave this error on my native react app project
when I execute: npm audit

# npm audit report
json5  <1.0.2
Severity: high
Prototype Pollution in JSON5 via Parse Method - https://github.com/advisories/GHSA-9c47-m6qq-7p4h
fix available via `npm audit fix`
node_modules/find-babel-config/node_modules/json5
  find-babel-config  <=1.2.0
  Depends on vulnerable versions of json5
  node_modules/find-babel-config
    babel-plugin-module-resolver  2.3.0 - 4.1.0
    Depends on vulnerable versions of find-babel-config
    node_modules/babel-plugin-module-resolver
      babel-preset-expo  *
      Depends on vulnerable versions of babel-plugin-module-resolver
      node_modules/babel-preset-expo
        expo  >=14.0.0
        Depends on vulnerable versions of babel-preset-expo
        node_modules/expo


5 high severity vulnerabilities

i can execute npm audit fix –force but I would like to see where the problem comes from

I tried to update the components and to click on the links that are given to me to understand where the problem comes from but it is still there

Javascript alert.window is not working on my github page

I am new to the developer world and currently working on a online course in web design and Python. So excuse me if my question is vague or stupid 😉

Im am working on a simple assignment where I need to add a jQuery application in my code. I created a very simple code where it should open a alert window. The code looks like this:

    <script type="text/javascript">
      $(document).ready(function() {
        $("#verzend").click(function() {
          var naam = $("#naam").val();
          var leeftijd = $("#leeftijd").val();
          var woonplaats = $("#woonplaats").val();
          var hobby = $("#hobby").val();
          window.alert(
          "Hallo " + naam +
          " van " + leeftijd +
          " jaar oud! Wat leuk dat jij in " + woonplaats +
          " woont en jouw " + hobby + " is. Groetjes, Jeffrey");
        });
      });
    </script>

When I open the html file in Chrome directly from the folder on my laptop the alert window works. But I have the exact same code in a online github page, but there the alert window won’t show when i visit the page via Chrome. The teachers of the online course aren’t really helping me and say that there must be a fault in the filepath. But then it wouldn’t be working in the html file as well, right? I have no clue what the problem is here, so hopefully someone can help.
The github page can be found here: https://jeffreykrab.github.io/huiswerkles25/

Thanks!

I wrote a code for a alert window using jquery. I opened the file with Chrome and the alert window is working as expected. Then i uploaded the html file to github and published the page. When i open the page via the github link the alert window is not working any more.

PrimeVue menu component – Uncaught TypeError: this.$refs.menu.toggle is not a function

I have the following template for showing PrimeVue menu.

<template>
   <div>
      <i class="pi pi-ellipsis-v" @click="onActionClick"></i>
      <Menu :model="items" :popup="true" ref="menu" />
   </div>
</template>

data() {
    return {
        items: [
            { label: 'New', icon: 'pi pi-fw pi-plus' },
            { label: 'Delete', icon: 'pi pi-fw pi-trash' }
        ]
    }
},
methods: {
    onActionClick(event) {
        this.$refs.menu.toggle(event);
    }
}

Now when I click, I am getting the error:

Uncaught TypeError: this.$refs.menu.toggle is not a function

how can I fix this ?

JS Loop through the forms and for each add submit handler

I want to submit my forms with js.
I have this code:

(function() {
  var handleSubmit = function (event) {
    event.preventDefault();
  
    var myForm = event.target;
    var formData = new FormData(myForm);
    
    fetch("/", {
      method: "POST",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: new URLSearchParams(formData).toString(),
    })
      .then(() => console.log("Form successfully submitted"))
      .catch((error) => alert(error));
  };
  
  var forms = document.getElementsByTagName('form');
  
  for(var i = 0; i < forms.length; i++) {
    forms[i].onsubmit = handleSubmit(event);
  }
})();

But it does not works. I have an error (as soon as the site has loaded, even before submitting the form): Uncaught TypeError: Cannot read properties of undefined (reading ‘preventDefault’).
What I should to fix there?

How do I show 2 legends for a single dataset in Chart.js

I have a Javascript program that displays a bar chart of solar energy based on JSON readings provided by Solcast. For the current day these readings consist of actual values for each half hour before the current time and forecast readings for those values after current time. I want to show the actual bars in one colour and the forecast bars in another colour. I can accomplish this easily enough using a single dataset with backgroundColor set to an array that contains the different colours depending on whether it is an actual or forecast reading.

What I want to do is to show a legend for each colour (a double legend) showing what each colour represents.

If I use 2 datasets, both start from the same origin with the initial forecast readings sitting beside the initial actual readings and each bar width is halved. If I use a second dataset and set its display set to ‘none’ then the legend text is struck out.

Is there any way that I can have a single dataset with two legends (is HTML Legend the way to go, but I can’t find any help on that)?

My (relevant) code is:

var intp3 = period[3].replace(":","");
if (intp3 < oldTime) {  //  determine if reading is actual or forecast
  xValues.unshift(period[3]);
  yValues.unshift(forecast);
  barColors.unshift("darkseagreen");
}
else {
  xValues.push(period[3]);
  yValues.push(forecast);
  barColors.push("orange");
}
oldTime = intp3;

new Chart("myChart", {
  type: "bar",
  data: {
    labels: xValues,
    datasets: [{
      backgroundColor: barColors,
      data: yValues
    }]
  },
  options: {
    title: {
      display: true,
      text: barText
    },
    legend: {
      display: false,
      position: "top",
      align: "center",
    }
  }
});

`

How to use JS classes (or similar concept) within AlpineJS modules

I use the following Todo module with AlpineJS in order to have a central logic/schema for data handling. It works in general. However, when I add multiple entries, they all point to the same instance; so when I add a new to do, all the todo’s in the list adapt the new name.

To avoid this I tried using a class instead of just a module, however, this does not seem to work at all with AlpineJS.

Any idea how to best tackle this approach?

// <todo.js>
/* Does not work at all */
export default class {
    constructor(name, completed = false){
        this.item = {
          name: name,
          completed: completed
        }
    }
};

/* Works, but all items point to the same instance */
export default() => ({
    item: {
      name: '',
      completed: false
    }

});
<script type="module">
  import Alpine from './modules/alpine.js';
  import Todo from './modules/todo.js';

  Alpine.data('todo', Todo);
  Alpine.start();
</script>
 <article x-data="{ todos: [] }">

        <form x-data="todo" @submit.prevent="todos.push(item)">
            <input x-model="item.name"><button>Add</button>
        </form>

       <ul>
            <template x-for="todo in todos">
                <li x-text="todo.name"></li>
            </template>
       </ul>
    </article>

my code does not work, collectable does not appear and it is an error [closed]

can you help me fix my code? it doesnt work… REWRITE IT PLEASE… (JAVASCRIPT)

var collectable;
var collectables_x;

function setup() {

  collectable = {
      x_pos: 400,
      y_pos: 407,
      size: 50,
      isFound: false
      collectables_x = [210, 333, 400, 500, 570, 650];

      function draw() {

        for (var i = 0; i < collectables; i++) {
          drawCollectable(collectable);
          checkCollectable(collectable);

          function drawCollectable(t_collectable) {

            if (t_collectable.isFound == false) {
              fill(30, 144, 255);
              stroke(2, 155);
              rect(collectables_x[i], t_collectable.y_pos, t_collectable.size - 35, t_collectable.size - 25);
              fill(155);
              rect(collectables_x[i] + 2, t_collectable.y_pos - 5, t_collectable.size - 40, t_collectable.size - 45);

              function checkCollectable(t_collectable) {
                if (dist(gameChar_x, gameChar_y, collectables_x[i], t_collectable.y_pos) <= 40) {
                  t_collectable.isFound = true;
                  if (dist(gameChar_x, gameChar_y, collectables_x[i], t_collectable.y_pos) <= 40) {
                    t_collectable.isFound = true;

i was expecting multiple collectables appearing in my game and each one able to collect by my character when it goes over it, basically an object where u can collect in-game and it should dissappear while walking over it`

Homework Programming 1 [closed]

I have thiss assessment and help to solve it:
Now we will continue to work on the task “guess the speech” that you worked on in the last assignment.

One point is that you now have an opportunity to improve your previous submissions. If you have improved something from the task from the first assignment, be sure to point this out.

Maybe it was that you did not get the random number in the previous assignment, but that with the teacher’s feedback you learned this.

enter image description here

For the purpose of the guessing century, use a do-while loop. If you work with Python, you can use a while-loop instead.

The challenge

The challenge in this task ( to be approved ) is to compare the secret number with the entered value. The code should repeat the entry until you guessed correctly. It’s okay to use a bool variable to determine when the numbers are equal.

Rating C ) But it will be even better if you compare the numbers directly to each other in the while statement. The program should also keep track of how many times the code has been repeated and you can then enter a code that will end the game after ten guesses.

Rating A ) The biggest challenge is that you have to handle several game rounds. When a game round is over, you can choose to play another round. Or you end the game.

When the game is over, the score for all game rounds should be printed, as well as which game round required the least number of guesses.

How to add multiple layer of image using fabricjs canvas?

I’m working on tshirt design composer using javascript(Fabricjs/canvas) where tshirt has three layer and each layer color will be changable according to need but im facing problem when putting all the layer together it cover backside or bottom image of the stack(all the image are in .png form).

By using canvas of fabricjs im able to add two image as a layer but small area covered image hide all the background image which are actually transaparent in their background. im trying to make visible those portion which are hidden after putting onto stack on three layer.