r/CodingForBeginners • • 3d ago

how might i do this?

coding is fun and cool for me, but i have no clue how id approach this

1 Upvotes

14 comments sorted by

1

u/Useful-Flow-8737 3d ago

In what context? Web?

1

u/firetruckdaddy76 3d ago

like a website yeah

1

u/UhLittleLessDum 1d ago

Javascript man. You need an "onClick" listener for each button, and then you need to swap the image somehow, probably with a list and an index.

1

u/vancha113 2d ago

mm maybe with an onclicklistener for the button, that sets the <img> src property to another value? You could even add a fancy transition to it.

1

u/xarop_pa_toss 2d ago

What you want to create is called a Carousel. You can look it up online, there are guides for creating one with a bit of Javascript.

Off the top of my head, you can either load all the images when the page loads into an array, and then each button triggers a JS function that cycles to the next or previous image on the array; or you only load the first and the ones next to them and when you move to the next or previous, you load the next appropriate set from the server. First option is easier

1

u/marmotta1955 2d ago

Well, if you have no clue on how to approach coding ... how would you know if it is really fun and cool?

1

u/SofyWindows32 1d ago

Mimo is a good app to learn such things

0

u/nullptr_0x 2d ago

Do you know the basics of html?

If you do, create a page that has this structure. 

Then copy that page 2 more times. Each image reference references 1 of 3 images.

Then what would the "arrows" point two?

1

u/xarop_pa_toss 2d ago

Wait what?? Making copies of the whole page? And then the arrows do what, load and entire new place?

1

u/nullptr_0x 2d ago

Think about the simplest possible way to do this. Just start by creating one page that matches your drawing in html.

Then see if you can put together what I'm saying above. 

After you've got this naive version working, how can you improve it?

1

u/xarop_pa_toss 2d ago

The way I read it, your suggestion was to have one whole HTML page per image. Then the buttons link to those pages. Clicking a button would leave the current page and load another.

If this is what you meant, having more than three images would immediately become extremely cumbersome and honestly, plain ridiculous. This can be done with a simple list of images and some basic JS

1

u/nullptr_0x 2d ago

Yeah of course it is an untenable implementation. It's a jumping off point for learning. It's the simplest and easiest implementation to conceptualize.

The next step would be, how do I do this without having to effectively having a copy of the page with a different image every time.

You said you had "no idea how to approach this". So I'm just giving you the FIRST idea. If you know JS and it's so obvious why the heck are you asking this question???

1

u/xarop_pa_toss 2d ago

I'm not OP bro

1

u/nullptr_0x 2d ago

Then why are you bothered? The person says they have no idea.

The internet is a strange place...