Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nothing just a little bit of better readme and support for mobile and desktop too #12

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
# impressingCrush
link mobile.js instead of script.js in index.html to work in mobile.

Thanks and Happy Coding.

# Impressing Crush

Impressing Crush is a lightweight web application designed to help users create a visually appealing showcase for photos with a user-friendly drag-and-drop interface. The project is built using HTML, CSS, and JavaScript, keeping it simple and accessible for everyone.

## Features

- **Drag-and-Drop UI:** Easily organize and arrange your photos by dragging and dropping them into the desired positions.
- **Photo Showcase:** Create an impressive showcase for your photos, allowing you to present your content in a visually appealing way.
- **HTML, CSS, JS:** Built with the fundamentals of web development, ensuring simplicity and ease of customization.

## How to Use

1. Clone or download the project repository to your local machine.
2. Open the `index.html` file in your preferred web browser.

## Customization

- **Adding Photos:** Place your photos in the designated folder and update the file paths in the HTML file to include your images.

- **Styling:** Customize the appearance by modifying the styles in the `style.css` file to suit your preferences.

## Contributing

Contributions are welcome! If you have suggestions, bug reports, or want to contribute to the development, feel free to open an issue or submit a pull request.

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
82 changes: 82 additions & 0 deletions mouseControl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
let highestZ = 1;

class Paper {
holdingPaper = false;
mouseTouchX = 0;
mouseTouchY = 0;
mouseX = 0;
mouseY = 0;
prevMouseX = 0;
prevMouseY = 0;
velX = 0;
velY = 0;
rotation = Math.random() * 30 - 15;
currentPaperX = 0;
currentPaperY = 0;
rotating = false;

init(paper) {
document.addEventListener('mousemove', (e) => {
if(!this.rotating) {
this.mouseX = e.clientX;
this.mouseY = e.clientY;

this.velX = this.mouseX - this.prevMouseX;
this.velY = this.mouseY - this.prevMouseY;
}

const dirX = e.clientX - this.mouseTouchX;
const dirY = e.clientY - this.mouseTouchY;
const dirLength = Math.sqrt(dirX*dirX+dirY*dirY);
const dirNormalizedX = dirX / dirLength;
const dirNormalizedY = dirY / dirLength;

const angle = Math.atan2(dirNormalizedY, dirNormalizedX);
let degrees = 180 * angle / Math.PI;
degrees = (360 + Math.round(degrees)) % 360;
if(this.rotating) {
this.rotation = degrees;
}

if(this.holdingPaper) {
if(!this.rotating) {
this.currentPaperX += this.velX;
this.currentPaperY += this.velY;
}
this.prevMouseX = this.mouseX;
this.prevMouseY = this.mouseY;

paper.style.transform = `translateX(${this.currentPaperX}px) translateY(${this.currentPaperY}px) rotateZ(${this.rotation}deg)`;
}
})

paper.addEventListener('mousedown', (e) => {
if(this.holdingPaper) return;
this.holdingPaper = true;

paper.style.zIndex = highestZ;
highestZ += 1;

if(e.button === 0) {
this.mouseTouchX = this.mouseX;
this.mouseTouchY = this.mouseY;
this.prevMouseX = this.mouseX;
this.prevMouseY = this.mouseY;
}
if(e.button === 2) {
this.rotating = true;
}
});
window.addEventListener('mouseup', () => {
this.holdingPaper = false;
this.rotating = false;
});
}
}

const papers = Array.from(document.querySelectorAll('.paper'));

papers.forEach(paper => {
const p = new Paper();
p.init(paper);
});
91 changes: 11 additions & 80 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,13 @@
let highestZ = 1;

class Paper {
holdingPaper = false;
mouseTouchX = 0;
mouseTouchY = 0;
mouseX = 0;
mouseY = 0;
prevMouseX = 0;
prevMouseY = 0;
velX = 0;
velY = 0;
rotation = Math.random() * 30 - 15;
currentPaperX = 0;
currentPaperY = 0;
rotating = false;

init(paper) {
document.addEventListener('mousemove', (e) => {
if(!this.rotating) {
this.mouseX = e.clientX;
this.mouseY = e.clientY;

this.velX = this.mouseX - this.prevMouseX;
this.velY = this.mouseY - this.prevMouseY;
}

const dirX = e.clientX - this.mouseTouchX;
const dirY = e.clientY - this.mouseTouchY;
const dirLength = Math.sqrt(dirX*dirX+dirY*dirY);
const dirNormalizedX = dirX / dirLength;
const dirNormalizedY = dirY / dirLength;

const angle = Math.atan2(dirNormalizedY, dirNormalizedX);
let degrees = 180 * angle / Math.PI;
degrees = (360 + Math.round(degrees)) % 360;
if(this.rotating) {
this.rotation = degrees;
}

if(this.holdingPaper) {
if(!this.rotating) {
this.currentPaperX += this.velX;
this.currentPaperY += this.velY;
}
this.prevMouseX = this.mouseX;
this.prevMouseY = this.mouseY;

paper.style.transform = `translateX(${this.currentPaperX}px) translateY(${this.currentPaperY}px) rotateZ(${this.rotation}deg)`;
}
})

paper.addEventListener('mousedown', (e) => {
if(this.holdingPaper) return;
this.holdingPaper = true;

paper.style.zIndex = highestZ;
highestZ += 1;

if(e.button === 0) {
this.mouseTouchX = this.mouseX;
this.mouseTouchY = this.mouseY;
this.prevMouseX = this.mouseX;
this.prevMouseY = this.mouseY;
}
if(e.button === 2) {
this.rotating = true;
}
});
window.addEventListener('mouseup', () => {
this.holdingPaper = false;
this.rotating = false;
});
}
function loadScript(url) {
var script = document.createElement('script');
script.src = url;
document.head.appendChild(script);
}

const papers = Array.from(document.querySelectorAll('.paper'));

papers.forEach(paper => {
const p = new Paper();
p.init(paper);
});
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
// Load mobile script for mobile devices
loadScript('touchControl.js');
} else {
// Load desktop script for other devices
loadScript('mouseControl.js');
}
File renamed without changes.