Viewing 15 replies - 1 through 15 (of 17 total)
  • Thread Starter blindtexth

    (@blindtexth)

    I guess this question can not be answered from the plug in side?

    Anybody a hint?

    Plugin Author malihu

    (@malihu)

    Hello,

    If you can add custom javascript in your template/theme you can do it.
    Give me few hours and I’ll post here a sample (but working) code ??

    Thread Starter blindtexth

    (@blindtexth)

    Hi, yes, I can add custom javascript.
    If you can post a sample – it would be great and highly appreciated! 8o)

    Plugin Author malihu

    (@malihu)

    The script below should scroll between sections using the mouse-wheel and up/down keyboard arrows.
    The script assumes that:

    • You have a main menu with links that point to each section and ‘Page scroll to id’ is enabled on them.
    • Each section height is the same as viewport height.

    Please note that these types of scripts depend greatly on the page layout. The code below uses a special ‘Page scroll to id’ class (_mPS2id-h) in order to work independently from most layouts. This class is related to plugin’s highlight feature, meaning that it should work in most cases.

    I’ve added few comments in the code so you can tell what’s happening.

    <script>
    	(function($){
    		$(window).load(function(){
    			/* mousewheel/keyboard section scrolling */
    			$(document)
    				//custom event
    				.on("scrollSection",function(e,dlt){
    					//sel variable is elements selector
    					//change to a more specific selector if needed (e.g. ".menu-item ._mPS2id-h")
    					var sel=$("._mPS2id-h");
    					if(!$("html,body").is(":animated")){ //scroll one section at a time
    						//set current element index (change to a more specific selector if needed)
    						var i=sel.index($(".mPS2id-highlight-first"));
    						//check first and last elements to prevent scrolling and scroll to next/previous sections
    						if(!(i===0 && dlt>0) && !(i===sel.length-1 && dlt<0)) sel.eq(i-dlt).trigger("click");
    					}
    				})
    				//mousewheel event
    				.on("mousewheel DOMMouseScroll",function(e){
    					e.preventDefault();
    					//send normalized mousewheel delta (-1/1) to scrollSection
    					$(this).trigger("scrollSection",((e.originalEvent.detail<0 || e.originalEvent.wheelDelta>0) ? 1 : -1));
    				})
    				//keyboard arrows event
    				.on("keydown",function(e){
    					var code=e.keyCode ? e.keyCode : e.which;
    					if(code===38 || code===40){ //up, down
    						e.preventDefault();
    						$(this).trigger("scrollSection",(code===38 ? 1 : -1));
    					}
    				});
    		});
    	})(jQuery);
    </script>

    This script could be placed in footer.php after wp_footer(); function or wherever your theme allows you to add custom javascript.

    Thread Starter blindtexth

    (@blindtexth)

    Hi, thank you very much!

    With Genesis/Dynamik the script is placed just above the closing </body> tag.

    Unfortunately the page jumps to only two locations (with scrolling and with arrow keys in opposite direction).
    – The main menu links point to each section and have the XFN to ?m_PageScroll2id?.
    – Each section hight is set to view port hight. (Done with beaverbuilder)

    Have a look: https://www.siel-apotheke.de/SLA
    You have a brief idea, why this is happening?

    I am very happy to put a donation …

    Carsten

    Plugin Author malihu

    (@malihu)

    Thanks for posting your link (otherwise it would be difficult to know what happens).

    It seems your menu links have additional js click events by some other script(s), so we need to trigger only the click event registered by ‘Page scroll to id’.
    In the script I posted, try changing:

    .trigger("click");

    to:

    .trigger("click.mPS2id");

    I’ve namespaced ‘Page scroll to id’ events (mPS2id) for these kind of situations so it should just work.

    Let me know

    Thread Starter blindtexth

    (@blindtexth)

    Thank you for the add on … unfortunately it did not change it.

    But I figured out, that it works only when you are at the bottom section.

    By choosing ?Kontakt? at the top navigation, when you are down there the scroll or arrow keys work as they should.

    hm …

    Plugin Author malihu

    (@malihu)

    No worries. I just saw that you’ve enabled ‘Force single highlight’ option in plugin settings. Disable (uncheck) it, as this option prevents mPS2id-highlight-first class from being added to your links. This class is required in the custom script above in order to get the current section without “guessing” page layout/markup.

    Thread Starter blindtexth

    (@blindtexth)

    Wow! That just did it!

    I disabled the ?force single highlight? option.
    It works like charm … thank you very much!

    Carsten

    Thread Starter blindtexth

    (@blindtexth)

    ah, yes … the topic is resolved (and marked).

    Plugin Author malihu

    (@malihu)

    Great ??
    Going to make this post sticky as other people have similar questions.

    Plugin Author malihu

    (@malihu)

    In case anyone interested or requires similar functionality, I’ve extended the code, removed the dependence on ‘Force single highlight’ option, added examples, demo etc. here:

    https://manos.malihu.gr/page-scroll-to-id-with-mousewheel-and-keyboard/

    siddy24

    (@siddy24)

    Hi,
    I also have the Same Requirement actually, I Don’t need On Click Scroll to id. In Just a Front page I Want Using Mouse Wheel only Home Page Section Should get Cover. I tried The Above solution and Put The Script in the Footer by using the plugin header and Footer Script. but instead of working mouse Wheel Stop the Working. Can You help me in that

    My Url of the website is https://www.merakifilms.in

    • This reply was modified 8 years ago by siddy24.
    Plugin Author malihu

    (@malihu)

    siddy24

    (@siddy24)

    Hey Sorry You Can Check it now i just Removed maintenance Mode

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Scroll with mouse to ID possible?’ is closed to new replies.