Category: javascript
Category Added in a WPeMatico Campaign
Why does (1,5 – 1) * 2 equal to 8? [duplicate]
I know that in JS point is a decimal mark and I see that there’s a comma between 1 and 5, but why does (1,5 - 1) equal to 4 and what happens with 1, in the beginning of the state
Interactive slots in weekly planner [closed]
i am looking for a way to create with JavaScript a weekly planner where every slots in the planner is identified by a date and an hour. The slots should be interactive, so when a user clicks on a slots a function will be called and the date and the hour will be received by this function and used to perform some actions.
The slots also should be colored based on the results of database queries and should have attributes that permits to deactivate or activate their status so that the function will be called or not after the click.
Is the first time I use JavaScript so I don’t know how could I do it and what library/frameworks to use. Can anyone suggest some frameworks or link an explained example that is similar to what i need because i can’t find anything useful?
Switching display style property between “none” and “flex” with Animated from React-Native
How can I switch between display none and flex using animated values?
I tried interpolating to 0 and 1 and depending on the value change the display property.
I am trying to hide the Animated.View when the animated value reaches 90 but nothing is happening.
// change animated value from 0 to 180
const flip = () => {
Animated.timing(flipAnimation, {
toValue: 180,
duration: 300,
useNativeDriver: true,
}).start();
};
//if the animated value is between 0 and 90 it will return 0 else it will return 1
const interpolate = flipAnimation.interpolate({
inputRange: [0, 90, 91, 180],
outputRange: [0, 0, 1, 1],
})
//if the value is 1 set display to "none" else set it to "flex"
<Animated.view style={{
display: interpolate === 1 ? "none" : "flex"
}}/>
How I can drag and drop item to array and from array to main level?
could some help me, how I can drag and drop an item to array and back from array to main level?
Here is the demo with working drag and drop by changing items order and I’m stuck how to expand this functionality by dropping items to the array and back. Also when I’m trying to drag and drop nested item to main level it copping the nested level
const app = new Vue({
el: '#app',
data: {
items: [
{ name: 'one' },
{ name: 'two' },
{ name: 'three' },
{ name: 'array', items: [ { name: 'four' } ] }
],
over: {},
startLoc: 0,
dragging: false,
dragFrom: {}
},
methods: {
startDrag(item, i, e) {
this.startLoc = e.clientY;
this.dragging = true;
this.dragFrom = item;
},
finishDrag(item, pos) {
this.items.splice(pos, 1)
this.items.splice(this.over.pos, 0, item);
this.over = {}
},
onDragOver(item, pos, e) {
const dir = (this.startLoc < e.clientY) ? 'down': 'up';
setTimeout(() => {
this.over = { item, pos, dir };
}, 50)
}
},
})
.list > div {
display: flex;
flex-direction: column;
}
.main-level {
width: 200px;
padding: 10px;
margin: 10px auto 10px 10px;
background: tomato;
color: white;
font-family: sans-serif;
border-radius: 5px;
display: inline-block;
}
.nested-level {
width: 200px;
padding: 10px;
margin: 10px auto 10px 220px;
background: tomato;
color: white;
font-family: sans-serif;
border-radius: 5px;
display: inline-block;
}
.flip-list-move {
transition: transform .2s;
}
.over {
opacity: .6;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div class="list">
<div>
<div
@dragover="(e) => onDragOver(item, i, e)"
@dragend="(e) => finishDrag(item, i, e)"
@dragstart="(e) => startDrag(item, i, e)"
v-for="(item, i) in items"
class="main-level"
:class="{over: (item === over.item && item !== dragFrom), [over.dir]: (item === over.item && item !== dragFrom) }"
draggable="true"
:key="item.name"
>
{{ item.name }}
<span v-if="item.items">
({{item.items.length}})
</span>
<div
v-if="item.items && item.items.length"
@dragover="(el) => onDragOver(item, index, el)"
@dragend="(el) => finishDrag(item, index, el)"
@dragstart="(el) => startDrag(item, index, el)"
v-for="(nestedItem, index) in item.items"
class="nested-level"
:class="{over: (nestedItem === over.item && nestedItem !== dragFrom), [over.dir]: (nestedItem === over.item && nestedItem !== dragFrom) }"
draggable="true"
:key="nestedItem.name"
>
{{ nestedItem.name }}
</div>
</div>
</div>
</div>
</div>
How can I get the module files links and use it in reactjs
I’m having a problem wherein I want to animated my text but I want to pass a module of javascript which is THIS. There is a link of how I can add this in js but I cannot call the module of the link here is my code sample
For the outside of function
function AnimationLibrary(url){
const script = document.createElement('script');
script.src = url;
script.async = true;
console.log(url)
document.body.appendChild(script);
}
// This is for text color animation css
useEffect(() => {
var textWrapper = document.querySelector('.introduction .text h4');
textWrapper.innerHTML = textWrapper.textContent.replace(/S/g, "<span class='letter'>$&</span>");
anime.timeline({loop: true})
.add({
targets: '.ml2 .letter',
scale: [4,1],
opacity: [0,1],
translateZ: 0,
easing: "easeOutExpo",
duration: 950,
delay: (el, i) => 70*i
}).add({
targets: '.ml2',
opacity: 0,
duration: 1000,
easing: "easeOutExpo",
delay: 1000
});
},[])
And the return in function
return (
{AnimationLibrary(
"https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"
)}
)
Yes I can see the link in my console.log but the problem is I cannot get the module of the link of the link that I give in first line.. Anyway this is my source of how I can get the external link
THIS
Any idea how can I get the modules of the link for animating my letters in react hooks? It would be a big help to me thank you.
How to change fill of an SVG element based on hover of an separate HTML element?
I have a simple SVG graphic (basically 4 squares) in one div. Next to that div is another div with 4 HTML buttons. I want that on hover of button 1, one of the SVG squares changes its background color. And on hover of button 2, another SVG square changes its background color, same for the next 2 buttons and SVG squares. (and when hovering out of the respective button, the SVG square goes back to no fill.)
I have been researching this a lot but have not found a solution. From what I am understanding I can’t do this with CSS but is this possible with jQuery or javascript?
For context; I am trying to understand how an interactive graphic like on this page is working: https://the-jay.ch/wohnungen (scroll down to “WOHNUNGSANGEBOT”)
.cls-1 {
fill: none;
stroke: #231f20;
stroke-miterlimit: 10;
stroke-width: 35px;
}
.svg_section {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 100%;
height: 500px;
}
.svg_wrapper {
overflow: hidden;
width: 50%;
height: 100%;
}
.html-embed {
width: 100%;
height: 100%;
}
.svg_trigger_div {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 50%;
height: 100%;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
background-color: #e4b5b5;
}
.button1 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 200px;
height: 30px;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
background-color: #973535;
}
.button2 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 200px;
height: 30px;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
background-color: #5aac6c;
}
.button3 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 200px;
height: 30px;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
background-color: #559bbb;
}
.button4 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 200px;
height: 30px;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
background-color: rgba(162, 71, 153, 0.72);
}
.text-block {
line-height: 14px;
}
<div class="svg_section">
<div class="svg_wrapper">
<div class="html-embed w-embed">
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 1035 1035.92">
<defs></defs>
<rect id="rec4" class="cls-1" x="17.5" y="17.5" width="500" height="500"></rect>
<rect id="rec3" class="cls-1" x="517.5" y="17.5" width="500" height="500"></rect>
<rect id="rec2" class="cls-1" x="17.5" y="518.42" width="500" height="500"></rect>
<rect id="rec1" class="cls-1" x="517.5" y="518.42" width="500" height="500"></rect>
</svg>
</div>
</div>
<div class="svg_trigger_div">
<a href="#" class="button1 w-inline-block">
<div class="text-block">Button 1</div>
</a>
<a href="#" class="button2 w-inline-block">
<div class="text-block">Button 2</div>
</a>
<a href="#" class="button3 w-inline-block">
<div class="text-block">Button 3</div>
</a>
<a href="#" class="button4 w-inline-block">
<div class="text-block">Button 4</div>
</a>
</div>
</div>
Cors issue in express
I am receiving this message when using axios [get] even though i am using cors
What i have tried:
//.... (Other imports and code not mentioned)
import cors from "cors";
app.use(
cors({
origin: "*",
})
);
app.get("/memes", (req, res) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET");
res.setHeader(
"Access-Control-Allow-Headers",
"X-Requested-With,content-type"
);
res.setHeader("Access-Control-Allow-Credentials", true);
res.status(200).send({hello: "world"});
});
// ......
Why does copied line of the code work but it doesnot when I type the same line manually? [closed]
How to implement CSV file in SOAP API using k6
const soapReqBody1 = `
<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”
xmlns:web="http://www.dataaccess.com/webservicesserver/">
<soapenv:Header/>
<soapenv:Body>
<web:NumberToWords>
<web:ubiNum>66</web:ubiNum>
</web:NumberToWords>
</soapenv:Body>
</soapenv:Envelope>`;
export default function () {
const res = http.post(
'https://www.dataaccess.com/webservicesserver/NumberConversion.wso',
soapReqBody,
{ headers: { 'Content-Type': 'text/xml'} }
);
3 Tam sayının ortalamasını bulan program integer ve float ile nasıl yazarım [closed]
3 Tane sayının ortalamasını bulan c kodu,kullanıcıdan 3 tane tam sayı girmesini isteyeceğiz printf ve scanf fonksiyonları kullanılmalı tam sayı integer ortalama değeri ondalık sayı float olarak tanımlanmalı yardım eder misiniz ödevim teşekkür ederim 🙂
Redux architecture for audio player and handling errors
Let’s say I am building an audio player which consists of a control panel, where user can pause/play currently selected track, and audio players themselves.
Possible actions are to pause/play the track, and the audio player component is listening to state changes and deciding whether to play/pause the track (example code taken from https://stackoverflow.com/a/50880480/18547676)
Actions:
// plays active track
export const playTrack () => ({
type: 'musicPlayer/PLAY_TRACK',
payload: true,
});
// pauses active track
export const pauseTrack () => ({
type: 'musicPlayer/PLAY_TRACK',
payload: false,
});
Reducer:
const initialState = {
isPlaying: false,
};
export const musicPlayer = (state = initialState, action) => {
switch (action.type) {
case 'musicPlayer/PLAY_TRACK':
return {
...state,
isPlaying: action.payload,
}
default: return state
}
}
Component (state mapped to props):
componentDidUpdate() {
if(this.props.audioTrack) {
if(this.props.isPlaying) audioTrack.play();
else audioTrack.pause();
}
}
My question is the following; what is the recommended way to handle the cases when for example, audio player could not execute the action due to error. For example, user wanted to pause the current player; state changed, and audio player received the update, but was unable to perform the action due to error. Is there some pattern to handle this?
Is there some way to do a kind of relationship between keys in an interface in Typescript?
Let me try to explain. I have the follow response interface:
interface IResponse {
status: "success" | "error";
content: IMySuccessResponse | string;
}
Is there any way to make Typescript understand that when the status for equal to “success” the only possible value of content will be “IMySuccessResponse”, and when the status for equal to “error” the only possible value of content will be a string?
I tried something like that:
interface IResponse {
response: {
status: "success";
content: IMySuccessResponse ;
} | {
status: "error";
content: string;
}
}
But the Typescript kept on understanding that both values of content are possible regardless of status value.
Materialized collapsible event is missing
I have two types of collapsibles on one page.
The first one is reacting as intended, the second one does not react/unfold on clicking. I noticed that the event is missing, I just don’t know why.
The first one is directly set into the html, this is the working one:
<ul class="collapsible">
<li>
<div class="collapsible-header"><i class="material-icons">help</i>Anweisung</div>
<div class="collapsible-body">
<span>
<ol>
<li>Barcode scannen</li>
<li>Platz scannen</li>
</ol>
</span>
</div>
</li>
</ul>
The second type of collapsible is generated via javascript, here the example code
$(document).ready(function () {
$('.collapsible').collapsible();
});
...
var my_content = "<ul class="collapsible"> <li><div class="collapsible-header"><i class="material-icons">file_download</i>Inhalt anzeigen";
my_content += "</div >";
my_content += "<div class="collapsible-body">";
my_content += "<span> Irgendwas</span>";
my_content += "</div>";
$("#containers_on_loadcarrier").html(articletype_list);
First one results in this:
Second one results in this:
Any ideas?
Thanks in advance!
How to sum up an array loop of PHP value with Javascript
I have a loop of an array of values in PHP that I will like to sum up with Javascript. Below image is the screenshot of what my array listing looks like:
I have an onClick function that multiple quantity with total every time - and + is clicked. I will like the sum up of 21,998 and 11,999 when - and + is clicked. Below is what my HTML code and PHP script looks like:
<table class="table table-cart table-mobile">
<thead>
<tr>
<th>Quantity</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<? for($i=0;$i<count($_SESSION['img_src']);$i++){ ?>
<tr>
<td>
<div onclick="clickMe(<?php echo $_SESSION['id'][$i]; ?>)">
<input type="number" value="1" min="1" max="10" step="1" data-decimals="0" required id = "<? echo $_SESSION['id'][$i].'_quantityCount' ?>">
</div><!-- End .cart-product-quantity -->
</td>
<td id = "<? echo $_SESSION['id'][$i].'_totalPrice' ?>">₦<?php echo $_SESSION['price'][$i] ?></td>
</tr>
<tbody>
<?
}
?>
</table>
And my javascript onclick looks like below code:
<script>
function clickMe(id) {
var price = document.getElementById(id+"_price").innerHTML;
let finalPrice = price.replace(/[^a-zA-Z0-9]/g, '')
var quantity = document.getElementById(id+"_quantityCount").value;
var totalPrice = quantity * finalPrice;
document.getElementById(id+"_totalPrice").innerHTML = "u20A6"+totalPrice.toString().replace(/B(?=(d{3})+(?!d))/g, ",");
}
</script>





