From cf01ccaaa90b5819422a5f6aaa00288bc051e1e3 Mon Sep 17 00:00:00 2001 From: Holtz Yan Date: Thu, 24 Oct 2024 10:30:42 +0200 Subject: [PATCH] scale lesson 1 ok --- .../CircleScaleExercise.tsx | 45 +++++++++++++---- pages/course/scales/introduction.tsx | 32 ++++++++++++ pages/course/svg/d3-shape.tsx | 34 ------------- pages/course/svg/tips-and-tricks.tsx | 49 ++++++++++++++----- util/lessonList.tsx | 2 +- 5 files changed, 106 insertions(+), 56 deletions(-) diff --git a/component/interactiveTeaching/CircleScaleExercise.tsx b/component/interactiveTeaching/CircleScaleExercise.tsx index be252b62..066c468a 100644 --- a/component/interactiveTeaching/CircleScaleExercise.tsx +++ b/component/interactiveTeaching/CircleScaleExercise.tsx @@ -1,15 +1,17 @@ import { Button } from '@/component/UI/button'; import { useCallback, useState } from 'react'; +const INITIAL_POSITIONS = [ + { id: 1, cx: 370, value: 0 }, + { id: 2, cx: 280, value: 50 }, + { id: 3, cx: 150, value: 60 }, + { id: 4, cx: 260, value: 82 }, + { id: 5, cx: 80, value: 100 }, +]; + export const CircleScaleExercise = () => { // Initial positions of the circles - const [circles, setCircles] = useState([ - { id: 1, cx: 200, value: 0 }, - { id: 2, cx: 220, value: 50 }, - { id: 3, cx: 240, value: 60 }, - { id: 4, cx: 260, value: 82 }, - { id: 5, cx: 280, value: 100 }, - ]); + const [circles, setCircles] = useState(INITIAL_POSITIONS); const [draggingCircleId, setDraggingCircleId] = useState(null); // Handle mouse down event to start dragging @@ -47,7 +49,7 @@ export const CircleScaleExercise = () => {
{ fillOpacity={1} onMouseDown={(e) => handleMouseDown(e, circle.id)} cursor={'pointer'} + style={{ + transition: 'cx 0.5s ease', // Smooth transition for the x-position + }} + onMouseEnter={(e) => (e.target.style.transition = 'none')} // Disable transition on hover + onMouseLeave={(e) => + (e.target.style.transition = 'transform 0.5s ease') + } // Re-enable transition when hover ends /> (e.target.style.transition = 'none')} // Disable transition on hover + onMouseLeave={(e) => + (e.target.style.transition = 'transform 0.5s ease') + } // Re-enable transition when hover ends > {circle.value} @@ -118,7 +135,15 @@ export const CircleScaleExercise = () => {
-
+
+