Support » Plugin: Page scroll to id » Scroll 50% of the viewport when clicking a button, without a target anchor

  • Hi!
    Your plugin is great, I already use it on dozens of sites…

    Just today I came across something more customized, I need for example:

    After clicking on an element, the page scrolls down 50% (viewport), I didn’t find anything like that in the documentation…

    I already have an event listening to this click, I also change other things on the page when it clicks, I just need to scroll 50% of the screen height.

    Can I get this with your plugin?
    Only with javascript can I do this smooth scrolling? The times I tried there was no transition, it just jumped straight.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ofmarconi

    (@ofmarconi)

    It’s just that I wanted to control it a little thinner, for example, to execute this movement with a delay.

    Plugin Author malihu

    (@malihu)

    Hello,

    This can only be done with javascript. Without knowing exactly how your page works, you can try adding the following code in your js click event:

    If you need to scroll to the middle of the viewport, you can try this:

    var autoSrollDelay=500;
    $("body").prepend("<div id='doc-middle' style='position:absolute;left:0;top:50vh;'></div>");
    setTimeout(function(){
        $.mPageScroll2id("scrollTo","#doc-middle");
    },autoSrollDelay);

    If you need to scroll to the middle of the document (the whole document, not just the screen/viewport), you can try adding this:

    var autoSrollDelay=500,
        body=document.body,
        html=document.documentElement,
        docMiddle=Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight) / 2;
    $("body").prepend("<div id='doc-middle' style='position:absolute;left:0;top:"+docMiddle+"px;'></div>");
    setTimeout(function(){
        $.mPageScroll2id("scrollTo","#doc-middle");
    },autoSrollDelay);

    You can change the autoSrollDelay value to the scroll delay you want (this is in milliseconds, e.g. 500=0.5sec).

    Let me know if this helped

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Scroll 50% of the viewport when clicking a button, without a target anchor’ is closed to new replies.