Skip to content

Commit

Permalink
Add touch event listeners to avatar element
Browse files Browse the repository at this point in the history
  • Loading branch information
YousifAbozid committed Feb 29, 2024
1 parent 3cb838f commit d5f1092
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
22 changes: 22 additions & 0 deletions app/about/page.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
'use client'

import Image from 'next/image'
import { useEffect } from 'react'

/**
* Renders the About component.
*
* @return {JSX.Element} A div container with the class name "about_container".
*/
export default function About() {
useEffect(() => {
const handleTouchStart = () => {
document.querySelector('.avatar').classList.add('touched')
}

const handleTouchEnd = () => {
document.querySelector('.avatar').classList.remove('touched')
}

const avatar = document.querySelector('.avatar')
avatar.addEventListener('touchstart', handleTouchStart)
avatar.addEventListener('touchend', handleTouchEnd)

return () => {
avatar.removeEventListener('touchstart', handleTouchStart)
avatar.removeEventListener('touchend', handleTouchEnd)
}
}, [])

return (
<div className='about_container'>
<div className='avatar'>
Expand Down
5 changes: 3 additions & 2 deletions styles/about/about.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@
width: 100%;
height: 100%;
object-fit: cover;
transform: scale(1.4) translateY(-7%);
transform: scale(1.4) translateY(-7%) rotate(0deg);
transition: all 0.8s ease;
}

.about_container .avatar:hover img {
.about_container .avatar:hover img,
.about_container .avatar.touched img {
transform: scale(2) translateY(7%) rotate(360deg);
}

Expand Down

0 comments on commit d5f1092

Please sign in to comment.