How to resize Javascript embedding in html css?

I am trying to embed a javascript interactive graph into my html code (its a markdown file) using Jekyll for GitHub. However, the graph is displayed way too large and I was wondering if I can resize it so it fits the webpage


# This is the title 

## This is the subitle 


### Example graph 

In the example below we see an interactive graph that you can push and pull in a very 

  <head>
    <style> body { margin: 0; } </style>

    <script src="//unpkg.com/three"></script>
    <script src="//unpkg.com/three-spritetext"></script>
  
    <script src="//unpkg.com/3d-force-graph"></script>
    <!--<script src="../../dist/3d-force-graph.js"></script>-->
  </head>

  <body>
    <div id="3d-graph"></div>
  
    <script type="text/javascript" src="/3d-JS-Network/test.js"></script>
  </body>
 

Here is also the output:

output

Slick Slider Center Mode Issues with Hidden Slides

I am using Slick Slider but have a few slides which are marked as hidden dynamically.

My issue is that Slick Slicker still assigns an index to the hidden slides as if they are visible, and in Center Mode this affects the centering of the slides. In my case, I have 3 slides always visible (left, center, right). If I select the slide after a hidden slide, it appears in the left position as oppose to the center position due to Slick Slider thinking that the hidden slide is taking up width.

Is there a way to have Slick Slider ignore hidden slides on initialization? Or at least get the center mode alignment to work when dealing with hidden slides.

jq('.slider').slick({
    prevArrow: '<div class="slick-prev"><i class="fa fa-angle-left" aria-hidden="true"></i></div>',
    nextArrow: '<div class="slick-next"><i class="fa fa-angle-right" aria-hidden="true"></i></div>',
    infinite: false,
    slidesToShow: 3,
    slidesToScroll: 1,
    focusOnSelect: true,
    centerMode: true,
    centerPadding: 0
});

To hide slides I am simple using display:none;

Webgl orbiting object with camera

I am playing around in webgl and have built a simple gltf loader, that allows to move the main object around. I can orbit the object, but it only allows to view the front side. I can orbit the object, but it only allows to view the forward.

Now I did fix that using rotation and multiplication, but I want to use the lookAt function, to make it more simple, and also to have pitch orbit (up-down). Currently, I can rotate the camera (orbit) the main object, but only on yaw.

My camera class has the transform matrix and the projection matrix. I then make a view matrix and multiply it with the projection matrix, then save it in the transform matrix. But this only allows for yaw rotation. If I add pitch, then the camera does move up and down, but it doesn’t rotate to keep the object in center.

I am thinking this could be done with the lookAt function, but how would I get the camera origin position, since it requires a vector, but I only have the main transform matrix. I do have transformation, rotation and scale vectors, but since I am multiplying matrixes, the remain 0.

// saves camera options into c constaint
const c = this;

let camX = Math.sin(c.yaw) * c.distance;
//let camY = Math.cos(c.pitch) * c.distance;
let camZ = Math.cos(c.yaw) * c.distance;

var viewMatrix = mat4.create();
// c.matrix is the camera transform matrix
mat4.invert(viewMatrix, c.matrix);
mat4.multiply(c.matrix, c.projection, viewMatrix);
mat4.fromTranslation(c.matrix, vec3.fromValues(camX, 0, camZ));
 
const vec = vec3.create();
// model is the object to orbit around
vec3.add(vec, vec3.clone(model.translation), vec3.fromValues(camX, 0, camZ));
var moveMatrix = mat4.create();
mat4.fromTranslation(moveMatrix,  vec);
mat4.multiply(c.matrix, c.matrix, moveMatrix);

var rotMatrix = mat4.create();
mat4.fromYRotation(rotMatrix, c.yaw);
mat4.multiply(c.matrix, c.matrix, rotMatrix);

WebScrape value of HTML element from an external website

I’m wondering if this kind of coding is possible.

I want to WebScrape from an in-house HTML page. I want to be able to select an option in my HTML page and by pushing a button, I want to WebScrape the version code of an application in the bottom of this page “https://play.google.com/store/apps/details?id=org.thoughtcrime.securesms” from Google PlayStore. The HTML form is very simple.

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<hr>
<label for="cars">Applikation:</label>
<select name="apps" id="SelectApps">
<option value="Tom">Tom</option>
<option value="Signal">Signal</option>
<option value="WhatsApp">WhatsApp</option>
</select>

<button type="button" id="myBtn" onclick="myFunction()">Hent data</button>

<hr>
<form id="myForm" action="xxxxxx">
  ID : <input id="ID1" type="text" value="ID"><br>
  Version : <input id="ID2" type="text" value="Version"><br>
</form>
<hr>

<script>

function myFunction() {
if(document.getElementById('SelectApps').value == "Signal") {
   
   ID1.value = 'org.thoughtcrime.securesms';
   ID2.value = webscrape from google store 
  
}
 }
   </script>
</body>
</html>

By using Python xxx

from lxml import html
import requests
import os

page = requests.get('https://play.google.com/store/apps/details? 
id=org.thoughtcrime.securesms')
tree = html.fromstring(page.content)

version = tree.xpath('//span[@class="htlgb"]/text()')

print('Data: ', version)

My output is

['December 3, 2021', 'Varies with device', '50,000,000+', '5.27.13', '4.4 and up', 
 'Users Interact, Shares Location', 'Signal Foundation']

How can I transfer this output into my HTM page? A value from Python into HTML

Load title/audio from json/js for music player. Getting error undefined

If I add the songs for the first album at:
line 220const songs = [‘OldLocal’, ‘AllOverAgain’, ‘Causes of the Causes’, Good Lord Willin and the Creeks Don’t Rise];
it works fine for those songs but I can’t figure out how to pull the songs from the json for this. PLEASE HELP.
….

// JavaScript Document
var musData =[
    {
        "imageUrl": "genpx1.png",
        "artist": "Artist1",
        "name": "First Album",
        "release":"2019",
        "slist":[
            {
                "tnumbr": 1,
                "stitle":"OldLocal1",
                "slink":"OldLocal.mp3",
                "duration": "2:47"
            },
            {
                "tnumbr": 2,
                "stitle":"AllOverAgain1",                
                "slink":"AllOverAgain.mp3",
                "slyric":"",
                "duration": "4:47"
            },
            {
                "tnumbr": 3,
                "stitle":"Causes of the Causes1",
                "slink":"Causes of the Causes.mp3",
                "slyric":"",
                "duration": "2:47"
            },
            {
                "tnumbr": 4,
                "stitle":"Good Lord Willin and the Creeks Don’t Rise1",
                "slink":"Good Lord Willin and the Creeks Don’t Rise.mp3",
                "slyric":"",
                "duration": "4:47"
            },
        ]
    },
    {
        "imageUrl": "genpx2.png",
        "artist": "Artist2",
        "name": "Second Album",
        "release":"20xx",
        "slist":[
            {
                "tnumbr": 1,
                "stitle":"OldLocal2",
                "slink":"OldLocal.mp3",
                "duration": "2:47"
            },
            {
                "tnumbr": 2,
                "stitle":"AllOverAgain2",                
                "slink":"AllOverAgain.mp3",
                "slyric":"",
                "duration": "4:47"
            },
            {
                "tnumbr": 3,
                "stitle":"Causes of the Causes2",
                "slink":"Causes of the Causes.mp3",
                "slyric":"",
                "duration": "2:47"
            },
            {
                "tnumbr": 4,
                "stitle":"Good Lord Willin and the Creeks Don’t Rise2",
                "slink":"Good Lord Willin and the Creeks Don’t Rise.mp3",
                "slyric":"",
                "duration": "4:47"
            },
        ]
    }
]
var lgimg=$(`  ${musData.map((cover) => {
          return `<img class="lgimg" src="images/music_imgs/covers/${cover.imageUrl}">
      `
      }).join('')
      }`)
var lgcv=$('#lgcv');
$( lgcv ).append( lgimg );
$( dots ).before( lgimg );

var info=$(` ${musData.map(( albuminfo ) =>{return `
    <div id="info">
                        <span class="name">${albuminfo.name}</span>
                        <span class="artist">${albuminfo.artist}</span>
    </div>
            `
      }).join('')       
}`)
var albtitle=$('#albtitle');
$( albtitle ).append( info );

var smimg=$(`  ${musData.map((cover) => {
          return `<img class="smimg" id="cover" style="width:75px" src="images/music_imgs/covers/${cover.imageUrl}">
      `
      }).join('')
      }`)      
var smcv=$('#smcv');
$( smcv ).append( smimg );

var songt = $(`${musData.map(function(tsong) {
    return `
        <div class="songt">
            ${tsong.slist.map(function(items){
                return`
                    <div id="title">${items.stitle}</div>
                    <audio id="audio" src="media/${items.slink}"</audio>
                    `
            }).join('')}
        </div>
        `
      }).join('')
}`);
var audioinfo=$('.audioinfo');
$( audioinfo ).append ( songt );

var albtunes = $(`${musData.map(function(tlist) {
    return `
        <div class="song-list">
            ${tlist.slist.map(function(item){
                return`
                    <div id="albtunes" class="activemus"><li>
                        <span class="numbr">${item.tnumbr}.&nbsp;</span>
                        <span class="song">${item.stitle}
                            <audio src="media/${item.slink}" id="audio"></audio></span>
                        <span class="time">${item.duration}</span>
                    </li></div>
                    `
            }).join('')}
        </div>
            `
      }).join('')
}`);
var tunes=$('#tunes');
$( tunes ).append ( albtunes );

//    <p class="footer">these ${musData.length} albums are previous releases. more releases to come. please check back soon for updates</p>

//albumsimgs, albumnames, tracks
var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(slideIndex += n);
}

function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var lgcv = document.querySelectorAll('.lgimg');
  var dots = document.getElementsByClassName("dot");
  var smcv = document.querySelectorAll('.smimg');
  var info = document.querySelectorAll('#info');
//  var songt = document.querySelectorAll('.songt');
  var tracks = document.querySelectorAll('.song-list');

  if (n > lgcv.length) {slideIndex = 1}    
  if (n < 1) {slideIndex = lgcv.length}
  for (i = 0; i < lgcv.length; i++) {
      lgcv[i].style.display = "none";  
  };

  for (i = 0; i < dots.length; i++) {
      dots[i].className = dots[i].className.replace("active", "");
  };
  
  if (n > smcv.length) {slideIndex = 1}    
  if (n < 1) {slideIndex = smcv.length}
  for (i = 0; i < smcv.length; i++) {
      smcv[i].style.display = "none";  
  };
  
  if (n > info.length) {slideIndex = 1}    
  if (n < 1) {slideIndex = info.length}
  for (i = 0; i < info.length; i++) {
      info[i].style.display = "none";  
  };
  
 // if (n > songt.length) {slideIndex = 1}    
//  if (n < 1) {slideIndex = songt.length}
//  for (i = 0; i < songt.length; i++) {
//      songt[i].style.display = "none";  
//  };

  if (n > tracks.length) {slideIndex = 1}    
  if (n < 1) {slideIndex = tracks.length}
  for (i = 0; i < tracks.length; i++) {
      tracks[i].style.display = "none";  
  };
 
 lgcv[slideIndex-1].style.display = "block";  
 dots[slideIndex-1].className += " active";
 smcv[slideIndex-1].style.display = "block";  
 info[slideIndex-1].style.display = "block";
 //songt[slideIndex-1].style.display = "inline-block";  
 tracks[slideIndex-1].style.display = "block";  
};

//Hide Pause
$('#pause').hide();
const controls = document.getElementById('controls');
const tune = document.getElementById('tunes');
const activemus = document.getElementsByClassName('activemus');
const playBtn = document.getElementById('play');
const pauseBtn = document.getElementById('pause');
const prevBtn = document.getElementById('prev');
const nextBtn = document.getElementById('next');
const audio = document.getElementById('audio');
const progress = document.getElementById('progress');
const progressContainer = document.getElementById('progress-container');
const title = document.getElementById('title');
//const cover = document.getElementById('cover');

// Song titles
const songs = title

// Keep track of song
let songIndex = 0;

// Initially load song details into DOM
loadSong(songs[songIndex]);

// Update song details
function loadSong(song) {
  title.innerText = song;
  audio.src = `media/${song}.mp3`;
 // tune.src = `media/${song}.mp3`;
  //  cover.src = `images/music_imgs/covers/${song}.png`;
}
// Play song
function playSong() {
  controls.classList.add('play');
 // activemus.classList.add('tune');
  playBtn.classList.remove('play');
  playBtn.classList.add('pause');
  audio.play();
}
// Pause song
function pauseSong() {
  controls.classList.remove('play');
 // activemus.classList.remove('tune');
  playBtn.classList.add('play');
  playBtn.classList.remove('pause');
  audio.pause();
}
// Previous song
function prevSong() {
  songIndex--;
  if (songIndex < 0) {
    songIndex = songs.length - 1;
  }
  loadSong(songs[songIndex]);
  playSong();
}
// Next song
function nextSong() {
  songIndex++;
  if (songIndex > songs.length - 1) {
    songIndex = 0;
  }
  loadSong(songs[songIndex]);
  playSong();
}


// Update progress bar
function updateProgress(e) {
  const { duration, currentTime } = e.srcElement;
  const progressPercent = (currentTime / duration) * 100;
  progress.style.width = `${progressPercent}%`;
}
// Set progress bar
function setProgress(e) {
  const width = this.clientWidth;
  const clickX = e.offsetX;
  const duration = audio.duration;

  audio.currentTime = (clickX / width) * duration;
}

//get duration & currentTime for Time of song
function DurTime (e) {
    const {duration,currentTime} = e.srcElement;
    var sec;
    var sec_d;

    // define minutes currentTime
    let min = (currentTime==null)? 0:
     Math.floor(currentTime/60);
     min = min <10 ? '0'+min:min;

    // define seconds currentTime
    function get_sec (x) {
        if(Math.floor(x) >= 60){

            for (var i = 1; i<=60; i++){
                if(Math.floor(x)>=(60*i) && Math.floor(x)<(60*(i+1))) {
                    sec = Math.floor(x) - (60*i);
                    sec = sec <10 ? '0'+sec:sec;
                }
            }
        }else{
            sec = Math.floor(x);
            sec = sec <10 ? '0'+sec:sec;
         }
    } 

    get_sec (currentTime,sec);

    // change currentTime DOM
    currTime.innerHTML = min +':'+ sec;

    // define minutes duration
    let min_d = (isNaN(duration) === true)? '0':
        Math.floor(duration/60);
     min_d = min_d <10 ? '0'+min_d:min_d;


     function get_sec_d (x) {
        if(Math.floor(x) >= 60){

            for (var i = 1; i<=60; i++){
                if(Math.floor(x)>=(60*i) && Math.floor(x)<(60*(i+1))) {
                    sec_d = Math.floor(x) - (60*i);
                    sec_d = sec_d <10 ? '0'+sec_d:sec_d;
                }
            }
        }else{
            sec_d = (isNaN(duration) === true)? '0':
            Math.floor(x);
            sec_d = sec_d <10 ? '0'+sec_d:sec_d;
         }
    } 

    // define seconds duration

    get_sec_d (duration);

    // change duration DOM
    durTime.innerHTML = min_d +':'+ sec_d;

};

// Event listeners
playBtn.addEventListener('click', () => {
  const isPlaying = controls.classList.contains('play');

  if (isPlaying) {
    pauseSong();
  } else {
    playSong();
  }
});




// Change song
prevBtn.addEventListener('click', prevSong);
nextBtn.addEventListener('click', nextSong);

// Time/song update
audio.addEventListener('timeupdate', updateProgress);

// Click on progress bar
progressContainer.addEventListener('click', setProgress);

// Song ends
audio.addEventListener('ended', nextSong);

// Time of song
audio.addEventListener('timeupdate',DurTime);

Webpack thinks classes in unused code are distinct

I have a class Vec2 which is used throughout my project. The function getBoundingBox() is unused:

let x = new Vec2();
export function getBoundingBox( prims, padding ) {
    let min = new Vec2( null, null );

when I run webpack (config below), every instance of Vec2 in the collated file is replaced by Vec2_Vec2, while the unused call in getBoundingBox() remains as Vec2, like so:

let x = new Vec2_Vec2();
export function getBoundingBox( prims, padding ) {
    let min = new Vec2( null, null );

The obvious fix is to remove the unused code, but I am curious if there is an option to automatically ignore unused code and not include it in the final output. My webpack config is below:

webpack 5.46.0
webpack-cli 4.7.2

{
  entry: {
    app: './build/app.js',
  },
  output: {
    filename: '[name].js',
    path: path.resolve('.', 'dist'),
  },
  devtool: 'inline-source-map',
  optimization: {
    minimize: false,
  },
}

PIXI.js SpriteSheet – Uncaught TypeError: Cannot set properties of undefined (setting ‘_parentID’)

I was trying to use PIXI.js to create an animation on the web. I needed to load a spritesheet with PIXI.Loader.Shared.add() and then use it with PIXI.AnimatedSprite() to create the animation.

This is my code with bugs:

PIXI.Loader.Shared.add(`assets/0.json`).load(sceneLoad);

function sceneLoad() {
  const scene = new PIXI.Container();
  const s = PIXI.Loader.Shared.resources["assets/0.json"].spritesheet.textures;

  let eyes = [s['Eyes.png'], s['ClosedEyes.png']]; 
  eyes = new PIXI.AnimatedSprite(eyes);
  scene.addChild(eyes); // Where the error occurs
}

This is the error I had:

Uncaught TypeError: Cannot set properties of undefined (setting '_parentID')
    at e.addChild (pixi.min.js:8)
    at sceneLoad (scenes.js:40)
    at t.dispatch (pixi.min.js:8)
    at e._onComplete (pixi.min.js:8)
    at pixi.min.js:8
    at s (pixi.min.js:8)
    at e.use (pixi.min.js:8)
    at pixi.min.js:8
    at pixi.min.js:8

I checked this thread with the same error. But it was about a different PIXI.js method. And I checked this thread with the same error. But the answer wasn’t explained and was about a different PIXI.js method.

This is the spritesheet I was using with its JSON:

{"frames": {
"ClosedEyes.png":
{
    "frame": {"x":500,"y":0,"w":500,"h":700},
    "rotated": false,
    "trimmed": false,
    "spriteSourceSize": {"x":0,"y":0,"w":500,"h":700},
    "sourceSize": {"w":500,"h":700}
},
"Eyes.png":
{
    "frame": {"x":0,"y":700,"w":500,"h":700},
    "rotated": false,
    "trimmed": false,
    "spriteSourceSize": {"x":0,"y":0,"w":500,"h":700},
    "sourceSize": {"w":500,"h":700}
}},
"meta": {
    "app": "https://www.codeandweb.com/texturepacker",
    "version": "1.0",
    "image": "1.png",
    "format": "RGBA8888",
    "size": {"w":1373,"h":1482},
    "scale": "1",
    "smartupdate": "$TexturePacker:SmartUpdate:f87f23b00c6d9d315163af7aa5edde4e:c4a362a6939011366e8ebf2df4b161e1:f91cade670d3cd0da3efe30dce0ef325$"
}
}

How to convert div of html to pdf with selectable text and preserved CSS?

I am trying to build a resume builder using reactjs but the problem that I am facing is that I want the user to get the pdf version of their resume on clicking the download button. But don’t know how to achieve that. I had tried jsPDF and it is converting div to pdf but not preserving CSS. I had also tried jsPDF with html2canvas but again it is converting div to pdf with preserved CSS but that pdf is kind of image and the text in not selectable and links are not clickable which is a bad characteristic for a resume. Please help me with this.

Any resource will be helpful.
Thanks

General Question about API’s and working with them in Node and JavaScript

I have been in a steep learning curve lately, trying to learn as much as possible about NodeJS and Backend-development in general. I have a project set up and I want to be able to flip some switches on a Website, that then tells the Node-Server what to do, which then makes a call to an API and all the way back to displaying it in the browser. I’ve already worked with promises, but I don’t specifically know how to approach this. Could you maybe provide me with an oversimplified example?

Thank you so much in advance and have a great rest of your day!

Javascript rest api tests

const express = require('express');
    const bodyParser = require('body-parser');
    const Sequelize = require('sequelize');
    const { STRING, INTEGER } = require('sequelize');

    const sequelize = new Sequelize({
      dialect: 'sqlite',
      storate: 'homework.db'
    });

    const Student = sequelize.define('student', {
      name: Sequelize.STRING,
      address: Sequelize.STRING,
      age: Sequelize.INTEGER
    }, {
      timestamps: false
    });

    const app = express();
    app.use(bodyParser.json());

    app.get('/create', async (req, res) => {
      try {
        await sequelize.sync({ force: true });
        for (let i = 0; i < 10; i++) {
          const student = new Student({
            name: 'name ' + i,
            address: 'some address on ' + i + 'th street',
            age: 30 + i
          });
          await student.save();
        }
        res.status(201).json({ message: 'created' });
      } catch (err) {
        console.warn(err.stack)
        res.status(500).json({ message: 'server error' });
      }
    });

    app.get('/students', async (req, res) => {
      try {
        const students = await Student.findAll();
        res.status(200).json(students);
      } catch (err) {
        console.warn(err.stack);
        res.status(500).json({ message: 'server error' });
      }
    });

    app.post('/students', async (req, res) => {
      try {
        //TODO
        if (req.body !== null) {
          const student = await Student.create(req.body);
          if (!(typeof(student.name) === STRING && typeof(student.address) === STRING && typeof(student.age) === INTEGER)) {
            if (student.age > 0) {
              return res.status(201).json({ message: "created" });
            } else {
              res.status(400).json({ message: "age should be a positive number" });
            }
          } else {
            res.status(400).json({ message: "malformed request" });
          }
        } else {
          res.status(400).json({ message: "body is missing" });
        }
      } catch (err) {
        console.warn(err.stack);
        res.status(500).json({ message: 'server error' });
      }
    });

    module.exports = app;

Right sooo I have a little school project here with apparently some simple http verbs implemented in node js. The problem is that I have some tests defined(all of them related to the last POST method) and out of five, only two of them pass and idk why. Can anyone tell how should I modify that post in order for the tests to be satisfied? The first code is the app js file and the second one is the server side.

The tests are as follws:

  • if request body is not sent server should respond with status code 400 and {“message”:”body is missing} -> failed

  • if request body is present but did not follow the specified format, server should respond with status code 400 and {“message”:”malformed request”} -> failed

  • age should not be negative -> passed

  • a student can be added -> passed

  • the student list is valid -> failed

    const app = require('./app')
    
    app.listen(8080, () => {
      console.log('Server started on port 8080...')
    })

Run simple js when Component is fully rendered in React functional component

This a (very) simplified version of my component:

export const DynamicComponent: FC<DynamicComponentProps> = (props) => {
  const ref = useRef<HTMLElement>(null);
  const [isSticked, setIsSticked] = useState(false);
  const parentSticked = useContext(StickyContext);
  const [overridedStyles, setOverridedStyles] = useState(props.styles ?? {});
  const [overridedArgs, setOverridedArgs] = useState(props.args ?? {});
  const { config } = useContext(GlobalContext);
  const data = useContext(DataContext);
  const [state, setState] = useContext(StateContext);

  const mountComponent = useMemo(() => {
    if (typeof props.mount === "undefined") return true;
    if (typeof props.mount === "boolean") return props.mount;
    if (typeof props.mount === "number") return props.mount === 1;
    if (typeof props.mount === "string") {
      let mount = stateParser.parse(props.mount, state) as unknown;
      return mount == true;
    }
    return false;
  }, [state, props.mount]);



  useLayoutEffect(() => {
    setTimeout(() => {
      const anchorHash = location.hash;
      if (
        anchorHash &&
        document &&
        document.querySelector(anchorHash) &&
        !document
          .querySelector(anchorHash)
          ?.classList.contains("already-scrolled")
      ) {
        document?.querySelector(anchorHash)?.scrollIntoView();
        document?.querySelector(anchorHash)?.classList.add("already-scrolled");
      }
    }, 50);
  }, []);

  let output = mountComponent ? (
    <StickyContext.Provider value={{ sticked: isSticked }}>
      <StyledDynamicComponent
        {...props}
        ref={ref}
        isSticked={applyStickedStyles}
        args={overridedArgs}
        styles={overridedStyles}
      />
    </StickyContext.Provider>
  ) : null;

  return output;
};

The code inside the useLayoutEffect won’t run correctly without the setTimeout because the component is not fully rendered and document?.querySelector(anchorHash) does not exist yet..

Tried with a window.onload but the code inside it will never run..

Is there a way to prevent using that horrendous setTimeout?

What’s wrong with the piece of JS Code to toggle between classes?

I want to use JavaScript code to toggle between two classes.

What’s wrong with this code that I finally got:

<script>
function tog() {
    var para = document.querySelector(".tn, .on");

    if(para.classList.contains("tn")) {
        para.classList.remove("tn");
        para.classList.add("on");
    }
    else if (para.classList.contains("on")) {
        para.classList.remove("on");
        para.classList.add("tn");

    }
}
</script>

Dynamic minmax values inside styled component

I’m trying to make the 250px number inside the minmax function dynamic inside a styled component.

Normally I could just use something like this:

minmax(${props => props.minWidth}, 1fr)

But this breaks instantly and won’t even render because it’s invalid syntax.

This is my code right now without it being dynamic. Any ideas much appreciated 🙂

const GridContainer = styled.div`
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  grid-auto-rows: auto;
  grid-gap: 20px;
  width: 100%;
`;