Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open on Page Load #34

Open
zeshan77 opened this issue Oct 8, 2013 · 4 comments
Open

Open on Page Load #34

zeshan77 opened this issue Oct 8, 2013 · 4 comments

Comments

@zeshan77
Copy link

zeshan77 commented Oct 8, 2013

Love the simple but useful plugin. I need to open the model on Page Load.
Can any one please help?

Thanks in advance.

@zeshan77
Copy link
Author

zeshan77 commented Oct 8, 2013

@FinelySliced

@thegearbox
Copy link

I am also looking to do this urgently!

@thegearbox
Copy link

I have found a way to do this courtesy of Dan F (http://stackoverflow.com/questions/6702887/leanmodal-initiate-without-click?answertab=active#tab-top).

Basically you need to create a hidden a href link and call it as a click onLoad.

Script:

    <script type="text/javascript">
        $(function() {
            $('a[rel*=leanModal]').leanModal({ top : 200, closeButton: ".modal_close" });
            $("#showDivId").click();        
        });
    </script>

Hidden Link:

<a href="#DivId" id="showDivId" style="display:none" rel="leanModal" name="DivId"></a>

Hope this helps

@kayaz
Copy link

kayaz commented Oct 5, 2014

(function($){
    $.fn.extend({
        leanModal:function(options){
                var defaults={
                    top:100,
                    overlay:0.5,
                    target:null,
                    closeButton:null,
                    auto:false
                    };
                var overlay=$("<div id='lean_overlay'></div>");

                $("body").append(overlay);
                options=$.extend(defaults,options);
                var o=options;
                if(o.auto == true) {
                        var modal_id=o.target;
                        $("#lean_overlay").click(function(){close_modal(modal_id)});
                        $(o.closeButton).click(function(e){close_modal(modal_id);e.preventDefault();});
                        var modal_height=$(modal_id).outerHeight();
                        var modal_width=$(modal_id).outerWidth();

                        $("#lean_overlay").css({"display":"block",opacity:0});
                        $("#lean_overlay").fadeTo(200,o.overlay);
                        $(modal_id).css({"display":"block","position":"fixed","opacity":0,"z-index":11000,"left":50+"%","margin-left":-(modal_width/2)+"px","top":o.top+"px"});
                        $(modal_id).fadeTo(200,1);
                }
                if(o.auto == false) {
                    return this.each(function(){
                        $(this).click(function(e){
                            var modal_id=$(this).attr("href");
                            $("#lean_overlay").click(function(){close_modal(modal_id)});
                            $(o.closeButton).click(function(e){close_modal(modal_id);e.preventDefault();});
                            var modal_height=$(modal_id).outerHeight();
                            var modal_width=$(modal_id).outerWidth();

                            $("#lean_overlay").css({"display":"block",opacity:0});
                            $("#lean_overlay").fadeTo(200,o.overlay);
                            $(modal_id).css({"display":"block","position":"fixed","opacity":0,"z-index":11000,"left":50+"%","margin-left":-(modal_width/2)+"px","top":o.top+"px"});
                            $(modal_id).fadeTo(200,1);
                            e.preventDefault()
                        })
                    });
                }
                function close_modal(modal_id){
                    $("#lean_overlay").fadeOut(200);$(modal_id).css({"display":"none"})
                }
            }
            })
            })(jQuery);

and then:

    $("").leanModal({top:200, target:"#thxforsend", closeButton: ".modal_close", auto:true});
    $("a[rel*=leanModal]").leanModal({top:200, closeButton: ".modal_close"});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants