How To Create Image Gallery In JavaScript | Horizontal Scrolling Using JavaScript

How To Create Image Gallery In JavaScript | Horizontal Scrolling Using JavaScript

GreatStack

1 год назад

98,889 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

uryuIshida
uryuIshida - 19.11.2023 11:55

Guys if you find ur js script dont work, juts replace all the (container) in ScrollContainer. Replace the Container with Bar, like this Scrollbar. Thats all

Ответить
Che Fernandez
Che Fernandez - 17.11.2023 18:31

Guys if your scroll behaviour isnt working its cause it should be behavior amrican eng

Ответить
Che Fernandez
Che Fernandez - 17.11.2023 18:17

The java script disnt work at all intwrnal and external

Ответить
Esarar Saikh
Esarar Saikh - 03.11.2023 09:13

Well explained sir😇😇

Ответить
indian-shorts
indian-shorts - 31.10.2023 18:05

hi can you please help me with the scroll bahvciour on click its not working

Ответить
Suhas Gardare
Suhas Gardare - 02.10.2023 15:44

Thank you sir... ❤❤

Ответить
AFC with Sabir
AFC with Sabir - 30.09.2023 10:16

This is very helpful sir❤❤❤

Ответить
BILAL Beny
BILAL Beny - 29.09.2023 01:41

what I can say is thank you so much for your videos, you are a great teacher.
🤩🤩🤩

Ответить
Cameron Fletcher
Cameron Fletcher - 24.09.2023 10:30

I cant get my buttons to work can anyone help

Ответить
collins omonievusa
collins omonievusa - 23.09.2023 13:05

1)i don't know but this code ain't working for me, perhaps the source code can help but for some reason it's no where to be found...
2) The prevent default is not preventing the default scroll behaivour don't know why

Ответить
time to laugh😂
time to laugh😂 - 17.09.2023 22:32

Thank you sooo much 😊, your video helped me alot.
Thanks again 😊

Ответить
Marijana Maja Đuričić
Marijana Maja Đuričić - 02.08.2023 11:39

Hello. In my case, don't work 'deltaY' and 'scrollBehavior'. Why? If anyone knows the answer, it would mean a lot to me. Thank you.

Ответить
jaydeep patil
jaydeep patil - 27.07.2023 19:01

Can you please make a video on all event listeners that are useful for these type of mini projects

Ответить
BlueFish
BlueFish - 16.07.2023 10:38

The only real issue I had after watching this video was that my JavaScript didn't work. Otherwise, simple and awesome!

Ответить
ARES MOBILIARIO
ARES MOBILIARIO - 15.07.2023 00:12

Friend, a question
How can I add more images?
It only allows me to add 6
When I add more images it deforms

Ответить
Rajnandini Patel
Rajnandini Patel - 14.07.2023 14:44

thanks but I want to scroll down, what should I do

Ответить
Azer Dunyamaliyev
Azer Dunyamaliyev - 09.07.2023 11:46

Thank you very much :D

Ответить
CodeWithLuap
CodeWithLuap - 05.07.2023 09:40

is it responsive?? damn why guyz never give media query

Ответить
Captain Br0st.
Captain Br0st. - 04.07.2023 16:40

Hats off to you

Ответить
Alif Azib
Alif Azib - 20.06.2023 20:47

Hi, thanks for showing us on how to apply these effects using javascript. Just to add something to your coding if you wanted to make the gallery "automatically scroll" to the next 3 images, you can try adding conditional and comparing your "evt.deltaY" whether it receives "negative value (left scroll)" or "positive value (right scroll)";


scrollCont.addEventListener("wheel", (evt) => {
scrollCont.style.scrollBehavior = 'smooth';
evt.preventDefault();
if(evt.deltaY < 0) {
scrollCont.scrollLeft = (Math.floor(scrollCont.scrollLeft/900)*900)-900;
} else if (evt.deltaY > 0) {
scrollCont.scrollLeft = (Math.floor(scrollCont.scrollLeft/900)*900) + 900;
}
});

nextBtn.addEventListener("click", () => {
scrollCont.style.scrollBehavior = 'smooth';
scrollCont.scrollLeft += 900;
});
backBtn.addEventListener("click", () => {
scrollCont.style.scrollBehavior = 'smooth';
scrollCont.scrollLeft -= 900;
});

______________________________________________________________________
// ofcourse if you wanted to make the "scrolling effect" to maintain its position, its possible but the bug is when you scroll and the position remains in between the interval of 0-900, the back/next button doesnt automate to the perfect position of the previous/next 3 images. So in order to rectify this, you can add conditional for both nextBtn and backBtn's "click" event listener:


scrollCont.addEventListener("wheel", (evt) => {
scrollCont.style.scrollBehavior = 'smooth';
evt.preventDefault();
scrollCont.scrollLeft += evt.deltaY;
});

nextBtn.addEventListener("click", () => {
scrollCont.style.scrollBehavior = 'smooth';
scrollCont.scrollLeft += 900;
if (scrollCont.scrollLeft % 900 !== 0) {
scrollCont.scrollLeft = (Math.floor(scrollCont.scrollLeft/900)*900) + 900;
}
});
backBtn.addEventListener("click", () => {
scrollCont.style.scrollBehavior = 'smooth';
scrollCont.scrollLeft -= 900;
if (scrollCont.scrollLeft % 900 !== 0) {
scrollCont.scrollLeft = (Math.floor(scrollCont.scrollLeft/900 )*900);
}
});

//what it does is that it reads the remainder if the button you click will have any remain values after divided with 900. If it does, it will automate to the perfect position of the previous/next 3 images. Hope this helps!

Ответить
Benji Cañones
Benji Cañones - 17.06.2023 07:35

When I external the JS, the side-scrollbar does not behave as internal JS.

Ответить
Esca P.F
Esca P.F - 07.06.2023 18:30

Hi, thank you ! I was trying it but the back btn was not working because I written : "scrollContainer.scrollLeft += 900" instead of -900 hahaha

Ответить
Benhafsa Ilhem
Benhafsa Ilhem - 27.05.2023 23:32

Thanks for share it works very well

Ответить
chathura chinthaka
chathura chinthaka - 12.05.2023 08:14

where is source code file? even i subscribed this

Ответить
Odartei Lamptey
Odartei Lamptey - 22.04.2023 15:10

As always 100% on point 👌

Ответить
Twoon Swig
Twoon Swig - 31.03.2023 20:06

For some reason scrolling right/forward isn't working in my code, anyone else found this problem?/know how it might be helped?

Ответить
easy programming lessons
easy programming lessons - 24.03.2023 19:01

Sir, I found this tutorial useful. Thanks!

Ответить
Samiul islam Sourov
Samiul islam Sourov - 16.03.2023 12:09

Sir i tried many time...but scrollBehavior doesn't work. Why it doesn't work?

Ответить
Rohit Parmar
Rohit Parmar - 13.03.2023 16:16

Hi There, Thanks for this amazing tutorial!
Can you please tell me the reason of placing img tag inside span tag and how it is helpful ?

Ответить
Litun Khan
Litun Khan - 09.03.2023 18:02

plx solve this if i use 9 image 0r 12 its just work 6 image not 9 or 12

Ответить
Litun Khan
Litun Khan - 09.03.2023 17:13

if i used nine image it just show just six baki sab nahi ata hai click karne ke bat vi

Ответить
Mani Dynamic
Mani Dynamic - 07.03.2023 13:15

Can you tell me how to make free png images ???

Ответить
jjjj
jjjj - 06.03.2023 13:58

Dark theme i use after watching one of your videos. But if I refresh the page, it comes back to the previous theme. What is the solution?

Ответить
Samiul islam Sourov
Samiul islam Sourov - 04.03.2023 08:23

Sir, please create a slider without using swiper js.... please create a slider using html,css and JavaScript. Please don't use any plugin. Please sir, please 🙏

Ответить
gibert malto
gibert malto - 04.03.2023 03:23

Hey, brother, can you make Anime websites?

Ответить
Ugwoka Anthony
Ugwoka Anthony - 03.03.2023 12:12

I wrote an investment template using html, css and js but I don't know how to connect the admin so that it controls the user interface

Ответить
Briankay
Briankay - 02.03.2023 22:47

this javascript failed to work in my external file

Ответить
Mr Lonely Tv (offornna_fine)
Mr Lonely Tv (offornna_fine) - 02.03.2023 13:02

Great job

Ответить
Антон Григорьевич
Антон Григорьевич - 02.03.2023 00:38

I like the visual theme of your code editor, very eye-catching, what’s the name?

Ответить
Антон Григорьевич
Антон Григорьевич - 02.03.2023 00:23

Simple and cool ! Thanks for helpful video.

Ответить
Pumpkin Pie
Pumpkin Pie - 01.03.2023 20:13

And how can I make this responsive in mobile device If I use absolute values for the width of container just like you?
Maybe change the grid column template?

Ответить
guru 88
guru 88 - 01.03.2023 20:02

Nice! is this gonna be responsive and working on phones?

Ответить
venkatachalam
venkatachalam - 01.03.2023 19:40

Nice sir ,

Ответить
Arigato
Arigato - 01.03.2023 18:49

Hey. I had a question. Could you please tell me how to upload an image in a website and then display the uploaded image in a separate website? Would be really helpful, Thank you

Ответить
jae chan park
jae chan park - 01.03.2023 17:00

Thank you I love JAVASCRIPT!!!!

Ответить
ProgrammingTT
ProgrammingTT - 01.03.2023 16:40

I make projects using HTML, CSS and JavaScript (with code, for beginners).💻

Ответить