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

Page scrolls to top when opening modal without # navigation #7

Closed
mweterings opened this issue Mar 26, 2014 · 7 comments
Closed

Page scrolls to top when opening modal without # navigation #7

mweterings opened this issue Mar 26, 2014 · 7 comments
Labels

Comments

@mweterings
Copy link

Even when I don't use the hashTracking function the page scrolls back to top when open the Remodal window, is there a way to fix this ?

The code:

<a data-remodal-target="test" class="huug" id="test">
    <div class="single-project">
        <div class="caption"><p>Test</p></div>
        <img width="750" height="500" src="thumbnail">
    </div>
</a>

<div class="remodal" id="modal_test" data-remodal-id="test">
    <!-- load dynamic content --> 
</div>          

<script>
$(document).ready(function() {
    $("a.huug").click(function() {
        var pid = $(this).attr("id");
        $("div#modal_"+pid).load("/?projects="+pid);
    });
});
</script>
@vodkabears
Copy link
Owner

You use hash tracking, you just call it without hash =). Write this to disable it:

<div class="remodal" id="modal_test" data-remodal-id="test"
     data-remodal-options='{ "hashTracking": false }'>
    <!-- load dynamic content --> 
</div>

The page scrolls back to the top, because of the native behavior of any browser. Your link has an id attribute 'test', when the hash changes to '#test', it scrolls back to the anchor with a 'test' id. By the way, it is the reason, why i've added 'data-remodal-id' instead of 'id' attribute.

@vodkabears
Copy link
Owner

But yes, thanks, i've tested it, it has a wrong behavior. I found that a page scrolls to the top, when closing modal, i've broken something. I will fix it soon.

@mweterings
Copy link
Author

Thanks for your fast response appreciate it, really like your plugin!

Already had disabled the hashtracking in de remodal.js file. And now using rel instead of id but still when opening the modal it scrolls back to the top not just when closing the modal.

@vodkabears
Copy link
Owner

OK, will be fixed.

@carlos1162
Copy link

In the script there is a piece of code that goes like this at the very end of this script (location.hash = "";) just add "id" in between the quotes, and it will save the current scroll position so it looks like this:
/**
* Close modal window
*/
Remodal.prototype.close = function () {
// check if animation is complete
if (this.busy) {
return;
}
this.busy = true;

    this.modal.trigger("close");

    if (this.settings.hashTracking &&
        this.modal.attr("data-" + pluginName + "-id") === location.hash.substr(1)) {
        // save current scroll position
        location.hash = "id";
    }

@mweterings
Copy link
Author

Thanks for your tip but it doesn't seem to work it just puts #id at the end of the url instead of #
i'm using the script on this website: http://stabstudio.com

@vodkabears
Copy link
Owner

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

No branches or pull requests

3 participants