Hi i am fairly new to coding, i have been coding for about 6 months now
I am currently trying to develop my own custom made lightbox, just for the fun of it!
Okay so my problem’s is
How do i make the “pop-up image” vertically/Horisontally in the middle/center of the whole page by all times? This has be somehow automated since there will be different size pictures in the lightbox gallery so i have had bad experince just giving it some pix or % ?
How do i make my “Next”/“Previous” buttons work? i would like a fade-in/fade-out effect of each image, only 1 img in there now but i would like to add more?
The display:table-cell with vertical-align:middle automatically centres the content regardless of size. For modern browsers you could use flexbox for vertical centering instead. Avoid the translate method or the absolute method for centering as they end up with content outside the viewport and unreachable.
I’ll leave the js previous and next to someone else
When everything is done i want 5 thumbnails to be able to click “(Cars)(Bikes)(Planes)(Motorcycles)(Boats)”
When one of the thumbnails is clicked AJAX,PHP,MYSQLI,Javascript/Jquery ? has to work together it has to import that set of pictures from the clicked category into the lightbox, if this makes sence? so that the html is not put directly into the page but is imorted from somewhere (mysqli)??
The only thing is i am not at all good at AJAX,PHP,MYSQLI and Javascript/Jquery i am pretty comfortable with html/css but it is also the easy part
Well you could certainly do this with AJAX, jQuery has some handy commands there, too. For example, you could specify the image sources in the aforementioned data-lightbox attribute, separated by spaces, like
store these sources in an array, and then fetch the images with $.get() sequentially each time you click the next button.
But here’s another idea: just put all 5 thumbnail links in one li element, but set 4 of them to display: none. Then my code above will allow you to cycle through all (and only) the images within the same ‘li’ element.
1 thumbnail for each category, when the category is pressed (etc cars) pic 1 shows in the lightbox then you press next then pic 2 is shown in the lightbox? This is the thing i want
Well ill take a very long bath now since i have to process all of this :smisweat:
Well, my suggestion above does exactly that. Here’s a fiddle. I’ve omitted the overlay and basically all CSS stuff, so it’s just the relevant JS bits. Also, I’ve tweaked the code a bit so that the next/previous button only shows when there actually is a next/previous image.
The fiddle you gave me does the job with prev/next and fading in/out but i cant figure out how to integrate this with the lightbox i have ? somehow the images does not display inside of the lightbox ?
You’re trying to access this element with $('.lightbox-content img'), but if it is not there, the jQuery selector will just return an empty object. Of course, you can also check if it’s there and create it if necessary with
if (!$('.lightbox-content img').length) {
$('.lightbox-content').prepend('<img />');
}
Okay i got it to work, the only problem is that my thumbnail is something a little more complicated, it contains 3-4 divs with hover caption etc etc… and i cant get it to work with that but ill try, i have to restart my pc just a sec
sets any image inside .lightbox-content to the new src. The solution is to select the image you want to address in an unambiguous way; in this case this is possible with
since the navigation elements are in another div and not an immediate child of .lightbox-content. However, if you want to be on the safe side, simply assign a unique class or an id to that image
I litterally start crying soon… i cant seem to integrate this so that it works properly
I was close once… but then somehow all my code rolled back (i dont know how it did it) to the beginning before you and i started this… very weird since i did save the project.
Well i have to start all over again trying to get this to work, i honestly feel shattered lol
Seriously wtf is going on… i cant even get the fiddle to work when i copy paste it over in a brand new project, then the next/previous buttons does not show when the image is displayer, wtf…