简体   繁体   English

打开后如何制作带有滚动效果的灯箱?

[英]How to make a lightbox with a scroll to top effect when opened?

I'm using lightbox_me script which is based on jQuery. 我正在使用基于jQuery的lightbox_me脚本。 Since my lightbox link is at the bottom of my page, I would like to have a scroll to top effect when someone click on a link that opens the lightbox. 由于我的灯箱链接位于页面的底部,因此当有人单击打开灯箱的链接时,我希望滚动至最佳效果。 So basically the lightbox would be shown at the top of the parent page. 因此,灯箱基本上将显示在父页面的顶部。

I've have setup a clean demo which can be found here : http://lyesdehili.com/LightBox.html 我已经设置了一个干净的演示,可以在这里找到: http : //lyesdehili.com/LightBox.html

$(function () {
    function launch() {
        $('#sign_up').lightbox_me({
            centered: true,
            onLoad: function () {
                $('#sign_up').find('input:first').focus()
            }
        });
    }

    $('#try-1').click(function (e) {
        $("#sign_up").lightbox_me({
            centered: true,
            preventScroll: true,
            onLoad: function () {
                $("#sign_up").find("input:first").focus();
            }
        });

        e.preventDefault();
    });


    $('table tr:nth-child(even)').addClass('stripe');
});


<div style="width:965px; height:1400px; background:#fff">
    <p>Scroll down the page to find the  lightbox link</p>
</div>
<a class="try sprited" id="try-1" href="#">Click to open lightbox</a>
<div style="display:none; height:350px; width:400px; background:#ccc;" id="sign_up">
    <h3 id="see_id" class="sprited" >Can I see some ID?</h3>
    <span>Please sign in using the form below</span>
    <div id="sign_up_form">
        <label><strong>Username:</strong> <input class="sprited"/></label>
        <label><strong>Password:</strong> <input class="sprited"/></label>
        <div id="actions">
            <a class="close form_button sprited" id="cancel" href="#">Cancel</a>
            <a class="form_button sprited" id="log_in" href="#">Sign in</a>
        </div>
    </div>
    <h3 id="left_out" class="sprited">Feeling left out?</h3>
    <span>Don't be sad, just <a href="#">click here</a> to sign up!</span>
    <a id="close_x" class="close sprited" href="#">close</a>
</div>
$('#try-1').click(function(e) {
    $('body').scrollTop(0);
    $("#sign_up").lightbox_me...; // continue with your code here
});


Add a scrollTop statement to scroll to the starting of the page. 添加scrollTop语句以滚动到页面的开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM