https://github.com/khadem-mh/formulas
This page contains a variety of application formulas that are used in various projects that we develop frontend programmers ♥
https://github.com/khadem-mh/formulas
formulas javascript js
Last synced: about 2 months ago
JSON representation
This page contains a variety of application formulas that are used in various projects that we develop frontend programmers ♥
- Host: GitHub
- URL: https://github.com/khadem-mh/formulas
- Owner: khadem-mh
- Created: 2024-05-18T10:17:24.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-08-13T13:23:36.000Z (8 months ago)
- Last Synced: 2025-01-14T01:16:25.871Z (3 months ago)
- Topics: formulas, javascript, js
- Homepage:
- Size: 59.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#
Hi👋
This page contains a variety of application formulas that are used in various projects that we develop frontend programmers ♥
##
`perspective2D-WhenHoverBox.js`
```javascript
const boxes = document.querySelectorAll('.article__link')boxes.forEach(box => {
const handleMouseMove = (e) => {
const rect = box.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const rotateX = (y - centerY) / centerY * 10;
const rotateY = (x - centerX) / centerX * 10;box.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`
}const handleMouseLeave = () => {
box.style.transform = `perspective(1000px) rotateX(0) rotateY(0)`
}box.addEventListener('mousemove', handleMouseMove)
box.addEventListener('mouseleave', handleMouseLeave)return () => {
box.removeEventListener('mousemove', handleMouseMove)
box.removeEventListener('mouseleave', handleMouseLeave)
}})
```##
`randomChooseItemFromArray.js`
```javascript
const randomChooseItemFromArray = (arr, randomCount) => {
const shuffled = arr.sort(() => .5 - Math.random())
return shuffled.slice(0, randomCount)
}
```##
`scrollHorizontal.js`
```javascript
let customScroll = document.getElementById('scroll')const scrollHorizontal = () => {
let scrollPercent = window.scrollY / (document.body.clientHeight - window.innerHeight)
let scrollPercentRoundede = Math.round(scrollPercent * 100)
customScroll.style.width = scrollPercentRoundede + '%'
}window.addEventListener('scroll', scrollHorizontal)
```##
`concatinationArray.js`
```javascript
let arr1 = [1, 2, 3, 4, 5]
let arr2 = [6, 7, 8, 9, 10]let concatNumsArray = [...arr1, ...arr2]
```##
`sortingArray.js`
```javascript
let arr1 = [2, 6, 1, 4, 7, 0, 3, 9, 10, 5, 8]
let numsArrSort = arr1.sort((a, b) => { return a - b })
```##
`determinationCountNumber.js`
```javascript
let arr1 = [2, 6, 1, 4, 7, 0, 3, 7, 9, 10, 5, 8, 5, 2]let numberReapet = numsArrSort.reduce((prev, current) => {
return { ...prev, [current]: (prev[current] || 0) + 1 }
}, {})for (let num in numberReapet) {
nums += ` ${num} `
console.log(nums);
}
```##
`findMaxNumber.js`
```javascript
let arr1 = [2, 6, 1, 4, 7, 0, 3, 7, 9, 10, 5, 8, 5, 2]let maxNumber = arr1.reduce((prevNum, currentNum) => {
if (prevNum < currentNum) return currentNum
else return prevNum
}, 0)
```##
`findMinNumber.js`
```javascript
let arr1 = [2, 6, 1, 4, 7, 0, 3, 7, 9, 10, 5, 8, 5, 2]let minNumber = arr1.reduce((prevNum, currentNum) => {
if (prevNum > currentNum) return currentNum
else return prevNum
}, 0)
```##
`getOutAreaBox.js`
```javascript
let getPositionElem = boxElem.getBoundingClientRect()if (
event.clientY < getPositionElem.top ||
event.clientY > (getPositionElem.top + getPositionElem.height) ||
event.clientX > (getPositionElem.left + getPositionElem.width) ||
event.clientX < getPositionElem.left
) {
console.log('outside');
}
```