• Hi.

    I was playing around with scroll to id from different pages.

    I used the whole https://url.com/#targetid instead of just #targetid

    this works but there are two issues.

    1) when from another page I click on the link its a little jumpy when it reloads the page
    2) the link text that has the “https://url.com/#targetid” remains highlighted even when not clicked.

    PS I have only tested with one link. on the headeryou will see the link thats highlighted even when not clicked

    I would like the scroll to id when clicked from another page to not be jumpy if thats possible.

    can I not have the link highlighted

    Regards

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author malihu

    (@malihu)

    Hi,

    1)The “jumpy” behavior happens due to page layout (and content) and cannot be fixed within the plugin. Certain page elements (like video, images etc.) are loaded with a bit of latency (which is normal) and this makes the page “jump” before scrolling to the target.

    We don’t have control on how the browser loads these elements or how the theme is laid-out. If you don’t want this behavior, the only thing you can do is to disable “Scroll from/to different pages” option (in plugin settings), so the page instantly jumps to the target (when coming from a different page).

    2)The link is highlighted by the theme itself. You can bypass it by adding the following CSS rules in your custom/additional CSS:

    .main-navigation .main-nav ul li[class*="current-menu-"]>a._mPS2id-h{
      background-color: transparent;
    }
    .main-navigation .main-nav ul li[class*="current-menu-"]>a._mPS2id-h:hover{
      background-color: #3f3f3f;
    }
    

    Another way to do it, is to edit your theme’s stylesheet and find/change the selector:

    .main-navigation .main-nav ul li[class*="current-menu-"]>a{
        color: #fff;
        background-color: #3f3f3f;
    }

    to:

    .main-navigation .main-nav ul li[class*="current-menu-"]>a:not(._mPS2id-h){
        color: #fff;
        background-color: #3f3f3f;
    }

    Hope this helps

    • This reply was modified 8 years, 5 months ago by malihu.
    Thread Starter dgops

    (@dgops)

    Hmmm.

    Thanks for the prompt reply. however looks like the problem was not solved.

    1) I tried disabling “Scroll from/to different pages” option (in plugin settings). this however messes up the offset and does not load at the target, goes slightly below where I’d like it to be. I tried it with a blank canvas with no images or videos and have the same problem. also I have set the size of images and am not using lazy load.

    In addition to disabling “Scroll from/to different pages” option (in plugin settings) is there some step that needs to be followed to not mess up the offset?

    2) the CSS you provided removed the highlight altogether. What I was trying to say is I’d like it to be highlighted when clicked. the problem was that when I used https://url.com/#targetid it stays highlighted all the time. when i change this to just #targetid the highlight problem goes away.

    As I was saying earlier I tried with a blank canvas with no images or videos and on multiple browsers. also tried using two different themes. same problem. Please help.

    Regards
    D

    Plugin Author malihu

    (@malihu)

    2)For the links highlighting, change the CSS to:

    .main-navigation .main-nav ul li[class*="current-menu-"]>a._mPS2id-h{
      background-color: transparent;
    }
    .main-navigation .main-nav ul li[class*="current-menu-"]>a._mPS2id-h:hover, 
    .main-navigation .main-nav ul li[class*="current-menu-"]>a.mPS2id-clicked{
      background-color: #3f3f3f;
    }

    This will highlight the clicked link.

    If you want to highlight the current section link (on-the-fly), change it to:

    .main-navigation .main-nav ul li[class*="current-menu-"]>a._mPS2id-h{
      background-color: transparent;
    }
    .main-navigation .main-nav ul li[class*="current-menu-"]>a._mPS2id-h:hover, 
    .main-navigation .main-nav ul li[class*="current-menu-"]>a.mPS2id-clicked{
      background-color: #3f3f3f;
    }

    1)Disabling “Scroll from/to different pages” option will indeed remove the offset etc. as this disables “Page scroll to id” from handling scrolling to the target on page load.

    We can’t really do anything for the momentary jump when coming from another page.

    What might work is the following:

    1. Enable “Scroll from/to different pages” option
    2. Set “Scroll duration” to 1
    3. Add the following class to each one of your menu links (in Admin – Menus):
      ps2id-speed-1000

    Doing the above will set the default scrolling duration to 1 millisecond (i.e. instant), so scrolling to/from other pages will scroll to the target instantly but with the offset we want. Adding the ps2id-speed-1000 class to the links, bypasses the default scroll duration (1) and sets it to 1000 so scrolling to same-page targets smooth (i.e. not instant).

    Thread Starter dgops

    (@dgops)

    1) This worked as you said. only wish if there was anyway to avoid the momentary jump. it does not have this jumpy behavior on mobile, only on desktop. maybe there is some code level changes that could fix this?

    2) Still having trouble here. the CSS highlights the clicked link as long as I am on the same page. when I go to another page and try to come back by clicking on the menu items it does not highlight the clicked menu item.

    Also the two CSS codes you sent me are identical. were they meant to be the same?

    Regards
    D

    Thread Starter dgops

    (@dgops)

    Would like to add one thing I noticed on the browser.

    From another page when I click browser menu the browser loads in the following manner

    https://url.com/#targetid

    https://url.com/#

    https://url.com/#targetid

    This gives kind of a yoyo effect when the page loads. Hope that makes sense

    Regards

    Plugin Author malihu

    (@malihu)

    2)Ah sorry for the identical code, my bad. It should be:

    .main-navigation .main-nav ul li[class*="current-menu-"]>a._mPS2id-h{
      background-color: transparent;
    }
    .main-navigation .main-nav ul li[class*="current-menu-"]>a._mPS2id-h:hover, 
    .main-navigation .main-nav ul li[class*="current-menu-"]>a.mPS2id-highlight{
      background-color: #3f3f3f;
    }

    If you use the above, you should also enable “Keep the current element highlighted until the next one comes into view” option. This is because you’re using simple targets that do not hold all section content.

    1)The behavior of https://url.com/#targetid and https://url.com/# is correct. It’s not the reason for the yoyo effect.

    Since you changed the scroll duration to 1, I can’t see any momentary jump most of the times (when coming from a different page).

    The majority of pages/websites do not produce this jump/yoyo effect. This might be affected by the way the page is cached(?)

    In any case, you cannot have full control on how to scroll to targets when coming from a different page/url. To have “perfect” single-page scrolling, you need a single-page. Otherwise, you’ll need a custom script (or some plugin) that “hides” the content while the page is loading (which hides such behaviors) and reveal it when ready to scroll.

    Thread Starter dgops

    (@dgops)

    1) I understand and I can work with it. the momentary jump is tolerable and not a show stopper in any way. thanks for your patience and help with this.

    2) this part however continues to be a problem. I used the second code and enabled “Keep the current element highlighted until the next one comes into view” doing this makes the first two links highlighted. I believe the two sections are too close and hence they are both highlighted at the same time. this definitely is a problem. I even tried disabling “Keep the current element highlighted until the next one comes into view” but see the same result.

    There must be a simpler way to fix the highlight issue. The highlight issue only happens when I use https://url.com/#targetid. when I only use #targerid I never encountered this problem.

    Regards

    Plugin Author malihu

    (@malihu)

    When you use https://url.com/#targetid (instead of just #targerid), the WordPress theme detects that the link points to the page/url as the one displayed in browser’s address bar (i.e. same page link) and makes it highlighted.

    The highlight happens by the theme itself (not by “Page scroll to id”).

    When you use simply #targerid, the theme does not consider it as same-page link, thus the highlight disappears.

    So, what we’re doing is resetting the theme’s highlight and use the highlight by “Page scroll to id” which works all the time (e.g. when scrolling, going back with the browser’s button etc.).

    To avoid having 2 links highlighted, try changing the CSS to:

    .main-navigation .main-nav ul li[class*="current-menu-"]>a._mPS2id-h{
      background-color: transparent;
    }
    .main-navigation .main-nav ul li[class*="current-menu-"]>a._mPS2id-h:hover, 
    .main-navigation .main-nav ul li[class*="current-menu-"]>a.mPS2id-highlight-first{
      background-color: #3f3f3f;
    }

    and keep “Keep the current element highlighted until the next one comes into view” enabled.

    Let me know

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Scroll to id from different page’ is closed to new replies.