Javascript convert uploaded image to canvas.toDataURL()

I need the data url of the image to be in:

 'data:image/jpeg;base64,""'.

format

So my first solution is to render the uploaded image as an Image element, and use canvas.drawImage(imageElement), to get canvas.toDataURL(), but I’m getting the canvas has been tainted Error.

Curious is there any alternative way to get the data url of the uploaded image?

Thanks.

How can I animate when rendering and unmount a component in React?

I trying animate a component when rendering and unmount it in React, but unsuccessfully.

Component to animate

One of the ways I’ve tried was create a state (fade) with the class of animation property, when rendering, the class is fadeIn and on will unmount the class is fadeOut

const handlePokemonDetails = async () => {

    if (pokemonDetails === true){
        setFade(styles.fadeOut)
        await timeout(500)
    }

    else{
        setFade(styles.fadeIn)
    }

    setPokemonDetails(!pokemonDetails)

}

…

<div className={pokemonDetails ? styles.pokemonDetails + " " + fade : ""}></div>

SASS code:

    .pokemonDetails
       position: absolute
       top: 0
       z-index: 3
       display: flex
       width: 35vmin
       height: 39.5vmin
       flex-direction: column
       background-color: rgba(210, 210, 210, 0.85)
       border-radius: 10px

    @keyframes fade
       0%
         height: 0vmin
       100%
         height: 39.5vmin

    .fadeIn
       animation: fade 0.5s normal
    
    .fadeOut
       animation: fade 0.5s reverse

But, when I change state to other class, the component don’t apply this new class animation style. Does anyone know how I can fix this or another way to do it?

Javascript: how to revert all but one style

I have a calculator app, that when you click ‘close’, will close the calculator app and show a thank you message instead. closeCalculator.style.display = 'none'; ensures that once the button is clicked, it will become hidden and the user can’t click it again, fully closing the app.

Problem is, I need to also make a hover effect for the buttons, but whenever I remove the hover effect styles, it also reverts the style for the close button and it will not be hidden once its clicked anymore.

I’ve tried adding closeCalculator.style.display = 'none'; after allButtons.style = 'revert';, I’ve even tried having the default value of the close button to be hidden so that it reverts to being hidden, but that doesn’t work either since it resets every time my cursor stops hovering over the close button, thus hiding the close button while the calculator app is still active.

Is there a simple way for me to revert these style values without manually pasting the original (non-hovered) styles?

    // Close button: closes calculator, shows message

const container = document.querySelector(".calculator");
const closeCalculator = document.querySelector(".end");

closeCalculator.addEventListener("click", (e) =>{
    container.innerHTML = "Thank you for using this calculator!";
    container.style.fontSize = '1.7rem';
    container.style.fontWeight = 'bold';
    container.style.textAlign = 'center';
    closeCalculator.style.display = 'none';
})

   // Hover effect

const allButtons = document.querySelectorAll("button");

allButtons.forEach(allButtons => {
    allButtons.addEventListener("mouseenter", (e) =>{
        allButtons.style.backgroundColor = 'rgb(211, 143, 202)';
        allButtons.style.border = '2px white solid';
        allButtons.style.cursor = 'pointer';
    })
    
    allButtons.addEventListener("mouseleave", (e) =>{
        allButtons.style = 'revert';
    })
});

Compare and sort all the keys values in an Array using JS

I am looking for a solution where I want an array object to be sorted based on the all the keys in an array.

Let’s say I have array like given below:

[
  {
    interested: 2,
    messageTimeDiffPercentage: 1.2280500666666667,
    availability: 5,
    ranking: '60'
  },
  {
    interested: 0,
    messageTimeDiffPercentage: 1.04,
    availability: 0,
    ranking: '10'
  },
  {
    interested: 3,
    messageTimeDiffPercentage: 2.56,
    availability: 3,
    ranking: '30'
  }
]

Here, I am looking to sort on all the keys (interested, messageTimeDiffPercentage, availability and ranking) within the array and whichever is higher should come at top (0th position).

In this example interested and messageTimeDiffPercentage is greater in 2nd element but availability and ranking is greater in 0th element. 1st element is having less values for all keys. So the sorted array will be like below:

[
  {
    interested: 2,
    messageTimeDiffPercentage: 1.2280500666666667,
    availability: 5,
    ranking: '60'
  },
  {
    interested: 3,
    messageTimeDiffPercentage: 2.56,
    availability: 3,
    ranking: '30'
  },
  {
    interested: 0,
    messageTimeDiffPercentage: 1.04,
    availability: 0,
    ranking: '10'
  }
]

Looking for a most feasible solution. Thanks in advance.

Mapping array in javacript app in a react app

This is my array, I’m working on react app

const categoryObj = [
    {
        id: "463e989a-c4f2-4616-85c5-0cb610c5fff0",
        name: "Women",
        subCategory: [
            {
                id: "91ba7308-b68e-4d0c-85d8-0cc8272c6bc8",
                name: "All",
                icon: "AllIcon"
            },
            {
                id: "0e0712c5-0b5a-4d4e-acf5-3d7faf2caa2a",
                name: "Clothes",
                icon: "ClothesIcon",
                sections: [
                    {
                        id: "9b7a7a58-04a1-4aba-ba68-0e6b1390021e",
                        name: "All",
                        href: "Women/Clothes/All".split(' ').join('-').trim().toLowerCase()
                    }
                ]
            }
        ]
    }
]

how can I access “women” in this array ? (I have many items like “women” this is just a sample of a large array. if you can suggest a mapping method it’s better.)

accept is not working in file type in react

I am creating a file upload component in which I have to allow only xls or xlsx file.I am writing below code.

      <div>
        <form onSubmit={handleSubmit}>
          <input type="file" accept="xlsx/*" required  onChange={handleChange}/>
          <button type="submit" className='submitbutton'>Import Bulk User</button>
        </form>
      </div>

but it is not restricting other file types.

enter image description here

how can I restrict other file types and allow only xlsx

How to make a customisable combobx using javascrpit inside a json

I know by far it’s not the best way, but I got this freelancer and I necessarily have to just use the available code. So i have this json whit the all values from my two combos, the TipoPoste and AlturaPoste:

    "switch_to_combo_after":12,
    "title":"Cemat",
    "elements":[
        {   "name":"PT",
            "title":"Poste",
            "attributes": [ 
                {   "name":"tipoposte",
                    "title":"Tipo de poste",
                    "values": [ 
                        {"title":"Tipo", 
                            "name": "TipoPoste", 
                            "required":true,                            
                            "onAfterChange":function(ele,attName){return cemat.Set_ALTURAESFORCO(ele,attName);},
                            "default_value":"",
                            "value": [ 
                                "CI","Base Cabine",
                                "DT","Duplo T",
                                "FI","Poste de Fibra",
                                "MA","Madeira", 
                                "TC","Tubular de Concreto",
                                "TR","Trilho",
                                "?", "Dúvida"
                            ] 
                            
                        },
                        {"title":"Foto Geral", 
                            "name": "FotoPrincipal", 
                            "required":true,
                            "default_value":"",
                            "enabled":true,
                            "control_type":"link",
                            "link":"",
                            "value": ""
                        }
                    ]
                },
                {   "name":"alturaesforco",
                    "title":"Altura/Esforço",
                    "values": [
                        { "title":"Altura", 
                            "name": "AlturaPoste", 
                            "required":true,
                            "default_value":"",
                            "value": [ 
                                "ILG", "ILEGIVEL",
                                "1", "1 m",
                                "6", "6 m",
                                "7", "7 m",
                                "7.5", "7.5 m",
                                "8", "8 m",
                                "9", "9 m",
                                "10", "10 m",
                                "11", "11 m",
                                "12", "12 m",
                                "13", "13 m",
                                "14", "14 m",
                                "15", "15 m",
                                "16", "16 m",
                                "17.5", "17.5 m",
                                "18", "18 m",
                                "19", "19 m",
                                "20", "20 m",
                                "20.5", "20.5 m",
                                "21", "21 m",
                                "22", "22 m",
                                "23", "23 m",
                                "24", "24 m",
                                "25", "25 m",
                                "?", "Dúvida"
                            ] 
                        }

And he calls this ‘function’ inside from the same json who change a single value from the AlturaPoste combobox when i choose one value from TipoPoste

/**
     * Change the Altura.
     *
     * @ele Element being changed
 @attName  Attribute that received the event.
     */
    this.Set_ALTURAESFORCO = function(ele,attName) {
      
      // var ele = attr.getElementPaiObject();
      
      if(ele.getAttributeValue(attName) == "CI") {
            ele.setAttributeValue("AlturaPoste", "ILG");
            ele.setEnabled("AlturaPoste", false);
            ele.setAttributeValue("EsforcoPoste", "ILG");
            ele.setEnabled("EsforcoPoste", false);
            ele.setAttributeValue("regra_alt_esf", "yes");
            ele.setEnabled("regra_alt_esf", false); 
            
        }
        
        else if(ele.getAttributeValue(attName) == "TR") {
            ele.setAttributeValue("AlturaPoste", "ILG");
            ele.setEnabled("AlturaPoste", false);
            ele.setAttributeValue("EsforcoPoste", "32");
            ele.setEnabled("EsforcoPoste", false);
            ele.setAttributeValue("regra_alt_esf", "yes");
            ele.setEnabled("regra_alt_esf", false); 
            
        }           
        
        else {
                    ele.setAttributeValue("AlturaPoste", "");
                    ele.setEnabled("AlturaPoste", true);
                    ele.setAttributeValue("EsforcoPoste", "");
                    ele.setEnabled("EsforcoPoste", true);
                    ele.setEnabled("regra_alt_esf", true);
                    ele.setAttributeValue("regra_alt_esf", "no");                   

                }

      return null;
    }

So how can i make,only using javascript, when i select a single value from the “TipoPoste” change the entire array value from “AlturaPoste”?

ReactJS-FullStack-CRUD-App: Axios not working, Error code 400 on console

I first take my time to thank you for reading this. I am desperately in need of your help. I know there are many questions out there that are similar to this and have been answered but I tried my best to follow them all. Nothing worked, so I would like a direct answer to my problem via this post. Refer to this and you will know what I’m talking about: https://youtu.be/FX5HE_gnOTI

I have a couple problems that may be related to one and another. So I followed mostly what the guy in the video did but there is a problem in my work that says otherwise: When I hit the VIEW button, the information submitted doesn’t populate. When I hit the DELETE button, it does not delete the item. (I have to manually send a request via Postman Agent and refresh the browser to see it delete.) And when I hit the EDIT button, it would not save and go back the main page when I hit SAVE. I have spent hours researching and debugging but none of them worked. Your help will be much appreciated and a huge thank you (I deeply mean it), if you managed to help me fix it.

The console of my application.

import React, { Component } from 'react'
import StudentService from '../services/StudentService';

class UpdateStudentComponent extends Component {
    constructor(props) {
        super(props)

        this.state = {
            id: this.props.match.params.id,
            firstName: '',
            lastName: '',
            emailId: ''
        }
        this.changeFirstName = this.changeFirstName.bind(this);
        this.changeLastName = this.changeLastName.bind(this);
        this.changeEmail = this.changeEmail.bind(this);
        this.updateStudent = this.updateStudent.bind(this);
    }

    componentDidMount() {
        StudentService.getStudentId(this.state.id).then((res) => {
            let student = res.data;
            this.setState
            ({firstName: student.firstName,
                lastName: student.lastName,
                emailId: student.emailId
            });
        });
    }

    updateStudent = (e) => {
        e.preventDefault();

        let student = {firstName: this.state.firstName, lastName: this.state.lastName, emailId: this.state.emailId};
        console.log('student => ' + JSON.stringify(student));
        console.log('id => ' + JSON.stringify(this.state.id));

        StudentService.updateStudent(student, this.state.id).then(res => {
            this.props.history.push('/students');
        });
    }
    
    changeFirstName = (event) => {
        this.setState({firstName: event.target.value});
    }

    changeLastName = (event) => {
        this.setState({lastName: event.target.value});
    }

    changeEmail = (event) => {
        this.setState({emailId: event.target.value});
    }

    cancel() {
        this.props.history.push('/students');
    }

    render() {
        return (
            <div>
                <br></br>

                   <div className = "container">
                        <div className = "row">
                            <div className = "card col-md-6 offset-md-3 offset-md-3">
                                <h3 className="text-center">Update Student</h3>

                                <div className = "card-body">
                                    <form>
                                        <div className = "form-group">
                                            <label> First Name: </label>
                                            <input placeholder="First Name" name="firstName" className="form-control" 
                                                value={this.state.firstName} onChange={this.changeFirstName}/>
                                        </div>

                                        <div className = "form-group">
                                            <label> Last Name: </label>
                                            <input placeholder="Last Name" name="lastName" className="form-control" 
                                                value={this.state.lastName} onChange={this.changeLastName}/>
                                        </div>

                                        <div className = "form-group">
                                            <label> Email Id: </label>
                                            <input placeholder="Email Address" name="emailId" className="form-control" 
                                                value={this.state.emailId} onChange={this.changeEmail}/>
                                        </div>

                                        <button className="btn btn-success" onClick={this.updateStudent}> Save </button>
                                        <button className="btn btn-danger" onClick={this.cancel.bind(this)} style={{marginLeft: "10px"}}> Cancel </button>
                                    </form>
                                </div>
                            </div>
                        </div>

                   </div>
            </div>
        )
    }
}

export default UpdateStudentComponent
import React, { Component } from 'react'
import StudentService from '../services/StudentService'

class ListStudentComponent extends Component {
    constructor(props) {
        super(props)

        this.state = {
                students: []
        }
        this.addStudent = this.addStudent.bind(this);
        this.editStudent = this.editStudent.bind(this);
        this.deleteStudent = this.deleteStudent.bind(this);
    }

    deleteStudent(id) {
        StudentService.deleteStudent(id).then(res => {
            this.setState({students: this.state.students.filter(student => student.id !== id)});
        }).catch(error => console.log(error));
    }

    viewStudent(id){
        this.props.history.push(`/view-student/${id}`);
    }

    editStudent(id){
        this.props.history.push(`/add-student/${id}`);
    }

    componentDidMount(){
        StudentService.getStudents().then((res) => {
            this.setState({students: res.data});
        });
    }

    addStudent(){
        this.props.history.push('/add-student/_add');
    }

    render() {
        return (
            <div>
                 <h2 className="text-center">Students List</h2>

                 <div className = "row">
                    <button className="btn btn-primary" onClick={this.addStudent}> Add Student </button>
                 </div>

                 <br></br>

                 <div className = "row">
                        <table className = "table table-striped table-bordered">

                            <thead>
                                <tr>
                                    <th> Student First Name</th>
                                    <th> Student Last Name</th>
                                    <th> Student Email Id</th>
                                    <th> Actions</th>
                                </tr>
                            </thead>

                            <tbody>
                                {
                                    this.state.students.map(
                                        student => 
                                        <tr key = {student.id}>
                                             <td> {student.firstName} </td>   
                                             <td> {student.lastName}</td>
                                             <td> {student.emailId}</td>
                                             <td>
                                                 <button onClick={ () => this.editStudent(student.id)} className="btn btn-success"> Edit </button>
                                                 <button style={{marginLeft: "10px"}} onClick={ () => this.deleteStudent(student.id)} className="btn btn-danger"> Delete </button>
                                                 <button style={{marginLeft: "10px"}} onClick={ () => this.viewStudent(student.id)} className="btn btn-info"> View </button>
                                             </td>
                                        </tr>
                                    )
                                }
                            </tbody>
                        </table>

                 </div>

            </div>
        )
    }
}

export default ListStudentComponent
import React, { Component } from 'react'
import StudentService from '../services/StudentService'

class ViewStudentComponent extends Component {
    constructor(props) {
        super(props)

        this.state = {
            id: this.props.match.params.id,
            student: []
        }
    }

    componentDidMount() {
        StudentService.getStudentById(this.state.id).then(res => {
            this.setState({student: res.data});
        })
    }

    render() {
        return (
            <div>
                <br></br>

                <div className = "card col-md-6 offset-md-3">
                    <h3 className = "text-center"> View Student Details </h3>
                    <div className = "card-body">

                        <div className = "row">
                            <label> Student First Name: </label>
                            <div> {this.state.student.firstName} </div>
                        </div>

                        <div className = "row">
                            <label> Student Last Name: </label>
                            <div> {this.state.student.lastName} </div>
                        </div>

                        <div className = "row">
                            <label> Student Email ID: </label>
                            <div> {this.state.student.emailId} </div>
                        </div>
                    </div>

                </div>
            </div>
        )
    }
}

export default ViewStudentComponent
import axios from 'axios';

const STUDENT_API_BASE_URL = "http://localhost:8080/api/v1/students";

class StudentService {

    getStudents() {
        return axios.get(STUDENT_API_BASE_URL);
    }

    createStudent(student) {
        return axios.post(STUDENT_API_BASE_URL, student);
    }

    getStudentById(studentId) {
        return axios.get(STUDENT_API_BASE_URL + '/' + studentId);
    }

    updateStudent(student, studentId) {
        return axios.put(STUDENT_API_BASE_URL + '/' + studentId, student);
    }

    deleteStudent(studentId) {
        return axios.delete(STUDENT_API_BASE_URL + '/' + studentId);
    }
}

export default new StudentService()
package com.studentroster.springboot.controller;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import com.studentroster.springboot.exception.ResourceNotFoundException;
import com.studentroster.springboot.model.Students;
import com.studentroster.springboot.repository.StudentRepository;

@CrossOrigin(origins = "http://localhost:3000")
@RestController
@RequestMapping("/api/v1/")
public class StudentController {
    
    @Autowired
    private StudentRepository stud_rep;
    
    // GET all students
    @GetMapping("/students")
    public List<Students> getAllStudents() {
        return stud_rep.findAll();
    }
    
    // ADD student
    @PostMapping("/students")
    public Students addStudent(@RequestBody Students student) {
        return stud_rep.save(student);
    }
    
    // Get Student ID
    @GetMapping("/students/{id}")
    public ResponseEntity<Students> getStudentId(@PathVariable Long id) {
        Students stud = stud_rep.findById(id).orElseThrow(() -> new ResourceNotFoundException("Student does not exist with the id: " + id));
        return ResponseEntity.ok(stud);
    }
    
    // UPDATE student
    @PutMapping("/students/{id}")
    public ResponseEntity<Students> updateStudent(@PathVariable Long id, @RequestBody Students studentDetails) {
        Students stud = stud_rep.findById(id).orElseThrow(() -> new ResourceNotFoundException("Student does not exist with the id: " + id));
        
        stud.setFirstName(studentDetails.getFirstName());
        stud.setLastName(studentDetails.getLastName());
        stud.setEmail(studentDetails.getEmail());

        Students studentUpdated = stud_rep.save(stud);
        return ResponseEntity.ok(studentUpdated);
    }
    
    // DELETE student
    @DeleteMapping("/students/{id}")
    public ResponseEntity<Map<String, Boolean>> deleteStudent(@PathVariable Long id) {
        Students stud = stud_rep.findById(id).orElseThrow(() -> new ResourceNotFoundException("Student does not exist with the id: " + id));
        
        stud_rep.delete(stud);
        Map<String, Boolean> response = new HashMap<>();
        response.put("Deleted", Boolean.TRUE);
        
        return ResponseEntity.ok(response);
    }

}
{
  "name": "react-frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.19.2",
    "bootstrap": "^4.5.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "^3.4.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
import React from 'react';
import logo from './logo.svg';
import './App.css';
import {BrowserRouter as Router, Route, Switch} from 'react-router-dom'
import ListStudentComponent from './components/ListStudentComponent';
import HeaderComponent from './components/HeaderComponent';
import FooterComponent from './components/FooterComponent';
import CreateStudentComponent from './components/CreateStudentComponent';
import UpdateStudentComponent from './components/UpdateStudentComponent';
import ViewStudentComponent from './components/ViewStudentComponent';

function App() {
  return (
    <div>
        <Router>
              <HeaderComponent />
                <div className="container">
                    <Switch> 
                          <Route path = "/" exact component = {ListStudentComponent}></Route>
                          <Route path = "/students" component = {ListStudentComponent}></Route>
                          <Route path = "/add-student/:id" component = {CreateStudentComponent}></Route>
                          <Route path = "/view-student/:id" component = {ViewStudentComponent}></Route>
                          <Route path = "/update-student/:id" component = {UpdateStudentComponent}></Route>
                    </Switch>
                </div>
              <FooterComponent />
        </Router>
    </div>
    
  );
}

export default App;

I have posted all the necessary files. Please let me know if you have any further questions and I thank you from the bottom of my heart if you manage to fix my problem.

Javascript Map taking several minutes to set 7k keys

I have around 7k database entries I want to set into a map. I loop through the data fetched from the db and set it into the map. However, it takes a very long time (around 3 minutes), to set these keys. Is there a better way to do it rather than just looping over the entries and setting them one by one? I’m using a map for cache and run a task every minute for this cache to be updated, but the map itself takes 3 minutes for all the keys to be set.

I’m setting an object as the value, like so:

const data = await fetchDataFromDb();

for (const element of data) cache.set(element.id, element)

cache here is a class extending map (which makes no changes to set method), having some custom methods.

cache update

How I can get the same result, convert javascript function to php

Please i’m new in PHP

and I would like to convert this function from Javascript to PHP

function getColorRGBArray(color) {
const pairs = color.toString().match(/.{1,2}/g) || []

return pairs.map(cHex => (
  parseInt(cHex, 16)
))
}

I did the first part use preg_match, I don’t know how to do this part

return pairs.map(cHex => (
  parseInt(cHex, 16)
))

Different result when declaring const/var/let vs not [duplicate]

Currently trying to solved Diameter of Binary Tree problem using js. I got a weird code when I do not include const when declaring left/right. Does anyone know why?

var diameterOfBinaryTree = function(root) {
  
  const result = dfs(root, 0);
  return result[1]; 
};
const dfs = (node, diameter) => {
  if(!node)
     return [0, 0];
  
  const left = dfs(node.left, diameter);
  const right = dfs(node.right, diameter);
  let oldDiameter = Math.max(left[1], right[1], diameter);
  let newDiameter = Math.max(oldDiameter, left[0] + right[0]);
  let depth = Math.max(left[0], right[0]) + 1;
  
  return [depth, newDiameter];
}

Modal Popup on Shopify debut theme – Background Not transparent

Hi Im having an issue here: I am on shopify using debut theme.

https://8zwowlkknx08rtbm-52123107526.shopifypreview.com

For some reason the modal popup background is not transparent but showing up as white.

Im using bootstrap modal.js, bootstrap.min.css, jquery.min.js

Here is the theme.liquid file i moded.
”’

<!doctype html>
<html class="no-js" lang="{{ request.locale.iso_code }}">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <meta name="theme-color" content="{{ settings.color_button }}">

  <link rel="preload" href="{{ 'theme.css' | asset_url }}" as="style">
  <link rel="preload" href="{{ 'bootstrap.min.css' | asset_url }}" as="style">
  <link rel="preload" as="font" href="{{ header_font | font_url }}" type="font/woff2" crossorigin>
  <link rel="preload" as="font" href="{{ base_font | font_url }}" type="font/woff2" crossorigin>
  <link rel="preload" as="font" href="{{ base_font_bold | font_url }}" type="font/woff2" crossorigin>
  <link rel="preload" href="{{ 'theme.js' | asset_url }}" as="script">
  <link rel="preload" href="{{ 'lazysizes.js' | asset_url }}" as="script">
  <link rel="preload" href="{{ 'jquery.min.js' | asset_url }}" as="script">
  <link rel="preload" href="{{ 'modal.js' | asset_url }}" as="script">

  <script src="{{ 'theme.js' | asset_url }}" defer="defer"></script>
  <script src="{{ 'lazysizes.js' | asset_url }}" async="async"></script>
  <script src="{{ 'jquery.min.js' | asset_url }}" async="async"></script>
  <script src="{{ 'modal.js' | asset_url }}" async="asnyc"></script>
   
</head>

<body class="template-{{ request.page_type | handle }}">
  <a class="in-page-link visually-hidden skip-link" href="#MainContent">{{ 'general.accessibility.skip_to_content' | t }}</a>
  
  {%- if settings.enable_ajax -%}
    {% include 'cart-popup' %}
  {%- endif -%}

  {% section 'header' %}

  <div class="page-container drawer-page-content" id="PageContainer">

    <main class="main-content js-focus-hidden" id="MainContent" role="main" tabindex="-1">
      {{ content_for_layout }}
    </main>

    {% section 'footer' %}

    <div id="slideshow-info" class="visually-hidden" aria-hidden="true">
      {{- 'sections.slideshow.navigation_instructions' | t -}}
    </div>

  </div>

  <ul hidden>
    <li id="a11y-refresh-page-message">{{ 'general.accessibility.refresh_page' | t }}</li>
    <li id="a11y-selection-message">{{ 'general.accessibility.selection_help' | t }}</li>
  </ul>
  <!-- Modal popup - Discount -->
    <div class="modal fade" id="discountModalCenter" tabindex="-1" role="dialog" aria-labelledby="discountModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <!--
        <h5 class="modal-title" id="exampleModalCenterTitle">Modal title</h5>
        -->
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
                SHOW IMAGE HERE!!!
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

<script> $(document).ready(function(){
            function delaymodaltime() {
    $('#discountModalCenter').modal('show');

  };
            setTimeout(function(){ delaymodaltime(); }, 1500);

                    
});
</script>
  
</body>
</html> 

Can you please advise. in the CSS file i have already set:

.modal-backdrop.in{
    filter:alpha(opacity=0.5);
    opacity:0 !important;
}

Below is the CSS file:

/*! * Generated using the Bootstrap Customizer (https://getbootstrap.com/docs/3.4/customize/) */
/*! * Bootstrap v3.4.1 (https://getbootstrap.com/) * Copyright 2011-2019 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) */
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
html{
    font-family:sans-serif;
    -ms-text-size-adjust:100%;
    -webkit-text-size-adjust:100%
}
body{
    margin:0
}
article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{
    display:block
}
audio,canvas,progress,video{
    display:inline-block;
    vertical-align:baseline
}
audio:not([controls]){
    display:none;
    height:0
}
[hidden],template{
    display:none
}
a{
    background-color:transparent
}
a:active,a:hover{
    outline:0
}
abbr[title]{
    border-bottom:none;
    text-decoration:underline;
    text-decoration:underline dotted
}
b,strong{
    font-weight:bold
}
dfn{
    font-style:italic
}
h1{
    font-size:2em;
    margin:0.67em 0
}
mark{
    background:#ff0;
    color:#000
}
small{
    font-size:80%
}
sub,sup{
    font-size:75%;
    line-height:0;
    position:relative;
    vertical-align:baseline
}
sup{
    top:-0.5em
}
sub{
    bottom:-0.25em
}
img{
    border:0
}
svg:not(:root){
    overflow:hidden
}
figure{
    margin:1em 40px
}
hr{
    -webkit-box-sizing:content-box;
    -moz-box-sizing:content-box;
    box-sizing:content-box;
    height:0
}
pre{
    overflow:auto
}
code,kbd,pre,samp{
    font-family:monospace, monospace;
    font-size:1em
}
button,input,optgroup,select,textarea{
    color:inherit;
    font:inherit;
    margin:0
}
button{
    overflow:visible
}
button,select{
    text-transform:none
}
button,html input[type="button"],input[type="reset"],input[type="submit"]{
    -webkit-appearance:button;
    cursor:pointer
}
button[disabled],html input[disabled]{
    cursor:default
}
button::-moz-focus-inner,input::-moz-focus-inner{
    border:0;
    padding:0
}
input{
    line-height:normal
}
input[type="checkbox"],input[type="radio"]{
    -webkit-box-sizing:border-box;
    -moz-box-sizing:border-box;
    box-sizing:border-box;
    padding:0
}
input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{
    height:auto
}
input[type="search"]{
    -webkit-appearance:textfield;
    -webkit-box-sizing:content-box;
    -moz-box-sizing:content-box;
    box-sizing:content-box
}
input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{
    -webkit-appearance:none
}
fieldset{
    border:1px solid #c0c0c0;
    margin:0 2px;
    padding:0.35em 0.625em 0.75em
}
legend{
    border:0;
    padding:0
}
textarea{
    overflow:auto
}
optgroup{
    font-weight:bold
}
table{
    border-collapse:collapse;
    border-spacing:0
}
td,th{
    padding:0
}
*{
    -webkit-box-sizing:border-box;
    -moz-box-sizing:border-box;
    box-sizing:border-box
}
*:before,*:after{
    -webkit-box-sizing:border-box;
    -moz-box-sizing:border-box;
    box-sizing:border-box
}
html{
    font-size:10px;
    -webkit-tap-highlight-color:rgba(0,0,0,0)
}
body{
    font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;
    font-size:14px;
    line-height:1.42857143;
    color:#333;
    background-color:#fff
}
input,button,select,textarea{
    font-family:inherit;
    font-size:inherit;
    line-height:inherit
}
a{
    color:#337ab7;
    text-decoration:none
}
a:hover,a:focus{
    color:#23527c;
    text-decoration:underline
}
a:focus{
    outline:5px auto -webkit-focus-ring-color;
    outline-offset:-2px
}
figure{
    margin:0
}
img{
    vertical-align:middle
}
.img-responsive{
    display:block;
    max-width:100%;
    height:auto
}
.img-rounded{
    border-radius:6px
}
.img-thumbnail{
    padding:4px;
    line-height:1.42857143;
    background-color:#fff;
    border:1px solid #ddd;
    border-radius:4px;
    -webkit-transition:all .2s ease-in-out;
    -o-transition:all .2s ease-in-out;
    transition:all .2s ease-in-out;
    display:inline-block;
    max-width:100%;
    height:auto
}
.img-circle{
    border-radius:50%
}
hr{
    margin-top:20px;
    margin-bottom:20px;
    border:0;
    border-top:1px solid #eee
}
.sr-only{
    position:absolute;
    width:1px;
    height:1px;
    padding:0;
    margin:-1px;
    overflow:hidden;
    clip:rect(0, 0, 0, 0);
    border:0
}
.sr-only-focusable:active,.sr-only-focusable:focus{
    position:static;
    width:auto;
    height:auto;
    margin:0;
    overflow:visible;
    clip:auto
}
[role="button"]{
    cursor:pointer
}
.btn{
    display:inline-block;
    margin-bottom:0;
    font-weight:normal;
    text-align:center;
    white-space:nowrap;
    vertical-align:middle;
    -ms-touch-action:manipulation;
    touch-action:manipulation;
    cursor:pointer;
    background-image:none;
    border:1px solid transparent;
    padding:6px 12px;
    font-size:14px;
    line-height:1.42857143;
    border-radius:4px;
    -webkit-user-select:none;
    -moz-user-select:none;
    -ms-user-select:none;
    user-select:none
}
.btn:focus,.btn:active:focus,.btn.active:focus,.btn.focus,.btn:active.focus,.btn.active.focus{
    outline:5px auto -webkit-focus-ring-color;
    outline-offset:-2px
}
.btn:hover,.btn:focus,.btn.focus{
    color:#333;
    text-decoration:none
}
.btn:active,.btn.active{
    background-image:none;
    outline:0;
    -webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,0.125);
    box-shadow:inset 0 3px 5px rgba(0,0,0,0.125)
}
.btn.disabled,.btn[disabled],fieldset[disabled] .btn{
    cursor:not-allowed;
    filter:alpha(opacity=65);
    opacity:.65;
    -webkit-box-shadow:none;
    box-shadow:none
}
a.btn.disabled,fieldset[disabled] a.btn{
    pointer-events:none
}
.btn-default{
    color:#333;
    background-color:#fff;
    border-color:#ccc
}
.btn-default:focus,.btn-default.focus{
    color:#333;
    background-color:#e6e6e6;
    border-color:#8c8c8c
}
.btn-default:hover{
    color:#333;
    background-color:#e6e6e6;
    border-color:#adadad
}
.btn-default:active,.btn-default.active,.open>.dropdown-toggle.btn-default{
    color:#333;
    background-color:#e6e6e6;
    background-image:none;
    border-color:#adadad
}
.btn-default:active:hover,.btn-default.active:hover,.open>.dropdown-toggle.btn-default:hover,.btn-default:active:focus,.btn-default.active:focus,.open>.dropdown-toggle.btn-default:focus,.btn-default:active.focus,.btn-default.active.focus,.open>.dropdown-toggle.btn-default.focus{
    color:#333;
    background-color:#d4d4d4;
    border-color:#8c8c8c
}
.btn-default.disabled:hover,.btn-default[disabled]:hover,fieldset[disabled] .btn-default:hover,.btn-default.disabled:focus,.btn-default[disabled]:focus,fieldset[disabled] .btn-default:focus,.btn-default.disabled.focus,.btn-default[disabled].focus,fieldset[disabled] .btn-default.focus{
    background-color:#fff;
    border-color:#ccc
}
.btn-default .badge{
    color:#fff;
    background-color:#333
}
.btn-primary{
    color:#fff;
    background-color:#337ab7;
    border-color:#2e6da4
}
.btn-primary:focus,.btn-primary.focus{
    color:#fff;
    background-color:#286090;
    border-color:#122b40
}
.btn-primary:hover{
    color:#fff;
    background-color:#286090;
    border-color:#204d74
}
.btn-primary:active,.btn-primary.active,.open>.dropdown-toggle.btn-primary{
    color:#fff;
    background-color:#286090;
    background-image:none;
    border-color:#204d74
}
.btn-primary:active:hover,.btn-primary.active:hover,.open>.dropdown-toggle.btn-primary:hover,.btn-primary:active:focus,.btn-primary.active:focus,.open>.dropdown-toggle.btn-primary:focus,.btn-primary:active.focus,.btn-primary.active.focus,.open>.dropdown-toggle.btn-primary.focus{
    color:#fff;
    background-color:#204d74;
    border-color:#122b40
}
.btn-primary.disabled:hover,.btn-primary[disabled]:hover,fieldset[disabled] .btn-primary:hover,.btn-primary.disabled:focus,.btn-primary[disabled]:focus,fieldset[disabled] .btn-primary:focus,.btn-primary.disabled.focus,.btn-primary[disabled].focus,fieldset[disabled] .btn-primary.focus{
    background-color:#337ab7;
    border-color:#2e6da4
}
.btn-primary .badge{
    color:#337ab7;
    background-color:#fff
}
.btn-success{
    color:#fff;
    background-color:#5cb85c;
    border-color:#4cae4c
}
.btn-success:focus,.btn-success.focus{
    color:#fff;
    background-color:#449d44;
    border-color:#255625
}
.btn-success:hover{
    color:#fff;
    background-color:#449d44;
    border-color:#398439
}
.btn-success:active,.btn-success.active,.open>.dropdown-toggle.btn-success{
    color:#fff;
    background-color:#449d44;
    background-image:none;
    border-color:#398439
}
.btn-success:active:hover,.btn-success.active:hover,.open>.dropdown-toggle.btn-success:hover,.btn-success:active:focus,.btn-success.active:focus,.open>.dropdown-toggle.btn-success:focus,.btn-success:active.focus,.btn-success.active.focus,.open>.dropdown-toggle.btn-success.focus{
    color:#fff;
    background-color:#398439;
    border-color:#255625
}
.btn-success.disabled:hover,.btn-success[disabled]:hover,fieldset[disabled] .btn-success:hover,.btn-success.disabled:focus,.btn-success[disabled]:focus,fieldset[disabled] .btn-success:focus,.btn-success.disabled.focus,.btn-success[disabled].focus,fieldset[disabled] .btn-success.focus{
    background-color:#5cb85c;
    border-color:#4cae4c
}
.btn-success .badge{
    color:#5cb85c;
    background-color:#fff
}
.btn-info{
    color:#fff;
    background-color:#5bc0de;
    border-color:#46b8da
}
.btn-info:focus,.btn-info.focus{
    color:#fff;
    background-color:#31b0d5;
    border-color:#1b6d85
}
.btn-info:hover{
    color:#fff;
    background-color:#31b0d5;
    border-color:#269abc
}
.btn-info:active,.btn-info.active,.open>.dropdown-toggle.btn-info{
    color:#fff;
    background-color:#31b0d5;
    background-image:none;
    border-color:#269abc
}
.btn-info:active:hover,.btn-info.active:hover,.open>.dropdown-toggle.btn-info:hover,.btn-info:active:focus,.btn-info.active:focus,.open>.dropdown-toggle.btn-info:focus,.btn-info:active.focus,.btn-info.active.focus,.open>.dropdown-toggle.btn-info.focus{
    color:#fff;
    background-color:#269abc;
    border-color:#1b6d85
}
.btn-info.disabled:hover,.btn-info[disabled]:hover,fieldset[disabled] .btn-info:hover,.btn-info.disabled:focus,.btn-info[disabled]:focus,fieldset[disabled] .btn-info:focus,.btn-info.disabled.focus,.btn-info[disabled].focus,fieldset[disabled] .btn-info.focus{
    background-color:#5bc0de;
    border-color:#46b8da
}
.btn-info .badge{
    color:#5bc0de;
    background-color:#fff
}
.btn-warning{
    color:#fff;
    background-color:#f0ad4e;
    border-color:#eea236
}
.btn-warning:focus,.btn-warning.focus{
    color:#fff;
    background-color:#ec971f;
    border-color:#985f0d
}
.btn-warning:hover{
    color:#fff;
    background-color:#ec971f;
    border-color:#d58512
}
.btn-warning:active,.btn-warning.active,.open>.dropdown-toggle.btn-warning{
    color:#fff;
    background-color:#ec971f;
    background-image:none;
    border-color:#d58512
}
.btn-warning:active:hover,.btn-warning.active:hover,.open>.dropdown-toggle.btn-warning:hover,.btn-warning:active:focus,.btn-warning.active:focus,.open>.dropdown-toggle.btn-warning:focus,.btn-warning:active.focus,.btn-warning.active.focus,.open>.dropdown-toggle.btn-warning.focus{
    color:#fff;
    background-color:#d58512;
    border-color:#985f0d
}
.btn-warning.disabled:hover,.btn-warning[disabled]:hover,fieldset[disabled] .btn-warning:hover,.btn-warning.disabled:focus,.btn-warning[disabled]:focus,fieldset[disabled] .btn-warning:focus,.btn-warning.disabled.focus,.btn-warning[disabled].focus,fieldset[disabled] .btn-warning.focus{
    background-color:#f0ad4e;
    border-color:#eea236
}
.btn-warning .badge{
    color:#f0ad4e;
    background-color:#fff
}
.btn-danger{
    color:#fff;
    background-color:#d9534f;
    border-color:#d43f3a
}
.btn-danger:focus,.btn-danger.focus{
    color:#fff;
    background-color:#c9302c;
    border-color:#761c19
}
.btn-danger:hover{
    color:#fff;
    background-color:#c9302c;
    border-color:#ac2925
}
.btn-danger:active,.btn-danger.active,.open>.dropdown-toggle.btn-danger{
    color:#fff;
    background-color:#c9302c;
    background-image:none;
    border-color:#ac2925
}
.btn-danger:active:hover,.btn-danger.active:hover,.open>.dropdown-toggle.btn-danger:hover,.btn-danger:active:focus,.btn-danger.active:focus,.open>.dropdown-toggle.btn-danger:focus,.btn-danger:active.focus,.btn-danger.active.focus,.open>.dropdown-toggle.btn-danger.focus{
    color:#fff;
    background-color:#ac2925;
    border-color:#761c19
}
.btn-danger.disabled:hover,.btn-danger[disabled]:hover,fieldset[disabled] .btn-danger:hover,.btn-danger.disabled:focus,.btn-danger[disabled]:focus,fieldset[disabled] .btn-danger:focus,.btn-danger.disabled.focus,.btn-danger[disabled].focus,fieldset[disabled] .btn-danger.focus{
    background-color:#d9534f;
    border-color:#d43f3a
}
.btn-danger .badge{
    color:#d9534f;
    background-color:#fff
}
.btn-link{
    font-weight:400;
    color:#337ab7;
    border-radius:0
}
.btn-link,.btn-link:active,.btn-link.active,.btn-link[disabled],fieldset[disabled] .btn-link{
    background-color:transparent;
    -webkit-box-shadow:none;
    box-shadow:none
}
.btn-link,.btn-link:hover,.btn-link:focus,.btn-link:active{
    border-color:transparent
}
.btn-link:hover,.btn-link:focus{
    color:#23527c;
    text-decoration:underline;
    background-color:transparent
}
.btn-link[disabled]:hover,fieldset[disabled] .btn-link:hover,.btn-link[disabled]:focus,fieldset[disabled] .btn-link:focus{
    color:#777;
    text-decoration:none
}
.btn-lg{
    padding:10px 16px;
    font-size:18px;
    line-height:1.3333333;
    border-radius:6px
}
.btn-sm{
    padding:5px 10px;
    font-size:12px;
    line-height:1.5;
    border-radius:3px
}
.btn-xs{
    padding:1px 5px;
    font-size:12px;
    line-height:1.5;
    border-radius:3px
}
.btn-block{
    display:block;
    width:100%
}
.btn-block+.btn-block{
    margin-top:5px
}
input[type="submit"].btn-block,input[type="reset"].btn-block,input[type="button"].btn-block{
    width:100%
}
.fade{
    opacity:0;
    -webkit-transition:opacity .15s linear;
    -o-transition:opacity .15s linear;
    transition:opacity .15s linear
}
.fade.in{
    opacity:1
}
.collapse{
    display:none
}
.collapse.in{
    display:block
}
tr.collapse.in{
    display:table-row
}
tbody.collapse.in{
    display:table-row-group
}
.collapsing{
    position:relative;
    height:0;
    overflow:hidden;
    -webkit-transition-property:height, visibility;
    -o-transition-property:height, visibility;
    transition-property:height, visibility;
    -webkit-transition-duration:.35s;
    -o-transition-duration:.35s;
    transition-duration:.35s;
    -webkit-transition-timing-function:ease;
    -o-transition-timing-function:ease;
    transition-timing-function:ease
}
.close{
    float:right;
    font-size:21px;
    font-weight:bold;
    line-height:1;
    color:#000;
    text-shadow:0 1px 0 #fff;
    filter:alpha(opacity=20);
    opacity:.2
}
.close:hover,.close:focus{
    color:#000;
    text-decoration:none;
    cursor:pointer;
    filter:alpha(opacity=50);
    opacity:.5
}
button.close{
    padding:0;
    cursor:pointer;
    background:transparent;
    border:0;
    -webkit-appearance:none;
    appearance:none
}
.modal-open{
    overflow:hidden
}
.modal{
    position:fixed;
    top:0;
    right:0;
    bottom:0;
    left:0;
    z-index:1050;
    display:none;
    overflow:hidden;
    -webkit-overflow-scrolling:touch;
    outline:0
}
.modal.fade .modal-dialog{
    -webkit-transform:translate(0, -25%);
    -ms-transform:translate(0, -25%);
    -o-transform:translate(0, -25%);
    transform:translate(0, -25%);
    -webkit-transition:-webkit-transform 0.6s ease-out;
    -o-transition:-o-transform 0.6s ease-out;
    transition:transform 0.6s ease-out
}
.modal.in .modal-dialog{
    -webkit-transform:translate(0, 0);
    -ms-transform:translate(0, 0);
    -o-transform:translate(0, 0);
    transform:translate(0, 0)
}
.modal-open .modal{
    overflow-x:hidden;
    overflow-y:auto
}
.modal-dialog{
    position:relative;
    width:auto;
    margin:10px
}
.modal-content{
    position:relative;
    background-color:#000;
    -webkit-background-clip:padding-box;
    background-clip:padding-box;
    border:1px solid #999;
    border:1px solid rgba(0,0,0,0.2);
    border-radius:6px;
    -webkit-box-shadow:0 3px 9px rgba(0,0,0,0.5);
    box-shadow:0 3px 9px rgba(0,0,0,0.5);
    outline:0
}
.modal-backdrop{
    position:fixed;
    top:0;
    right:0;
    bottom:0;
    left:0;
    z-index:1040;
    background-color:#000
}
.modal-backdrop.fade{
    filter:alpha(opacity=0);
    opacity:0
}
.modal-backdrop.in{
    filter:alpha(opacity=0.5);
    opacity:0 !important;
}
.modal-header{
    padding:2px;
    border-bottom:1px solid #e5e5e5
}
.modal-header .close{
    margin-top:-2px
}
.modal-title{
    margin:0;
    line-height:1.42857143
}
.modal-body{
    position:relative;
    padding:15px
}
.modal-footer{
    padding:15px;
    text-align:right;
    border-top:1px solid #e5e5e5
}
.modal-footer .btn+.btn{
    margin-bottom:0;
    margin-left:5px
}
.modal-footer .btn-group .btn+.btn{
    margin-left:-1px
}
.modal-footer .btn-block+.btn-block{
    margin-left:0
}
.modal-scrollbar-measure{
    position:absolute;
    top:-9999px;
    width:50px;
    height:50px;
    overflow:scroll
}
@media (min-width:768px){
    .modal-dialog{
        width:600px;
        margin:30px auto
    }
    .modal-content{
        -webkit-box-shadow:0 5px 15px rgba(0,0,0,0.5);
        box-shadow:0 5px 15px rgba(0,0,0,0.5)
    }
    .modal-sm{
        width:300px
    }
}
@media (min-width:992px){
    .modal-lg{
        width:900px
    }
}
.clearfix:before,.clearfix:after,.modal-header:before,.modal-header:after,.modal-footer:before,.modal-footer:after{
    display:table;
    content:" "
}
.clearfix:after,.modal-header:after,.modal-footer:after{
    clear:both
}
.center-block{
    display:block;
    margin-right:auto;
    margin-left:auto
}
.pull-right{
    float:right !important
}
.pull-left{
    float:left !important
}
.hide{
    display:none !important
}
.show{
    display:block !important
}
.invisible{
    visibility:hidden
}
.text-hide{
    font:0/0 a;
    color:transparent;
    text-shadow:none;
    background-color:transparent;
    border:0
}
.hidden{
    display:none !important
}
.affix{
    position:fixed
}

But still it does not set the bg to transparent. When i try it off line it works and is transparent.
Let me know if i need to provide additional information or code.
thanks
RJ

can i use querrySelectorAll() to change the src value of a single attibute in multiple img elements? [duplicate]

  <body>

    <div class="container">
      <h1>Refresh Me</h1>

      <div class="dice">
        <p>Player 1</p>
        <img class="img1" src="test">
      </div>

  <div class="dice">
    <p>Player 2</p>
    <img class="img2" src="test">
  </div>

</div>

i was able to get this to work

document.querySelector(".dice img.im1, img.img2").src = "images/dice6.png"

because queryselectorAll gets copies of the elements, does that stop it from changing these values like I was able to with a regular querySelector?

and why wont this work?

document.querySelector(".dice img").src = "images/dice6.png"