Trigger Lightbox onLoad w/ Delay

浪尽此生 提交于 2019-12-13 18:19:23

问题


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?


回答1:


I used some info from another SO post to simulate the click event: 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.



来源:https://stackoverflow.com/questions/3443663/trigger-lightbox-onload-w-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!