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

Using Confirm and scrollTop in action causes page to scroll up and then back down #468

Closed
dcdalton opened this issue Mar 15, 2019 · 4 comments

Comments

@dcdalton
Copy link

dcdalton commented Mar 15, 2019

jquery-confirm version:
v3.3.0

I'm submitting a ... (check one with "x")
[ ] bug report
[ ] feature request
[x] support request

Current behavior:
Using the jQuery confirm to tell user there are issues within the submitted form, in the action on the button I have a scrollTop. When the button is clicked the page scrolls to the top and then back down to the bottom.

Expected behavior:
Expect page to scroll top and stay there, here is my code:

$.alert({
	boxWidth: '50%',
	useBootstrap: false,
	title: '<p>Questionnaire Errors Found</p>',
	titleClass: 'alert_title',
	content: "<p class='alert_body'>Errors were found in the submitted questionaire and are highlighted in red</p><p class='alert_body'>Please review and correct the missing information</p>",
	buttons:	{
		okay:	{
			text: 'Okay',
			btnClass: 'alert_button',
			action: function()	{
				$('html').stop().animate({
					scrollTop: $('#voters_guide_form').offset().top
					}, 500);
							
				}
			}
		}
	});

I should also note without using jQuery-confirm the behavior is correct. I have also played with using different element ids in the scrollTop and even added the .stop() before the animate call. Nothing changes

@Hizoka76
Copy link

Hizoka76 commented Mar 18, 2019

Hi, I haved same problem, i solved it with :

okay:
{
    text: 'Okay',
    btnClass: 'alert_button',
    action: function()
    {
        setTimeout(function() 
        {
            $('html').stop().animate(
            {
                scrollTop: $('#voters_guide_form').offset().top
            }, 500);
        }, 100);
}

@dcdalton
Copy link
Author

HMM, that's not working for me either, here's the new code I am using:

okay:	{
	text: 'Okay',
	btnClass: 'alert_button',
	action: function()	{

		setTimeout(function()	{

			$('html').stop().animate({
			     scrollTop: $('#voters_guide_form').offset().top
				}, 500);

			}, 100);
							
		}
					}

@Hizoka76
Copy link

Hizoka76 commented Mar 19, 2019 via email

@dcdalton
Copy link
Author

BINGO! I set the timeout to 600 and it now works perfectly ..THANKS!

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

2 participants