How to apply the css on all ID starting with [duplicate]

On my website I have an AJAX search form. The HTML code displays this ID:

id="edit-field-geolocation-proximity-center-geocoder--Bq5Bx8zXA1A"

I want to apply a style to it. My problem is that the code at the end of Bq5Bx8zXA1A changes with each search.

How to style all ID starting with :

id="edit-field-geolocation-proximity-center-geocoder--"

MultiIndex dataframe into Json

I have Datframe with Multiindex and I want to transfer it to Json

this is Datframe

This is the dataframe

When I try to convert it to JSON, and I put to_json() on the orient = index, it converts all the keys to tuple

That’s why I tried to put data in this format, but it didn’t know how to do it correctly

    data = {
        '2022-01-21': {
            'SF1_8-1':
                {"Lock_Auto":0,
                 "Lock_Man":0,
                 "lability_Auto":0,
                 "lability_Man":67499,
                 "ANd":40,
                 "ANR_Remove":0,
                 "AveI":11.01470647,
                 "AveLoss":113.8496936
                },
            'S01_8-2':
                {"Lock_Auto":0,
                 "Lock_Man":0,
                 "Unavailability_Auto":0,
                 "Unavailability_Man":8475,
                 "ANd":40,
                 "ANR_Remove":0,
                 "AveI":11.01470647,
                 "AveLoss":113.8496936
                },

            'S01_8-3':
                {"Lock_Auto":0,
                 "Lock_Man":0,
                 "Unavailability_Auto":0,
                 "Unavailability_Man":8475,
                 "ANd":40,
                 "ANR_Remove":0,
                 "AveI":11.01470647,
                 "AveLoss":113.8496936
                }
        },
        '2022-01-22': {
            '001_P87-1':
                {"Lock_Auto":0,
                 "Lock_Man":0,
                 "Unavailability_Auto":0,
                 "Unavailability_Man":8475,
                 "ANd":40,
                 "ANR_Remove":0,
                 "AveI":11.01470647,
                 "AveLoss":113.8496936
                },

            },
            '001_P-2':
                {"Lock_Auto":0,
                 "Lock_Man":0,
                 "Unavailability_Auto":0,
                 "Unavailability_Man":8475,
                 "ANd":40,
                 "ANR_Remove":0,
                 "AveI":11.01470647,
                 "AveLoss":113.8496936
                },

            '001_P-3':
                {"Lock_Auto":0,
                 "Lock_Man":0,
                 "Unavailability_Auto":0,
                 "Unavailability_Man":8475,
                 "ANd":40,
                 "ANR_Remove":0,
                 "AveI":11.01470647,
                 "AveLoss":113.8496936
                },
        }
  • Question 1: Is there a way to transfer Multi_index Dataframe to Json
  • Question 2: How can I put data like this?

Map image data to an Object src for an image tag

I am trying to add an image attribute after the “description” field, and before the “tags” field.

//Card.js
const Card = (props) => {
  const { id, name, description, img_data, tags, demo, github } = props.data;
  return (
    <Box key={id} variants={item}>
      <Title>{name}</Title>
      <Description>{description}</Description>
      <DescriptionNext><image src={img_data}></image></DescriptionNext>
      <Tags>
        {tags.map((t, id) => (
          <Tag key={id}>#{t}</Tag>
        ))}
      </Tags>
      <Footer>
        <Link to={{ pathname: `${demo}` }} target="_blank">
          Visit
        </Link>
        <Git to={{ pathname: `${github}` }} target="_blank">
          <Github width={30} height={30} />
        </Git>
      </Footer>
    </Box>
  );
};

Here is the Data layout
//WorkData.js

import display from "../assets/Images/mattball.png";

export const Work = [
    {
        id:1,
        name:"Agency Landing Page",
        description:"It is build on top of the React JS, with styledComponents and GSAP for smooth scrolling animations.",
        img_data: display,
        tags:["react","gsap","styledComponents"],
        
        demo:"https://agency-website-eta.vercel.app/",
        github:"https://github.com/codebucks27/Agency-website"
    },
      /*
      ...
      ...
      ...
        */
]

Here is my directory layout:
https://imgur.com/a/9uipHHl

Without being restrictive, I understand there’s many ways to implement the image source for this tag. I would like to see a working way to implement this because I’m not sure how it works for this particular set of dependencies

How to record webcam in browser and store video on same page?

I have a simple program where a user records themselves (via their webcam) and that video is stored on the same HTML page. Can anyone let me know how I can go about adding to what I have below to record and save the video?

#HTML
<button id="speak_button"></button> #click to start video
    
<div id="circle"><p id="submit_button">Submit</p></div> #click to end video

<video" id="video" width="180" height="140" autoplay muted></video> #where webcam is 

    <video id="second_video" width="180" height="140" controls></video> #where I want recorded video to be 



#JAVASCRIPT
  <script>

    let video = document.getElementById("video");
    let mediaRecorder;
    
    navigator.mediaDevices.getUserMedia({video: true, audio: true})
    .then(function(stream){
        video.srcObject = stream;
        video.play();

        mediaRecorder = new MediaRecorder(stream, { mimeType: "video/webm"});
        mediaRecorder.ondatavailable = function(event) {

            if (event.data.size > 0) {
                const reader = new window.FileReader();
                reader.readAsDataURL(event.data);
                reader.onloadend = function() {

                    let base64 = reader.result.split('base64,')[1];

                    let recording = document.getElementById('second_video');
                    recording.src = "data:video/webm;base64," + base64;
                    recording.type = "video/webm";
                    recording.play();

                };
            };
        };

  
    });

    document.getElementById("speak_button").addEventListener("click", function() {
        mediaRecorder.start();
        stream.record();
    });

    document.getElementById("submit_button").addEventListener("click", function() {
        mediaRecorder.stop();
        stream.stop();
        var superBuffer = new Blob(recordedChunks);
        document.getElementById("second_video") = window.URL.createObjectURL(superBuffer);
    });
  
    </script>

Thanks!

Changing color of button based off data with JS

I would like to change the color of my btn based of data retrieved from an API. E.g if the data = 2 i would like it to change the class to low.

Here is my JS

function showUvIndex(data){

let UVInumber = Math.round(data.current.uvi);

uvIndex.classList = "btn btn-lg";

if (UVInumber.value == 11) {
    uvIndex.classList.add('extreme');
  } else if ([8, 9, 10].includes(UVInumber.value)) {
    uvIndex.classList.add('very-high');
  } else if ([6, 7].includes(UVInumber.value)) {
    uvIndex.classList.add('high');
  } else if ([3, 4, 5].includes(UVInumber.value)) {
    uvIndex.classList.add('moderate');
  } else if ([0, 1, 2].includes(UVInumber.value)) {
    uvIndex.classList.add('low');
  };

console.log(UVInumber);
};

And here is my CSS

.extreme{
background-color: violet;
}

.very-high {
background-color: red;
};

.high {
background-color: orange;
}

.moderate {
background-color: yellow;
};

.low {
background-color:lightgreen;
};

Why does my scroll function work with IDs but not classes?

I’m trying to add (not replace) a class to multiple elements when scrolling down 10px. I need to target multiple IDs in some HTML that I have no way of changing. These elements do share a few classes though, so I thought I could just target one of those instead.

When I use getElementById, it runs just fine and adds a class to a single ID. If I use getElementsbyClassName or querySelectorAll to target a class, it won’t work.

This one works:

tabs = document.getElementById("intro");

scrollFunc = function() {
  var y = window.scrollY;
  if (y >= 10) {
  tabs.classList.add("scrollNav");
              }
  else {
    tabs.classList.remove("scrollNav");
  }
};

window.addEventListener("scroll", scrollFunc);

This one doesn’t:

tabs = document.getElementsByClassName("navTabs");
    
    scrollFunc = function() {
      var y = window.scrollY;
      if (y >= 10) {
      tabs.classList.add("scrollNav");
                  }
      else {
        tabs.classList.remove("scrollNav");
      }
    };
    
    window.addEventListener("scroll", scrollFunc);

Use the Bluetooth API in JavaScript to connect to media output devices?

I am having some difficulties with connecting a Bluetooth audio output device with JavaScript’s navigator.bluetooth class. Help is appreciated.

Here is my JavaScript code:

function opendevicemenu() {
    if ('bluetooth' in navigator) {
        navigator.bluetooth.requestDevice({ acceptAllDevices: true }).then(devices => {
            console.log(devices)
            devices.gatt.connect()
        })
    }
}

I am also using Chrome.

index.d.ts file missing from npm pack

I am trying to add type definitions to this existing npm package: https://github.com/linchCN/react-native-swisseph

My forked repo and working branch (named typescript support) are here: https://github.com/sstephans/react-native-swisseph/tree/typescript-support

The problem I’m running into is that when I run npm pack and then install that local tarball into a project, it only shows 3 files:

index.js
package.json
README.md

However, when I run npx npm-packlist it shows me this:

index.js
package.json
README.md
index.d.ts

If I remove the "files" field in package.json entirely, it puts all the files into the tarball, but still only the same 3 as above are available in the package under node_modules.

For ease, here are what seem to be the relevant files

package.json

{
  "name": "react-native-swisseph",
  "version": "0.1.0",
  "description": "Swiss Ephemeris binding for react-native",
  "main": "index.js",
  "types": "./index.d.ts",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1"
  },
  "files": ["./index.d.ts"],
  "keywords": [
    "react-native",
    "swiss",
    "ephemeris",
    "astrology",
    "astronomy"
  ],
  "author": "linch <[email protected]>",
  "license": "MIT",
  "homepage" : "https://github.com/linchenhuicn/react-native-swisseph/",
  "bugs": {
    "url": "https://github.com/linchenhuicn/react-native-swisseph/issues"
  },
  "peerDependencies": {
    "react-native": "^0.41.2"
  }
}

**.npmignore



#################
# from .gitignore:
################


############
# Node
############
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

################
# JetBrains
################
.idea

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

./logo.png


############
# iOS
############
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
ios/build/
ios/DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
ios/xcuserdata/

## Other
*.moved-aside
*.xcuserstate

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
ios/Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md

fastlane/report.xml
fastlane/screenshots


############
# Android
############
# Built application files
*.apk
*.ap_

# Files for the Dalvik VM
*.dex

# Java class files
*.class

# Generated files
android/bin/
android/gen/
android/out/
android/app/build/

# Gradle files
android/.gradle/
android/build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
android/proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
android/.navigation/

# Android Studio captures folder
android/captures/

# Intellij
*.iml

# Keystore files
*.jks

##################
# React-Native
##################
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IJ
#
.idea
.gradle
local.properties

# node.js
#
node_modules/
npm-debug.log

# BUCK
buck-out/
.buckd/
android/app/libs
android/keystores/debug.keystore

Perform text animation by splitting text, but retain line breaks

I have created a function that maps over a sentence (provided by a CMS) and adds containers to each word. Splitting each word at spaces.

Now, some words will require line breaks, but my function is wiping them out, and I am not quite sure how I am going to retain line breaks in this case.

The demo below displays the issue I am having. The second one, although originally having a line break, has it remoed when the function runs

Any ideas or advice of how to retain the breaks will be appreciated. For the purpose of my animations, each word will require the markup in the return value of $reformatedText

let $textAreaContent;
let $splitText;
let $reformatedText;
let $delayTime;
let $delayValue;
let $textAreas = document.querySelectorAll('.stagger-text');


function setDelayValue(curCount) {
  $delayTime = 0.075;
  return parseFloat(curCount * $delayTime).toFixed(3);
}

function createStaggerContainers($textArea) {
  $textAreaContent = $textArea;
  $splitText = $textAreaContent.innerText.split(/s|<br>/g);

  $reformatedText = $splitText.map((item, i, arr) => {
    $delayValue = setDelayValue(i);
    return `<span class="stagger__container">
              <span class="stagger__text" style="animation-delay: ${$delayValue}s">${arr.length - 1 === i ? item : `${item}&nbsp;`}</span>
            </span>`;
  }).join('');

  $textAreaContent.innerText = '';
  $textAreaContent.innerHTML = $reformatedText;
}

if ($textAreas && $textAreas.length) {
  $textAreas.forEach(($textArea) => {
    createStaggerContainers($textArea);
  });
}
<div class="stagger-text">Some text here</div>
<div class="stagger-text">This has line<br> breaks</div>

Proper way to inherit an object constructor’s prototype?

In the following code, which is the correct way to inherit an object constructor’s prototype? I want Admin’s prototype to have the ‘login’ method that was previously attached to the User prototype. I’ve tried both and I’m not exactly sure which is the correct way.

function User(email, name) {
    this.email = email;
    this.name = name;
    this.online = false;
}

User.prototype.login = function() {
    this.online = true;
    console.log(this.email, 'has logged in');
}

function Admin(...args) {
    User.apply(this, args);
    this.role = 'super admin';
}

Admin.prototype = Object.create(User.prototype);  //option 1
Admin.prototype = User.prototype;                 //option 2

How can I remove a number of objects in an array?

I have an array like this :

const myArray = [ 
  {
    title: 'title',
    category: 'genetic-diseases'
  },
  {
    title: 'title',
    category: 'genetic-disorders'
  },
  { title: 'title', category: 'genetic-disorders' },
  {
    title: 'title',
    category: 'genetic-disorders'
  },
  {
    title: 'title',
    category: 'genetic-mutation'
  },
  {
    title: 'title',
    category: 'genetic-mutation'
  },
  {
    title: 'title',
    category: 'genetic-mutation'
  }
]

I only want two of each of category object in the array and remove the rest If the number of objects of that category is over 2 and get something like this :

const myArray = [ 
  {
    title: 'title',
    category: 'genetic-diseases'
  },
  { title: 'title', category: 'genetic-disorders' },
  {
    title: 'title',
    category: 'genetic-disorders'
  },
  {
    title: 'title',
    category: 'genetic-mutation'
  },
  {
    title: 'title',
    category: 'genetic-mutation'
  }
]

How can I remove the rest of the objects of a specific category If the number of those objects in the array is over 2 ?

Navbar scroll effect not working when having background color

I have a navbar having a gradient type background(slightly black, to transparent).
enter image description here

I wanted the navbar to turn completely black when scrolling, and I wrote the necessary JavaScript code, but the color changes only when I remove that background color gradient from the CSS, otherwise, it doesn’t work. Is there a solution for this?

HTML Code:

<section id="header" class="headerr">
<a href="#"><img src="images/logo.png" class="logo"></a>
<div>
  <ul id="navbar">
    <li><a class="active" href="why.html">Why Snap Smile</a></li>
    <li><a href="solutions.html">Solutions</a></li>
    <li><a href="pricing.html">Pricing</a></li>
    <li><a href="about.html">About</a></li>
    <li><a href="gallery.html">Gallery</a></li>
    <li><a href=""><i class="fa-solid fa-headset fa-2x"></i></a></li>
  </ul>
</div>

CSS code:

  body {
  font-family: 'Montserrat', sans-serif;
  width: 100%;
  margin: 0;
  background-color: #121212;
}

/* Header Section */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 80px;
  background: rgb(0,0,0);
background: linear-gradient(180deg, rgba(0,0,0,0.6629026610644257) 0%, rgba(9,9,121,0) 57%);
  z-index: 999;
  position: sticky;
  top: 0;
  left: 0;
}

.headerr__black{
  background-color: #121212;
}

#navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#navbar li {
  list-style: none;
  padding: 0 20px;
  position: relative;
}

#navbar li a {
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  color: #ffffff;
  transition: 200ms ease-in-out;
}

#navbar li a:hover,
#navbar li a.active {
  color: #e50914;
}

#navbar li a.active::after,
#navbar li a:hover::after {
  content: "";
  width: 30%;
  height: 3px;
  background: #e50914;
  position: absolute;
  bottom: -6px;
  left: 20px;
}

.logo {
  width: 10rem;
}

JavaScript Code:

const nav=document.getElementById('header');
window.addEventListener('scroll',function(){
  if(window.scrollY >= 100){
    nav.classList.add('headerr__black');
  }
  else{
    nav.classList.remove('headerr__black');
  }
});

None response from a function http in JS

I’m coding a request HTTP in a JS function, but it not work (none message in console, none response, none data). Though, is not my first time in request HTTP, but I not find the error i n my code.
Can you enlighten me ?
Here is my code :

function dmd_art(){
  var httpRequest = getHttpRequest();
  httpRequest.onreadystatechange = function () {
    if (httpRequest.readyState === 4){
      document.getElementById('annimation_loader').style.display = 'none';
      document.getElementById('aff_pub').innerHTML = httpRequest.responseText;
    }  
  }
  httpRequest.open('GET', 'includes/article.php', true)
}

getHttpRequest() is a function to adapted XMLHttpRequest to all web browsers

Javascript: using a math function to control an output range according to an input range

If I know that a ratio of two input variables variables “a/b” has a range of [1;2]
And if I want my output value of “y” to have a range of [ymin;ymax] of my choice, based on the range of “a/b”:

Is there a formula that can bind those two ranges so that I can always find the value of y, whatever the value of “a/b” (knowing it will always be between 1 and 2)?

Practically:

I have a grid that I can zoom.
The number of zoom steps can’t be predicted but I know that the ending scale divided by the starting scale will always be between 1 and 2.
And according to that predictable range, I would like to proportionally output an opacity value to my gridlines going from a min value to a max value of my choice.

So let say, I would like my opacity values to range from 0.12 to 0.38:
If the scale ratio is 1 then the opacity will be 0.12 and if the scale ratio is 2, then the opacity will be 0.38. And all opacity values In between would remain proportional.
And that should work for any output range of my choice.

So I wonder if looking for a formula to achieve this is reasonable or if it’s harder to compute than it seems.

Something like this

let opacity[from desired min to max] = (endScale/startScale)[from 1 to 2] * something + opacityMin;

I tried to plot some points on paper to try to figure that out but even though the points seem to follow a nice curve (it’s not linear though), I don’t know how to find its algebraic formula.

Any hep would be appreciated.

Vanilla alternative to Jquery .css()

So, I’m migrating a code who uses a lot of Jquery and I’m trying to keep the functions working well.

I could migrate almost everything, but when I try to change the .css() to vanilla option the app stop to work.

To be more specific, the project uses a library which makes a great carrousel. I saw the library code and seems that it don’t use any Jquery.

Then I started to migrate the code, and everything works well, except in one part:

When I try to change this:

newSlide.css({
  display: "block",
  width: 0,
  right: newSlideRight,
  left: newSlideLeft,
  zIndex: 2,
});

To this:

newSlide.style.display = "block";
newSlide.style.width = 0;
newSlide.style.right = newSlideRight;
newSlide.style.left = newSlideLeft;
newSlide.style.zIndex = 2;

or:

newSlide.setAttribute('style', `
    display: "block",
    width: 0,
    right: newSlideRight,
    left: newSlideLeft,
    zIndex: 2`
)

The carrousel stop working. The animation just freeze and is that.

Trying to figure what is happening I discovered that using the .css() the styles are changing all the time until the animation ends, but using the alternatives, this don’t happen.

The library is called TweenMax