views:

25

answers:

1

Does anyone familiar with Lightbox2 (http://www.huddletogether.com/projects/lightbox2/) know how to trigger a lightbox onLoad and preferably with a 1 minute delay?

A: 

I used some info from another SO post to simulate the click event: http://stackoverflow.com/questions/460644/trigger-an-event-with-prototype

Get the code from event.simulate.js and include a reference in your file.

<script src="js/simulate.js" type="text/javascript"></script>

Add an id to the anchor link you want to auto-fire:

<a href="images/image-1.jpg" id="openLink" rel="lightbox">

Then at the bottom of your file insert this code (or put in external file):

<script type="text/javascript">
    function openLightbox() {
        $('openLink').simulate('click');
    }
    document.observe("dom:loaded", function() {
        openLightbox.delay(5);
    });
</script>

The number in the delay() function is the number of seconds you want to wait before the lightbox fires off.

Shawn Steward
Thanks Shawn. Simulating a click was a great idea, I actually went ahead and just used Prototypes default click action to simulate a click. Worked like a charm.
radrew
Ok cool, I am not familiar with Prototype and couldn't easily find how they did that.
Shawn Steward