I want to click on the first rectangle and click on the second rectangle, they will be connected by

anyone can help me ? pls
50 Replies
majkl
majkl10mo ago
conmeomaunau
conmeomaunauOP10mo ago
i want this
conmeomaunau
conmeomaunauOP10mo ago
Suppose the first image contains the question, the second image contains the answer, and I want to click on the first image and then click on the second image, a line connecting the first image and the second image.
majkl
majkl10mo ago
Look into the ::before / ::after selectors, maybe .I am off now.
conmeomaunau
conmeomaunauOP10mo ago
tks u
CheT
CheT10mo ago
Oohh so u want to like when u click on the first box , the line to show up And when u click on the second the line to go away and show on second box Yeah u could play with opacities of psuedo elements
majkl
majkl10mo ago
For a click trigger you proly need js. Or maybe :focus pseudoclass. Not difficult. would go for transform scale rather than opacity to get the scaling animation. But whatever suits one.
CheT
CheT10mo ago
Love the way u think :this: :thumbup:
conmeomaunau
conmeomaunauOP10mo ago
No, I want when we click on the first image and click on the second image, we will connect together
glutonium
glutonium10mo ago
here is something i once made
glutonium
glutonium10mo ago
i never thought I'd be sharing this lmao
conmeomaunau
conmeomaunauOP10mo ago
Exactly, I want to join 2 blocks together but I want the 2 blocks to have a fixed position
glutonium
glutonium10mo ago
glad it helped since i coded it a long ago, the code may not be in the best shape i hope u can still understand
conmeomaunau
conmeomaunauOP10mo ago
tks u
glutonium
glutonium10mo ago
welcome i can firmly say i got 0 clue wth is going on in that code
conmeomaunau
conmeomaunauOP10mo ago
More specifically, I want to connect the left block to the right using a black seam
No description
glutonium
glutonium10mo ago
i would've used canvas instead of normal html elements let me try to make things simple for you try to instead make a function a function that takes two point(object). each point will have an x,y position so u have 2 input points, the function will draw a line from point a to point b work on making that function as a separate project perhaps u can do it with codepen by doing so, once u get able to make such a function, all just need to copy paste it in your current project, you'll pass the position of the left and right block to the function and it'll draw it for you
conmeomaunau
conmeomaunauOP10mo ago
tks u so much i will try
glutonium
glutonium10mo ago
i thought it would be a nice project for me as well so i came up with a solution of my own.. lemme know yours so i can share mine
conmeomaunau
conmeomaunauOP10mo ago
tks u <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <link rel="stylesheet" href="./styles.css" /> </head> <body> <div class="app"> <main class="project"> <div class="project-questionTest">question test dispplay here</div> <div class="project-tasks"> <div class="project-tasks-questionsList"> </div> <div class="project-tasks-results"></div> <div class="project-tasks-questionTitle"></div> <div class="project-tasks-answers"> </div> </div> </div> </main> </div> <script src="app.js"></script> <!-- <script type="application/javascript" src="/js/answers.js"></script> --> </body> </html>
conmeomaunau
conmeomaunauOP10mo ago
I haven't drawn the seam line yet
glutonium
glutonium10mo ago
m talking bout the line making function this..not the whole project
conmeomaunau
conmeomaunauOP10mo ago
I want you to check it out to understand the problem better
glutonium
glutonium10mo ago
make a codepen m in a trip rn.. perhaps someone else can check
conmeomaunau
conmeomaunauOP10mo ago
tks u so much
glutonium
glutonium10mo ago
welcome do let me know if u manage to code a function that draws a line I don't want u to stop trying yourself so i won't show mine here
conmeomaunau
conmeomaunauOP10mo ago
Currently I want to connect many points together, I will save the positions of the points, then I use a loop to connect them all into 1 pair.
glutonium
glutonium10mo ago
if u can make a function that connects two points u can use it on multiple points so try to make a function that works with 2 points just make it a separate project this will help u focus more on it
conmeomaunau
conmeomaunauOP10mo ago
okay , i will try
MarkBoots
MarkBoots10mo ago
leader-line is a simple js library I used in the past https://anseki.github.io/leader-line/
LeaderLine
Draw a leader line in your web page.
conmeomaunau
conmeomaunauOP10mo ago
No description
conmeomaunau
conmeomaunauOP10mo ago
Currently I have connected the two images, but I want to draw them on the right edge of the first image and the left edge of the second image, can you help me? @glutonium
conmeomaunau
conmeomaunauOP10mo ago
i want this
No description
glutonium
glutonium10mo ago
give the cards higher z index than the line
conmeomaunau
conmeomaunauOP10mo ago
i don't understand :((((
conmeomaunau
conmeomaunauOP10mo ago
No description
conmeomaunau
conmeomaunauOP10mo ago
i.e. I want the start point to be at the edge of the first shape and the end point to be the edge of the second shape
glutonium
glutonium10mo ago
increase the z index of the cards
conmeomaunau
conmeomaunauOP10mo ago
i don't see any z attribute :(((
conmeomaunau
conmeomaunauOP10mo ago
Please help me with this part, I tried my best, I spent many days doing it
glutonium
glutonium10mo ago
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
conmeomaunau
conmeomaunauOP10mo ago
Maybe you misunderstood me I mean the starting point on the first shape will default to the right edge, and the left edge of the second shape when they are joined together
clevermissfox
clevermissfox10mo ago
Pseudo element with url to svg <path /> or <line />. could use JS to find the values of where the target ending point set as a custom property to update it? That’s my first thought anyway.
conmeomaunau
conmeomaunauOP10mo ago
Thank you everyone for your comments, thank you very much. I have completed the assignment
majkl
majkl10mo ago
Do show!
conmeomaunau
conmeomaunauOP10mo ago
I will leave the codepen link when completed
glutonium
glutonium10mo ago
since u have solved the issue this is the function i had came up with previously
function drawLine(pointA, pointB, className = null) {
// deconstructing the objects
const { x: x1, y: y1 } = pointA;
const { x: x2, y: y2 } = pointB;
// finding the point that's above the other point / has lower y position
const topPoint = y1 <= y2 ? pointA : pointB;
const bottomPoint = y1 <= y2 ? pointB : pointA;
// finding the distance between both points using Pythagoras theorem
const distance = Math.sqrt(
Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)
);

const line = document.createElement("div");
className && line.classList.add(className);

// set the initial styles
const styles = {
backgroundColor: "black",
width: "5px",
height: distance + "px",
position: "absolute",
transformOrigin: "top center",
// setting the top of the line to the point that has lower y position / above the other point along y axis
// Doing so we can simply check the relative rotation towards the bottom pointing from the top point always and that helps us at overall rotating the line
top: topPoint.y + "px",
left: topPoint.x + "px",
// we want the center of the width to be on the x position
// "left" puts the top left corner instead so we have to translate the whole div by 50% along the x axis
translate: "-50% 0"
}


// use a loop to set the styling to the line
for (const [key, value] of Object.entries(styles)) {
line.style[key] = value;
}

// calculate how much it needs to rotate towards the other point keeping the origin at the top center
const base = Math.abs(y1 - y2);
const rotation = Math.acos(base / distance);
// based on weather the bottom point is on the left or right of the top point, we are setting the direction to negative or positive 1 to rotate the line either the right or left direction
const direction = topPoint.x - bottomPoint.x < 0 ? -1 : 1;
line.style.rotate = direction * rotation + "rad"

document.body.appendChild(line);
}
function drawLine(pointA, pointB, className = null) {
// deconstructing the objects
const { x: x1, y: y1 } = pointA;
const { x: x2, y: y2 } = pointB;
// finding the point that's above the other point / has lower y position
const topPoint = y1 <= y2 ? pointA : pointB;
const bottomPoint = y1 <= y2 ? pointB : pointA;
// finding the distance between both points using Pythagoras theorem
const distance = Math.sqrt(
Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)
);

const line = document.createElement("div");
className && line.classList.add(className);

// set the initial styles
const styles = {
backgroundColor: "black",
width: "5px",
height: distance + "px",
position: "absolute",
transformOrigin: "top center",
// setting the top of the line to the point that has lower y position / above the other point along y axis
// Doing so we can simply check the relative rotation towards the bottom pointing from the top point always and that helps us at overall rotating the line
top: topPoint.y + "px",
left: topPoint.x + "px",
// we want the center of the width to be on the x position
// "left" puts the top left corner instead so we have to translate the whole div by 50% along the x axis
translate: "-50% 0"
}


// use a loop to set the styling to the line
for (const [key, value] of Object.entries(styles)) {
line.style[key] = value;
}

// calculate how much it needs to rotate towards the other point keeping the origin at the top center
const base = Math.abs(y1 - y2);
const rotation = Math.acos(base / distance);
// based on weather the bottom point is on the left or right of the top point, we are setting the direction to negative or positive 1 to rotate the line either the right or left direction
const direction = topPoint.x - bottomPoint.x < 0 ? -1 : 1;
line.style.rotate = direction * rotation + "rad"

document.body.appendChild(line);
}
drawLine(
{x:100, y:50},
{x:200, y:500}
)
drawLine(
{x:100, y:50},
{x:200, y:500}
)
Want results from more Discord servers?
Add your server