jQuery custom lighbox
- Started
- Last post
- 30 Responses
- acescence0
again, i would consolidate everything into one "open" function. get rid of the var open = anonymous function on line 59 and make that a separate function. pass all of the stuff you need to that function as arguments, as you have it all available to you right there. then when the image actually loads, show the div that contains the text you've already set back in your open function.
- Stugoo0
funny, i was reading about this earlier today, im done in though. bump it tomorrow and ill see if i can dig out what i was reading.
- acescence0
this is starting from line 48 in your original code...
maybe you want to just pass the numbers to your open function, as you may only have one image and you'll want to check that, but to give you an idea of what i was explaining above.
- juhls0
Hmm...the previous and next buttons don't seem to work, and the right and left keypresses keep going back to the same image rather than moving on to the next one.
The "CC" prevents the lightbox from opening up when the page loads.
Thanks for the help though
- attentionspan0
http://www.nickstakenburg.com/pr…
havent tried it but seems like the neatest out there
- acescence0
yeah, i guess it's a little weird the way it's organized. you've got a lot of anonymous functions doing all of the work in different places, where it could be centralized a bit. i would make a display function that controls everything, and then pass the necessary data to that from each of your links...
showImage( link.attr( 'href' ), link.attr( 'title' ), position, etc );
or you could pass that stuff to the open function on lines 52/59, and amend that to set caption, etc..
- alwaysnice0
i hate lightboxes... yuck
- juhls0
Is there a way to do it without consolidating it? Is that what you mentioned above with the var index = $('a[rel^=imageViewer]').index(t... ?
- juhls0
This is what I have so far. The simplest things are going to kill me. Anyway:
http://pastebin.com/m5da27757I need to make those key presses work (along with the escape button closing the lightbox window), and then add a caption to the image.
Any help would be appreciated. Been at this for hours.
- neverblink0
I've recently discovered shadowbox, it has a nice feature; it resizes the image on browser resize
- zarkonite0
I personally like this guy: http://jquery.com/demo/thickbox/…
why do you want to start from scratch?
- Stugoo0
had issues with most of the above lightboxes for reasons I cannot remeber,
colorbox is the one i use now.
http://colorpowered.com/colorbox…
highly recommend :)
- acescence0
i think the primary reasons for starting from scratch are that you learn and know exactly how it works, and you end up with some code that does exactly what you want, and not a bunch of extra cruft for features you don't even use. lightbox + all the stuff that makes it go clocks in at 190+ k, you can do the same thing in < 10k if you code it up to do exactly what you need.
- a good approach indeed, I got the impression he had a deadline to meet and had zero knowledge.zarkonite
- monNom0
move your previous an next functions out to named functions, rather than anonymous functions following prev.click, next.click
so next.click(function...
becomes
next.click(nextFunc...
and
function nextFunc () {...then call those new functions in your key script.
to add a caption, mimic the '.append' scripts that add the 'close', 'prev' and 'next' buttons to 'displayImage'.
- Daithi0
Colorbox is really good.
- acescence0
this is just the part i updated. not sure it really works
- nocomply0
I wouldn't try to make your own from scratch, but instead focus on the one that's closest to what you need and hack away at it.
i've made some custom tweaks to the original lightbox (http://www.huddletogether.com/p... in the past. It was a bitch but eventually doable.
Maybe one of the lightboxes that runs off of jQuery would offer more of the controls you're looking for? Can't confirm, just a hunch.
- spraycan0
cowbox is nice too