Bonjour je cherche un bout de code qui me permettra au survole de mon logo de faire apparaitre mon texte et lorsque la souris n’est plus sur mon logo le texte devra disparaitre, quelqu’un pourrait m’aider ?
Category: javascript
Category Added in a WPeMatico Campaign
Render child_process in electron
I’m trying to use child_process to open another program through electron, but when I click the button even calling the function to render it doesn’t open the requested application.
Electron version ^16.0.7:
main.js
const { app, shell, BrowserWindow } = require('electron')
const path = require('path')
let mainWindow = null;
function createWindow () {
mainWindow = new BrowserWindow({
autoHideMenuBar: true,
width: 1300,
height: 840,
resizable: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
webPreferences: {nodeIntegration: true}
}
})
mainWindow.loadFile('./app/home.html')
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('web-contents-created', (e, contents) => {
contents.on('new-window', (e, url) => {
e.preventDefault();
require('open')(url);
});
contents.on('will-navigate', (e, url) => {
if (url !== contents.getURL()) e.preventDefault(), require('open')(url);
});
});
preload.js
window.openGaeme = function(executablePath) {
let child = require('child_process').execFile;
child(executablePath, function(err, data) {
if(err){
console.error(err);
return;
}
console.log(data.toString());
});
}
function in renderer.js
function onClick() {
var executablePath1 = "C:\Program Files (x86)\Game\system\game.exe";
window.openGaeme(executablePath1);
}
HTML BUTTON AND SCRIPT:
<button class="button-go" role="button" onclick="onClick()">JOIN</button>
<script src="./core/renderer.js"></script>
Nextjs: update state not work in interval
This is my state:
const [time, setTime] = useState(10)
And this is my handler:
const runTimer = () => {
useEffect(() => {
const interval = setInterval(() => {
console.log(time)
if (time > 0) {
setTime(time - 1)
} else {
console.log("End")
}
}, 1000);
return () => clearInterval(interval)
}, [])
}
My log:
9
9
9
9
9
.
.
.
Why setTime doesn’t work ?
time variable most increase per 1000 delay
Faster Better Replacement for useReducer?
Hi I am using a simple useReducer Function to Start and Stop a Lottie Animation for a Hamburger Menu Icon
Please suggest a better approach or something with faster performance if it exists or let me know if it is good enough.
Thanks in Advance
import Lottie from 'react-lottie-player/dist/LottiePlayerLight' //@ Lottie Player
import menuIcon from './menu-icon.json' //@ Lottie Menu Icon
import { useReducer } from 'react'
const Menu = () => {
//$ Reducer Hook for Menu State Management
//@ Reducer Function
const controlAnim = (controls, action) => {
switch (action) {
case 'OPEN':
return { isClicked: true, close: false }
case 'CLOSE':
return { isClicked: true, close: true }
case 'SWITCH':
return { isClicked: false, close: !controls.close }
default:
return controls
}
}
//@ States and Controls
const [controls, setControls] = useReducer(controlAnim, {
isClicked: false,
close: false,
})
return (
<div className="menu-header-button" onClick={() => (controls.close ? setControls('CLOSE') : setControls('OPEN'))}>
<Lottie
className="menu-header-button-lottie"
animationData={menuIcon}
loop={false}
speed={1}
play={controls.isClicked}
direction={1}
segments={controls.close ? [55, 90] : [15, 45]}
onComplete={() => setControls('SWITCH')}
/>
</div>
)
}
export default Menu
I can’t solve the error “Uncaught SyntaxError: Unexpected token ‘<'"
JS:
import React from "react";
import { ReactDOM } from "react";
import './style.css';
import App2 from "./App2.js";
function App() {
return (
<App2.js />
)
}
ReactDOM.render(<App />, document.getElementById('root'))
Referred App2.js in the above file:
import React from "react";
import { ReactDOM } from "react";
export default function App2() {
return (
<div>
<h1>Yusif Ahmedov</h1>
<button id="email"></button>
<button id="linkedin"></button>
<h2>Front-End Developer</h2>
<header id="about-header">About</header>
<p id="about">I am a front-end developer who is passionate about coding and engaging both creative and practical side of the human potential.</p>
<header id="interests-header">Interests</header>
<p id="interests">Productivity articles, Time Management, Coffee, Music, Sports, Social Activities.</p>
</div>
)
}
And simple HTML:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Card</title>
<script type="module" src="./App.js" defer></script>
</head>
<body>
<div id="root"></div>
</body>
</html>
I wrote all from scratch and so there are no extra files.
When I run it, it gives an error:
Uncaught SyntaxError: Unexpected token ‘<‘ App.js:8(line)
I didn’t get it why it gives an error on the 8th line.
await promise.all chained array-methods
I need to recursively call an API to walk down child entries, and return the filtered results before continuing. I was initially putting the results in an array, and then doing a .forEach, and if I found a match I needed to recurse doing so; however, that didn’t work because of the problem described in the answer to this question. So, I tried to modify the answer to that question, but it’s still not waiting.
const getDatabases = async (blockId) => {
let databases = [];
let childDatabases = [];
const children = await getChildren(blockId);
Promise.all(children.results
.filter( (child) => {
return (['child_database', 'database'].includes(child.type)
|| child.has_children === true);
})
.map( async (child) => {
if (['child_database', 'database'].includes(child.type)) {
return { id: child.id, title: child.child_database.title };
} else {
console.log(`Waiting on getDatabases for ${child.id}`); // 1
childDatabases = await getDatabases(child.id);
return false;
}
})
)
.then((childDbs) => {
console.log(`Got childDbs`); // 3, 4
databases =
[...databases, ...childDatabases].filter(dbId => dbId !== false);
return databases;
})
.catch((err) => console.log(err));
}
app.get('/api', async (req, res) => {
const dashboardPage = await getDashboardPage();
const databases = await getDatabases(dashboardPage);
console.log('No longer awaiting getDatabases'); // 2
...
}
So the question is, why is 2 happening before 3 and 4, instead of after them? Shouldn’t const databases = await getDatabases(dashboardPage); before 2 be waiting for all the recursive calls that pass through childDatabases = await getDatabases(child.id); after 1?
Should we use SSG for deploying a dashboard created using Nuxt.js?
We are going to develop a dashboard for internal use using Nuxt.js. As this will be an internal dashboard there is no need for a universal mode. Generally most of the dashboard are developed in SPA.
But SPA also requires a server to send the initial HTML and js bundle to the browser. So what if we use SSG and deploy it to s3 as it will no longer need a server and we can save the cost?
How can i mark a certain area in React-Native
I want users to be able to click on a certain area on the body (as image) where they endure pain, i want to ask what is the best way to accomplish this?
Kind regards!
The scroll method doesn’t work the way I need it to, how to solve?
When scrolling down, the class is added and immediately removed, which is seen in this video https://radikal.ru/video/Ua66Nz79e5D -radikal.
need to make the script work correctly so that the header is removed, and the block with the player is stretched to the full screen by height 100vh
html
<div class="oneboss">
<div class="header">HEADER</div>
<div class="main">
<div class="player"></div>
</div>
</div>
css
body {
width: 100%;
min-height: 100%;
overflow-x: hidden;
}
.oneboss {
display: flex;
flex-direction: column;
height: 100vh;
overflow: hidden;
position: relative;
}
.main {
width: 100%;
overflow: hidden;
overflow-y: auto;
position: relative;
}
.player {
//there is nothing
}
js jq
const $header = $(".header")
let prevScroll
let lastShowPos
$('.main').scroll(function() {
const scrolled = $('.main').scrollTop()
if (scrolled > 0 && scrolled > prevScroll) {
$header.addClass("header_hide")
lastShowPos = scrolled
} else if (scrolled <= Math.max(lastShowPos - 255, 0)) {
$header.removeClass("header_hide")
}
prevScroll = scrolled
});
this class is being added.
.header_hide {
display:none;
}
pls tell me how do solve this?
Trying to get PanelSnap.js work on wordpress
I am trying to get PanelSnap.js work on my wordpresssite.
My coding experience is like read manuals and copy-paste. So I am sorry if basic stuff isn`t right.
I downloaded the panelsnap.js the developer uses on panelsnap.com/panelsnap.js and took the file to upload it to the server (in the child-themes-directory). After that i added this line to the functions.php in the child-theme.
wp_enqueue_script( 'panelSnap', get_template_directory_uri() . '/js/panelsnap.js', array ( 'jquery' ), 1.1, true);
Next step was to use the “Simple Custom CSS and JS”-PlugIn to add some HTML to the Header
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.js"></script>
<script src="/wp-content/themes/kadence-child/assets/js/panelsnap.js"></script>
<script>
jQuery(function () {
new PanelSnap();
})
</script>
<script src="/wp-content/themes/kadence-child/assets/js/panelsnap.js" defer></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
new PanelSnap();
});
</script>
<script>
var defaultOptions = {
container: document.body,
panelSelector: '> section',
directionThreshold: 50,
delay: 0,
duration: 300,
easing: function(t) { return t },
};
new PanelSnap(options);
</script>
and some JS in to the footer
jQuery(document).ready(function( $ ){
var options = {
// jQuery object referencing a menu that contains menu items
$menu: false,
// CSS selector to menu items (scoped within the menu)
menuSelector: 'a',
// css selector to panels (scoped within the container)
panelSelector: 'section',
// jQuery event namespace that's being used
namespace: '.panelSnap',
// fired before a panel is being snapped
onSnapStart: function(){},
// fired after a panel was snapped
onSnapFinish: function(){},
// fired before a panel is being snapped.
onActivate: function(){},
// An integer specifying the ammount of pixels required to scroll
// before the plugin detects a direction and snaps to the next panel.
directionThreshold: 50,
// The ammount of miliseconds in which the plugin snaps to the desired panel
slideSpeed: 200,
// The jQuery easing animation to use.
easing: 'linear',
// An integer specifying the number of pixels to offset when snapping to a panel.
offset: 0,
// keyboard navigation.
keyboardNavigation: {
enabled: false,
nextPanelKey: 40,
previousPanelKey: 38,
wrapAround: true
},
strictContainerSelection: true
};
jQuery('body').panelSnap(options);
});
If I open the site and the console it gives me this
I tried even to build one of the sites like should be similiar to the developers demo.
https://mobeil.helfersyndrom-ev.de/522-2/
Thank you for your time reading this and i would appreciate every help or critics.
Infinite loading for a ReactJS app despite me having lazy loading
Soo. I am getting an infinite loading screen when I start my react app. Eventually after waiting like 2 minutes it says Error code: Out of Memory. I tried lazy loading with seperate components in seperate files and it stills does the same thing. If you want to see the code, https://github.com/SupaSibs/social-media-network/tree/Supa-Branch/client/website/src
How to resolve – Cypress detected a cross origin error?
So i am using cypress to log into google and create a google form. I have gotten through the login, but now that I want to select create new form, I am seeing cross origin errors which seem to be blocking such actions. Can anyone help me out here? Heres my code. Its the click on #1f that is not working

”’
describe('Test', function () {
it('logs into google', function () {
Cypress.on('uncaught:exception', (err, runnable) => {
return false
})
cy.visit('http://docs.google.com/forms/u/0')
cy.xpath("//input[@type='email']").type("[email protected]");
cy.xpath("//span[contains(text(),'Siguiente')]").click();
cy.wait(5000);
cy.xpath("//input[@type='password']").type("1Testagain");
cy.xpath("//span[contains(text(),'Siguiente')]").click();
cy.wait(5000);
///cy.xpath("//span[contains(text(),'Probar otra manera')]").click();
/// cy.wait(5000)
/// cy.xpath("//span[contains(text(),'Confirmar')]").click();
/// cy.wait(5000)
//cy.xpath("//span[contains(text(),'Untitled form')]").click();
//cy.wait(5000)
cy.get('#:1f').click();
cy.wait(5000);
”’
Why only in chrome i’m getting a blurry textarea? Any solution
how to show preview of a video and an image selected using the same html input type=file
I want to show the preview of selected file (video and image) before uploading them. so far i am only able to create a function to show the preview of an image like this:-
<!-- button for selecting image/video -->
<label for="inp-img-vid">
<span> Photos/Videos</span>
<input type="file" accept="image/*, video/*" name="img-vid" id="inp-img-vid">
</label>
<div class="display-img-vid-con">
<!-- showing selected image here -->
<img src="" id="preview-img">
<!-- showing selected video here -->
<video controls>
<source src="" id="preview-vid">
Your browser does not support HTML5 video.
</video>
</div>
$("#inp-img-vid").change(function(){
imgPreview(this);
});
function imgPreview(input){
if(input.files && input.files[0]){
var reader = new FileReader();
reader.onload = function(e){
$("#preview-img").show().attr("src", e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
The above code shows the image inside #preview-img exactly how i want it. Now i don’t know how show the video inside #preview-vid which is selected through the #inp-img-vid input tag using jquery…. any help is much appreciated.
Function to change a HTML Form Input from text to hidden if the value from the DB is not NULL
function myFunction() {
var x = document.getElementById("DatabaseColumn");
if (x.style.display === "null") {
x.type="hidden";
}
}
<div class="form-group row">
<label for="DatabaseColumn" class="col-6 col-form- label">Database Column</label>
<div class="col-7">
<input id="DatabaseColumn" name="DatabaseColumn" type="text" value="${columnRecord.DatabaseColumn}" class="form-control" required="required">
</div>
</div>
The function is intended to check whether the value from columnRecord is null. If it is null it means it still requires input but if it is not null no input is required for the Database Column.
