Page scroll to id
Page scroll to id is an easy-to-use jQuery plugin that enables animated page scrolling to specific id within the document. The plugin replaces the default browser behaviour of “jumping” to page sections when links with href value containing hash (#) are clicked, by smoothly animating the page to those sections. You can use it for simple back-to-top links or complex, single-page website navigation and features include: adjustable animation speed, advanced animation easings, vertical and/or horizontal scrolling, ready-to-use classes for links highlighting etc.
Current version 1.6.8 (Changelog)
- Get started
- Configuration
- Methods
- Code examples & short tutorials
- FAQ
- Page scroll to id for WordPress
How to use it
The plugin works simply by connecting links in the form of <a href="#id">link</a>
, to sections within the document, in the form of <div id="id">target</div>
. Clicking the links will smoothly animate the page to the connected sections.
Get started by Downloading the archive which contains all plugin files and examples. Extract and upload jquery.malihu.PageScroll2id.min.js to your web server.
Include jQuery library (if your project doesn’t use it already) and jquery.malihu.PageScroll2id.min.js in your document’s head tag or at the very bottom of your html, just before the closing body tag (recommended for better performance)
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="jquery.malihu.PageScroll2id.min.js"></script>
After files inclusion, call mPageScroll2id function on the matching set of elements (selectors) you want the plugin to handle
<script> (function($){ $(window).on("load",function(){ $("a[rel='m_PageScroll2id']").mPageScroll2id(); }); })(jQuery); </script>
Using the a[rel='m_PageScroll2id']
selector above, means that the plugin will apply on links with m_PageScroll2id
rel attribute value (e.g. <a href="#id" rel="m_PageScroll2id">link</a>
). You can change the selector to anything you want (id, class name, js variable etc. – strings that represent ways of choosing elements in the DOM). For multiple selectors, use comma separated values: e.g. a[rel='m_PageScroll2id'], a.class-name, li.menu-item a[href*='#']
.
Your links href value should contain #
with the id of the section you want to scroll-to and your document should contain sections with such id.
By default, the plugin scrolls the page vertically. If your page layout is horizontal (demo), set the layout
option parameter to horizontal
$("a[rel='m_PageScroll2id']").mPageScroll2id({ layout:"horizontal" });
To enable both vertical and horizontal scrolling (demo), set layout
to auto
$("a[rel='m_PageScroll2id']").mPageScroll2id({ layout:"auto" });
Page scroll to id provides a ready-to-use class for the highlighted links (links whose target element is considered to be within the viewport). The default highlight class is mPS2id-highlight
, which you can use in your CSS to style your highlighted links (more info). For example:
a.mPS2id-highlight{ background: #ff0; }
This sums up the basics of implementing Page scroll to id in your project. For help and detailed usage guides see Code examples & short tutorials and FAQ.
Configuration
Page scroll to id option parameters
Usage $(selector).mPageScroll2id({ option: value });
scrollSpeed: integer
- Sets the scroll animation speed in milliseconds (default:
1300
).
Example:
$(selector).mPageScroll2id({ scrollSpeed: 900 });
autoScrollSpeed: boolean
- Auto-adjusts animation speed according to target element position and window scroll (default:
true
).
Example:
$(selector).mPageScroll2id({ autoScrollSpeed: true });
scrollEasing: "string"
- Sets the animation easing type when page is idle (easings).
Example:
$(selector).mPageScroll2id({ scrollEasing: "easeInOutQuint" });
scrollingEasing: "string"
- Sets the animation easing type while page is animating (easings).
Example:
$(selector).mPageScroll2id({ scrollingEasing: "easeOutQuint" });
pageEndSmoothScroll: boolean
- Adjusts automatically the scroll-to position so when scrolling to a target element that sits at the bottom of the document, the animation stops smoothly at bottom of the page, instead of breaking at an earlier point (default:
true
).
Example:
$(selector).mPageScroll2id({ pageEndSmoothScroll: true });
layout: "string"
- Defines the page scrolling axis.
Value can be"vertical"
,"horizontal"
or"auto"
.
Example:
$(selector).mPageScroll2id({ layout: "vertical" });
offset: integer, "string", object, function
- Defines the amount of pixels to offset the scroll-to position.
The value can a be a positive/negative number, an element selector as string, a js/jquery object, a function or an array.
Code examples
highlightSelector: "string"
- The matching set of elements already handled by the plugin that will be highlighted (by default, all selectors are eligible for highlighting).
Code examples
clickedClass: "string"
- Sets the class name for the link that’s been clicked (default:
mPS2id-clicked
)
targetClass: "string"
- Sets the class name for the (current) target element (default:
mPS2id-target
).
highlightClass: "string"
- Sets the class name for the (current) highlighted link (default:
mPS2id-highlight
).
Code examples
forceSingleHighlight: boolean
- Allows only one highlighted element at a time (default:
false
).
Example:
$(selector).mPageScroll2id({ forceSingleHighlight: true });
keepHighlightUntilNext: boolean
- Keeps element highlighted until next so at least one element always stays highlighted (default:
false
)).
Example:
$(selector).mPageScroll2id({ keepHighlightUntilNext: true });
highlightByNextTarget: boolean
- Highlight elements according to their target and next target position (default:
false
).
Useful when targets have zero dimensions.
Example:
$(selector).mPageScroll2id({ highlightByNextTarget: true });
disablePluginBelow: boolean
- Disables plugin below [width,height] screen size: boolean, integer, array ([width,height]).
clickEvents: boolean
- Enable/disable click events for all selectors (default:
true
).
Example:
$(selector).mPageScroll2id({ clickEvents: false });
appendHash: boolean
- Append link’s href hash value to browser’s URL/address bar when clicked (default:
false
).
Example:
$(selector).mPageScroll2id({ appendHash: true });
onStart:function(){}
- User defined callback function, triggered when scrolling animation begins.
Code examples
onComplete:function(){}
- User defined callback function, triggered when scrolling animation is completed.
Code examples
liveSelector: "string"
- The matching set of elements that will be handled by the plugin even if they’re not present in the DOM (e.g. dynamic elements that will be added later on).
Example:
$(selector).mPageScroll2id({ liveSelector: "a.my-future-class" });
excludeSelectors: "string"
- The matching set of elements that will be excluded from the plugin (i.e. the plugin will not handle these elements).
Example:
$(selector).mPageScroll2id({ excludeSelectors: "a[href^='#tab-'], a[href^='#tabs-']" });
encodeLinks: boolean
- Encode links selector when their href/URL have encoded unicode characters, e.g. on internationalized domain names (default: false).
Example:
$(selector).mPageScroll2id({ encodeLinks: true });
inIframe: boolean
- Enable to run the script inside iframe.
Example:
$(selector).mPageScroll2id({ inIframe: true });
Plugin methods
scrollTo
Usage $.mPageScroll2id("scrollTo","#id");
Calling plugin’s scrollTo method will automatically scroll the page to the id specified in the second parameter.
Method option parameters
layout: "string"
- Defines the page scrolling axis.
Example:
$.mPageScroll2id("scrollTo","#id",{ layout:"auto" });
offset: integer
- Defines the amount of pixels to offset the scroll-to position.
Example:
$.mPageScroll2id("scrollTo","#id",{ offset:100 });
clicked: boolean
- The jQuery object to simulate the click event.
Example:
$.mPageScroll2id("scrollTo","#id",{ clicked:$(this) });
destroy
Usage $.mPageScroll2id("destroy");
Calling plugin’s destroy
method will completely remove Page scroll to id functionality from all links and targets, returning them to their original state. The method removes all plugin-specific classes, data objects and namespaced events.
Plugin dependencies & requirements
- jQuery version 1.7.0 or higher
License
This work is released under the MIT License.
You are free to use, study, improve and modify it wherever and however you like.
https://opensource.org/licenses/MIT
Donating helps greatly in developing and updating free software and running this blog 🙂
Hi,
it seems i get a conflict when i use customscrollbar together with scrolltoid
i mean, custom scrollbars work fine, but if i add scrolltoid, the anchors don’t work, just doesn’t happen anything
however, if i use only scrolltoid it works fine (without customscrollbars)
the same happens with the wp plugin
you can see it in action here
http://www.unioneimpreseitaliane.it/web/
(click on “prova” on the left)
how can i fix that?
thanks!
Hi,
Page scroll to id works only with browser’s native scrollbar.
Custom scrollbars plugin being a js/css scrollbar, has its own method (scrollTo) for scrolling (programmatically) to specific position. For info on how to use the method, see: http://manos.malihu.gr/jquery-custom-content-scroller/#methods-section.
Hi,
thanks for your reply
sorry for bothering you, but i can’t get it to work
in order to scroll the news box, i have this code:
<script> (function($){ $(window).load(function(){ //news box $("#rpwe_widget-2").mCustomScrollbar({ theme:"dark-thick" }); }); })(jQuery); </script>
and it works fine
also, the #main div scrolls horizontally as desired
now, i can’t get the menu anchors to work
i have this code:
<script> $(function(){ $(window).load(function(){ $("#main").mCustomScrollbar({ axis:"x", horizontalScroll:true, scrollInertia:1100, advanced:{ autoExpandHorizontalScroll:true }, /*, callbacks:{ onScroll:function() { alert("scrolled..."); } }, scrollButtons:{ enable:true }*/ }); /* Navigation */ $(".widget ul li a").click(function(){ var myid= $(this).attr("href"); $(".widget ul li a").removeClass('selected'); $(this).addClass('selected'); $("#main").mCustomScrollbar("scrollTo","" + myid + ""); }); }); })(jQuery); </script>
what am i doing wrong?
thanks!
Is there a way to make scroll with mouse wheel possible as well?
I’d be willing to make a donation for integration of this feature into the plug in.
Please let me know,
Thank you!
The plugin offers a way to trigger scrolling programmatically via the scrollTo method (see methods for more info).
This method, along with the jquery mousewheel plugin can be used to create custom scripts that’ll offer mouse-wheel functionality on specific web apps or pages, e.g.:
$(selector).on('mousewheel', function(event) { /* your condition logic here using event.deltaY/event.deltaX to set a scroll-to value... */ $.mPageScroll2id("scrollTo", scroll-to value); });
Scrolling through sections with mouse-wheel has no general scope (no default or standard functionality) and it’s used in very specific situations/layouts. For this reason it cannot be integrated in “Page scroll to id” plugin.
If you need assistance creating such custom script for a specific web page, I can help 🙂
I have attempted at contacting you via Facebook but got no reply. Is there a better way to contact you privately?
Oh sorry I must have missed your message. We’ll talk through e-mail.
everythink worked out fine until i installed the next plugin “Q2W3 Fixed Widget” http://www.q2w3.ru/q2w3-fixed-widget-wordpress-plugin/ which makes “pagescroll to id” don’t work anymore!
any ideas???
From what I can see on the Q2W3 Fixed Widget documentation, you probably need to disable “Refresh interval” (set to 0) in Fixed Widget Options.
i tried it, but it still jumps directly to the link no page scroll anymore…
I found the solution, i had to enable “Use jQuery(window).load() hook” in the fixed widget options. thanx for the great plugin
I have a couple of questions. Can I use the link with an image link? If so could you give me an example? I am thinking like an arrow.
Is there a way to configure so when someone scrolls with their mouse they move from link to link?
I also am having a hard time understanding what part of the link example I change
link) and a section with such an id exists in your page (e.g. target).
Example If I have 5 areas I scroll to do I add a number or something instead of the “id” noted above?
I am sure this plug in is what I am after, but a more basic user guide would really help.
Thanks in advance for any help you can give.
HI, great plugin, really love it!
I am just not sure how ti integrate the plugin into the navigation though.
I am using Ubermenu, and Pagelines DMS2 – i can also use the normal menu and not ubermenu.
I just need some pointers on how to integrate the “mPS2id-highlight” into the code.
Thank you.
mPS2id-highlight class is added by the plugin script automatically to menu link(s) when their targets are within the viewport when the page is being scrolled.
You can use .mPS2id-highlight directly in your theme’s CSS in order to apply a different style on the highlighted link(s).
More info in Code examples & short tutorials: Links highlighting.
I have kindly asked you via email some support, I have also asked you on this comment board. What I received is a ban! You can now delete this as well, but still I see no reason to why you denied me help. Good luck with your work.
Hey what ban?
I’ve already replied to your other comment here: http://manos.malihu.gr/page-scroll-to-id/comment-page-1/#comment-17960
I haven’t received any “spam” comments from you so I don’t know what you mean by “ban”? Please let me know as maybe my spam protection refused your comment if for instance was posted really fast (this happens automatically).
Please consider that I’m not denying help to anyone. Most days I get more support requests than I can handle (many plugins, galleries, scripts, here, on github, on WP forums etc.) on top of doing other work in order to make a living…
Hello,
first of all thanks for your great work – i love this plugin!
One Question: have you ever did something like a “stop scrolling” function for touch/swipe and mousewheel scrolling? So that if the user scrolls down (or up), the scrolling stops on the next section in the given direction? Or do you have planned something like that for a future version?
I have seen your answer concerning the keydown/up question in comment <a href="#comment-17480". Like this way, i can do something similar with some existing jQuery plugins for touch/swipe and mousewheel events, but i would prefer a slim and fast solution instead of using different plugins.
Any hint would be appreciated! Thanks!
It would be awesome. Any chance of this feature in any future release? Thanks!
These functions aren’t really inside plugin’s scope. In either case you will need additional plugins (e.g. jquery-mousewheel plugin). Page-scroll-to-id provides the necessary methods for triggering scroll-to events externally.
The pages that restrict mouse-wheel/touch scrolling are too specific on markup and events and it wouldn’t make much sense to code such functionality in the script.
I’ll try to write some tutorial(s) and/or include examples with the mousewheel plugin in the archive.
Great plugin. Thanks for making it free.
When I scroll down manually the highlight will change when the next section gets into the viewport like it’s supposed to. The problem is when a section does not fill the entire viewport the highlight changes before I want it to. How could I make the highlight wait to change until the next section is more like 75% up in the viewport?
Hi,
You can use the additional plugin highlight classes, useful when multiple short-height sections come into view. These classes are:
.mPS2id-highlight-first
.mPS2id-highlight-last
In your case, you may need to use .mPS2id-highlight-first instead of .mPS2id-highlight which is added in every link that’s connected to a section within the viewport.
As an example, if you have 3 sections all into view, the html of your links will be like:
<a class="mPS2id-highlight mPS2id-highlight-first">...</a> <a class="mPS2id-highlight">...</a> <a class="mPS2id-highlight mPS2id-highlight-last">...</a>
Hello Malihu,
Great job, congrats!
I want to ask 2 things:
1. how to use together two of your scripts 1) page scroll to id & 2) Custom Scrollbar (full page).
When i use them as single plugin works fine, but when i put them together the page “scroll to id” does not work and the scrollbar(full page) works fine.
and the 2nd
2. how, in “page scroll to id”, can i target with one or two links of a menu to show the id element at the bottom of the screen instead show at the top. I tried offset option but in a different resolution doesn’t show in the right position.
thanks for your help in advance
The two plugin’s are not compatible as Page scroll to id works with browser’s native scrollbar. Custom scrollbar plugin has its own set of methods/events, one of them being the scrollTo method which you can trigger in a script like this:
$(selector).mCustomScrollbar("scrollTo","#id")
You can set the offset value based on an element selector (e.g. a menu) instead of a fixed number of pixels (this is handy when your menu is responsive). Is this what you need?
Hello malihu,
thanks for your answer.
About the 2 question/answer, i already use element selector, let me rephraze my question.
i have my link targeting to an id and when i click my link it takes(scroll) me to the id section and naturally it goes at the top of my browser at the beginning of the div id. I want when i click my link to scroll to the specific id but at the bottom of the screen in my browser.
Γεια χαρά Μάνο,
σου γράφω και στα ελληνικά τι θέλω να επειδή τα αγγλικά μου δεν είναι και τόσο καλά :).
Θέλω όταν πατάω πάνω σ’ ένα από τα link του μενού όταν σκρολάρει στο συγκεκριμένο id αντί να με πηγαίνει στην κορυφή της οθόνης μου (στο browser) θα ήθελα να πηγαίνει στο κάτω μέρος.
Ευχαριστώ και πάλι,
Γεια σου Chris! Τα αγγλικά σου είναι super 🙂
The plugin allows you to set the offset value as an anonymous function. This would work if your sections have a fixed height (e.g. 200 pixels). For example:
$(selector).mPageScroll2id({ offset: function(){ return $(window).height()-200 } });
I can’t really see another way of doing what you describe or even if this solution does help with your page layout…
Let me know if this helps
This is a great plugin, thanks for that.
As i developed it on a static page it worked like a charm but now in the production environment, the plugin won’t highlight the current menu-item.
What could be the problem? How to the sections are related together (do the navi need the same “href=#section1″ as the section id=”section1”, which I have already!)?
thanks and best regards, Michael
Hi.
I have the same problem.
I noticed that script don’t add class “mPS2id-highlight” to anchor when element is inside List element with current-menu-item class.
Any ideas how to fix this issue?
Thanks,
Tom
On ebookstory.pl, your link “Co robimy” href attribute has a slash (/) before the hash (#). Remove the slash and it’ll work.
Change:
href="/#corobimy"
to:
href="#corobimy"
Thank you for reply.
Yes. I know, that if I remove slash befores hash it will be working. But I have page “projects”: http://ebookstory.pl/projekty/ and if you go to “projekty” the menu don’t work, because menu items (except “Co robimy”) has no slash. If menu item has no slash wordpress wont to go to i.e. ebookstory.pl/projekty/#kontakt instead ebookstory.pl/#kontakt
Can you help me?
Sorry for my english.
Thanks,
Tom
If you need the link to work from everywhere put the absolute URL, e.g.
http://ebookstory.pl/#corobimy
Hi Malihu.
Can you answer on my question, please?
Maybe on private e-mail address if you don’t want write here?
When I have href without slash everythink working on homepage, witch is my one-page-layout page.
But if I have another page, like mywebsite.com/another-page and menu items are without slash, menu on this page doesn’t work (it works but reffer to the same page, not to parrent page).
Thansk,
Tom
Ok. Everythings work 🙂
It is different between href: /#corobimy and http://ebookstory.pl/#corobimy.
Thank you for help.
Good job 🙂
Tom
I use to have a site http://www.agendadelvolo.info which had many problems the way I implemented it, then I found your script thus I’m rebuilding the old site. You can see the new one under construction on http://agendadelvolo.info/rebuilt_2/examples/demo-horizontal-layout.html.
I have two questions, though:
1) I need to replicate the old menu on the left. In your demo the menu is on the top and if I resize the window it moves nicely on the left. I just need to have a fixed menu on the left but I have played with CSS to no avail.
2) Offsetting the content section works for all the sections but not for the first one. I have tried specific offset for the “section1” link, but nothing. Solution?
3) I need to fix the in a centered position but it seems stuck to the section1.
I’d really appreciate your aid. Criss
too silly a question to be answered ?
Not really. Just too much requests to handle 🙂
To have the fixed menu always on the left you need to remove from the CSS the media query at the bottom:
@media only screen and (min-width: 1140px){ ... }
This will probably fix the offset issues as well.
Let me know if this helps
I have cut the @media queries and the menu sticks on the left, but the main title desappears. How can I still keep the title, making it fixed at the center?
The specific offset still don’t work.
🙂
To make your header fixed you should add these CSS properties to it:
position: fixed; z-index: 2;
and also remove width:10% from .horizontal-layout header > *
To have the text centered you’ll need to add to your header properties:
width: 100%; text-align: center;
Hey it doesnt work for me.
I created a custom menus an enabled the “Link Relationship (XFN)” and put in “m_PageScroll2id” like in the description. Put in the Link “#title1”
On the Page I put in target
It jumps when i click but it not marks when i scroll down.
What to I do wrong?
target
“target”
without the “
div id=”title1″>target</div
sry
<div id="title1">target</div>
Check if your links and targets are modified by another plugin or script.
You might also check if your entire content resides in an overflowed div instead of the body tag. If you could send me a link I’d be able to provide more help.
Here is my site:
http://www.artur-kosch.de/test/
The menu is at the sidebar!
Your targets don’t have the id attribute and are in the form of:
<a name="title3"></a>
The plugin requires an id (not name) attribute in order to work, e.g.:
<a id="title3"></a>
I changed, still doesn’t work. 🙁
You links and/or targets seems to be generated/modified by some other theme script(s). Probably some js script inside dt-presscore theme dir creates/modifies your sidebar menu after ‘Page scroll to id’ plugin is initialized. I don’t know if you can find/edit the script responsible, but if you do, you could add the following jquery code after the menu is ready:
$.mPageScroll2id();
Hi, is it possible to have plugin working with body, html{height:100%} ?
I can’t get it to work, I tried all sorts of overflows, but no luck :((
Thanks,
Mirko
Not really. The plugin works and animates only the root page element (html or body) and not other overflowed elements (such as divs).
Ok, thanks for the explanation!
First of all, Thanks Malihu!
I’m just a newbie but I have a question which is probably very basic:
I’m using buttons to scroll to different parts of the page and it works great but if I use “Button A” to scroll from point “A” to point “B” and then I use the scroll bar to go back to “Button A” and click it, it won’t scroll.
However, if I click on “Button B” to move from point “B” to point “C” and then use the scroll bar to move to back “Button A” and click it, it will scroll. Seems I can’t get it to work two times in a row (the same thing happens to all buttons). Any ideas?
Thanks in advance
Can’t really say. If you send me link with your implementation I’d be able to help.
Giving it for free is honorable but if I could understand your instructions, I’d be already qualified to have written it myself. I’m not a novice either.
1. Insert a link at the top of your page:
<a href="#id" rel="m_PageScroll2id">link</a>
2. Further down in your page, insert a div:
<div id="id">target</div>
3. Include jQuery in your head tag:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
4. Include plugin js file in your head tag:
<script src="jquery.malihu.PageScroll2id.min.js"></script>
5. Call plugin function on your link:
<script> (function($){ $(window).load(function(){ $("a[rel='m_PageScroll2id']").mPageScroll2id(); }); })(jQuery); </script>
Great work – Good job – Simple simple
Hi, Malihu thanks for the plugin. I have been working on WordPress sites for about 7 years and now I couldn’t figure out how to do this. Is it only me? I tried to check if there is any video on youtube and there isn’t any.
This type of instruction would be helpful to me and people like me. Something like this”
– First you should do this and that as a precondition (for eg adding the code m_PageScroll2id into the menu which I read it in WP faq )
– To do this go to this place and do this and that (by giving example etc)
In general I would have been glad if there was a step by step guide even a video walkthrough of the set up.
* I installed the plugin 3 days ago but couldn’t do a thing. If you can post a step by step video in youtube I would appreciate it. Thanks.
Hey,
I am quite new to wordpress and I would really love to use your js. When i used it as plugin it only worked for me when i was commenting all the code I had in my function.php file. That was:
// Add RSS links to <head> section automatic_feed_links(); // Load jQuery if ( !is_admin() ) { wp_deregister_script('jquery'); wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"), false); wp_enqueue_script('jquery'); } // Clean up the <head> function removeHeadLinks() { remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); } add_action('init', 'removeHeadLinks'); remove_action('wp_head', 'wp_generator'); if (function_exists('register_sidebar')) { register_sidebar(array( 'name' => 'Sidebar Widgets', 'id' => 'sidebar-widgets', 'description' => 'These are widgets for the sidebar.', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h2>', 'after_title' => '</h2>' )); }
Also I would like to enqueue all the js in my function.php file and therefore I uninstalled your plugin again and used the following code to enqueue all the scripts by hand:
//Add my custom JS scripts: function load_scripts() { if ( is_page('HOME')) { wp_register_script( 'scroller', get_template_directory_uri() . '/js/jquery.malihu.PageScroll2id.js'); wp_enqueue_script( 'scroller' ); wp_register_script( 'my_jquery', get_template_directory_uri() . '/js/jquery.js'); wp_enqueue_script( 'my_jquery' ); } } add_action('wp_enqueue_scripts', 'load_scripts');
In my_jquery i wrote the code to activate the “plugin”:
(function($){ $(window).load(function(){ $("a[rel='m_PageScroll2id']").mPageScroll2id(); }); })(jQuery);
Now when I click the links on my homepage its just jumping to the correct position without a smooth effect. Can you help me and tell me what’s wrong with my code?
Ah, one remark: when i analyse my homepage the js seem to be implementet in the correct way…
Thanks a lot,
Stefan
Hello,
The plugin requires jQuery version 1.6 or later. The part in your functions.php that prevented it is this:
wp_deregister_script('jquery'); wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"), false); wp_enqueue_script('jquery');
as you’re loading jQuery 1.4.1 from Google CDN.
In your second attempt of adding the plugin manually, you need to load jQuery before jquery.malihu.PageScroll2id.js.
In
wp_register_script
function, the third parameter is dependencies ($deps), which is an array of the handles of all the registered scripts that this script depends on, that is the scripts that must be loaded before this script. So you could do it like this:wp_register_script( 'scroller', get_template_directory_uri() . '/js/jquery.malihu.PageScroll2id.js', array('jquery'));
Thank you so much! Works perfectly! Great work!
great work thanks you saved my job
Hi I am trying to implement this on my clients website (sorry its not available for viewing) and I am not able to get the main menu to scroll or anything for that matter. Is it possible it is a conflict?
Hi
Great script, I want to use it on this page: https://texelsontwerp.nl/stappenplan…
I integrated it with Joomla, which seems to work pretty well. I only have one question: I can’t go back the last step because the #id is not set in the address like here: http://manos.malihu.gr/repository/page-scroll-to-id/demo/demo-jqaddress.html
If I change the code, the smooth scrolling is gone, but I’d like to have both options as you can understand ;-).
Is there a solution for this?
Regards, Carst
No one a solution for this?
Hi! how to use css indent on top of the anchor links?
I tried this:
.mPS2id-clicked {
padding-top: 70px;
}
did not work (
I tried to add a slideshow within a section, but no luck. When it is in a div, the scrolling effect seemed to be affected. Any luck out there to include any other jquery effect in the scrolltoID? Furthermore, I am looking for an example showing parallax effect with different divs moving in different speeds both horizontally and vertically.
I just tried installing this plugin and it gave me a server error (500). Any idea what’s going on? I’m using pagelines DMS (2) on the latest WordPress. Custom sidebars and ninja forms are the only other activated plugins.
Hello Malihu,
Would it be possible to trigger the url to change (on the fly) while scrolling?
Somewhat like the menu (active state) does change while scrolling?
Thanks, Murk
You’d need to write extra code to do that but in my opinion it can be counter-productive without offering anything significant to the user.
Among others, you would need to prevent the browser from keeping history while scrolling (but not when clicking links) because otherwise, you’d need to hit browser’s “Back” button like 50 times to actually go back.
To answer the question, yes it is possible but it would require a more or less complicated script to make it work right while the result could still be questionable.
Hi Malihu,
That sounds like good reasons not to want this functionality.
Thanks for your clear and comprehensive answer!
Best regards, Murk
Hello Malihu,
Your plugin functions really nice!
I’m using it in WordPress now, and I have one problem, perhaps you can help me on this.
I would like to use the hashchange funtion, so copied the code from your demo file to my template.
The page does scroll nicely, but the URL does not change.
<script src="js/jquery-1.10.2.min.js"></script> <script src="js/jquery.hashchange.min.js"></script> <script src="jquery.malihu.PageScroll2id.js"></script> <script> (function($){ $(window).load(function(){ $("#navigation-menu a,a[href='#top'],a[rel='m_PageScroll2id']").mPageScroll2id({ highlightSelector:"#navigation-menu a" }); $(window).hashchange(function(){ var loc=window.location, to=loc.hash.split("/")[1] || "#top"; $.mPageScroll2id("scrollTo",to,{ clicked:$("a[href='"+loc+"'],a[href='"+loc.hash+"']") }); }); }); })(jQuery); </script>
The hashchange function does work when I leave this part out:
$("#navigation-menu a,a[href='#top'],a[rel='m_PageScroll2id']").mPageScroll2id({ highlightSelector:"#navigation-menu a" });
But than there is no scrolling.
I hope you can help me, thanks in advance for your reply.
Hello,
So, you implemented the plugin manually (meaning there’s no Page scroll to id plugin in your Plugins page), correct?
If yes, you’ll need to add
a[rel='m_PageScroll2id']
to your links manually.Also, you need to change “#navigation-menu a” to the selector matching your navigation menu links (e.g. “menu-item a”).
It probably doesn’t work because your links href value should be in the form of
#/id
(notice the slash after the hash) which is the format of the haschange plugin.Hi Malihu,
Thank you very much for your quick response.
The slash after the # does the trick!
This makes my day (and many more days to come…).
Best regards, Murk
Hi!
So, I decided to use your plugin to navigate on my one-page site, and when it comes to the scrolling and navigation it works like a charm! Thank you for that.
But I’m facing problems with the highlighting. I think that my theme dosen’t allow the plugin to control the highlighting or something. I added:
.menu-item a.mPS2id-highlight{ color: #2ea3f2 !important; }
To the CSS, and still no difference… My current theme is highlighting all the links connected to an anchor on that page, and I don’t know if I have set everything up correctly. I have left all the default settings in the plugin too.
Would you mind taking a look for me?
Thanks in advance,
Timothy
Sure send me a link.
As a note, if you have many types of links handled by the plugin (e.g. primary navigation links, back-to-top link, next/previous links etc.), you might need to set the ‘Highlight selector(s)’ to the selector you need highlighted (e.g.
menu-item a
).This is the page I’m trying to set it up on:
http://www.wordpress.bmvstudio.se/cinema-4d/
I’m sorry, I’m a real newbie when it comes to coding, so please bear with me hehe…
I can see only one blue link when I scroll the page, isn’t this correct?
This plugin is genius! Thank you for it!
One question: I was successful in using the css you provided to get the active item to have a colored background. Here’s what Iused:
.menu-item a.mPS2id-highlight{ background: #2ea3f2; }
Instead of this, I’d like the active menu item to be BOLD and in a specific color. How would I revise the CSS to make this work?
Thanks again for an excellent solution.
T.
Like this:
.menu-item a.mPS2id-highlight{ font-weight: bold; color: #2ea3f2; }
Thanks very much for your fast response. On my site, the bolding works, but the highlight color doesn’t. Is there something I’m missing?
There’s probably another more-specific CSS rule that overwrites
.menu-item a.mPS2id-highlight
.A quick solution is to add
!important
in your rule:.menu-item a.mPS2id-highlight{ font-weight: bold; color: #2ea3f2 !important; }
That did the trick. Thank you!
Hi guys. Love the plugin. Is there a way to mane the me u items do the same thing? I can’t figure it out :/
Hi, what do you mean by “doing the same thing”?
basically how do I get the scroll down affect using the menu items through wordpress
nevermind. I figure it out. You go to Apperence>Menus
Add a new Link menu item and leave the URL box empty, then paste this on to the name box:
VIEW PORTFOLIO
or whichever id and name you want. Thanks guys!!
Also, please check “How to use the plugin with WordPress custom/native menus?” in plugin’s FAQ:
http://manos.malihu.gr/page-scroll-to-id/3/
and
http://wordpress.org/plugins/page-scroll-to-id/faq/
While on WP ‘Menus’ admin page, you need to click ‘Screen Options’ and check ‘Link Relationship (XFN)’. Click the arrow on the right of any menu item and insert
m_PageScroll2id
in the ‘Link Relationship (XFN)’ field. This will add therel="m_PageScroll2id"
to your link(s) which is plugin’s default selector.oh!!!! even better! Thanks so much. You guys rock!
Please, help me out with this one: How can I get all pages content on the main page so I can see the scroll down effect?
I’ve did all settings but what I see on the main page is just the content of the main page not the others 🙁
Thanks!
Hello,
The plugin does not manipulate your content, page layout or theme. It’s scope is to “connect” link and destination targets elements in the page.