开发者

jquery maintain scroll position for modal dialog

If users are not authenticated and click something only authenticated users do then i am loading a modal dialog saying they need to login to perform this.

the modal contains a link which when clicked is meant to load a modal dialog with a login form.

this is what i have:

$("#login-link").click(function () {
开发者_运维问答        $("#dialog-unauthenticated").dialog("close");
        var x = $(this).position().left + jQuery(this).outerWidth();
        var y = $(this).position().top - jQuery(document).scrollTop();
        $("#dialog-form").dialog("open",{position:[x,y]});

    });

it works okay, the only problem is that the page does not maintain the scroll position. the dialog loads in the right place.

how can i maintaining page scroll position instead of it scrolling to the top?


when opening the first modal (or right before) - save the page (document? document.body?) scroll position into some variables. then, on your $("#login-link").click() function, set it to those values you saved. sorry I don't have code for you, but basicall it's

$(document).scrollTop() 
// or
$(document.body).scrollTop()
// or even without the $ function!
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜