Support » Plugin: Page scroll to id » Full page scrolling with mousewheel.

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

    (@malihu)

    You’d need to use an additional plugin like jquery-mousewheel (https://github.com/brandonaaron/jquery-mousewheel). Include it in your theme manually like this:

    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.11/jquery.mousewheel.min.js"></script>

    Then, you should insert a script like the following in your theme’s header or footer:

    <script>
    (function($){
    $(window).load(function(){
    
    /* bind mousewheel event on document */
    $(document).mousewheel(function(e){
        e.preventDefault();
        var section=$("#content > section"), /* define your sections selector (change to your selector) */
            currentTarget=$(".mPS2id-target"), /* define the current section */
        /*
        if mouse-wheel delta is less than zero scroll-to next section from current
        if mouse-wheel delta is greater than zero scroll-to previous section from current
        */
        to=e.deltaY<0 ? currentTarget.next().attr("id") : currentTarget.prev().attr("id");
        /* if variable to is defined, use plugin's scrollTo method to programmatically scroll to target */
        if(to){
            $.mPageScroll2id("scrollTo",to);
        }
    });
    
    });
    })(jQuery);
    </script>

    Can’t really provide a more specific code or details, as it depends on your theme and content structure.

    Hello, the plug-in works great.

    But I have a small question. How can I turn off script on different pages per site ID

    FirebatHero

    (@firebathero)

    Hey jaja, to assign scripts to different pages you can use the
    CSS & Javascript Toolbox plugin.

    MWCreative

    (@mwcreative)

    Jaja,

    you could also use a hook within your functions file (or wherever you pasted the code in a php file) to restrict the output of your script. Say you have your script in your main theme folder – called ‘myscript.js’.

    The proper way to include scripts within WordPress is with the ‘wp_enqueue_scripts’ action hook. There are some examples in your functions.php file within your theme. Here’s a quick way to restrict output using the wp_enqueue_scripts and get_current_blog_id() functions.


    <?php
    function enqueue_my_custom_scripts() {
    wp_register_script('my-script', '/wp-content/themes/mytheme/myscript.js');
    $blog_id = get_current_blog_id();
    if($blog_id == '2') {
    wp_enqueue_script('my-script');
    }

    }
    add_action('wp_enqueue_scripts', 'enqueue_my_custom_scripts');
    ?>

    Adding this code, altered to fit your Javascript code file, you should be able to effectively load the scripts only on the blog specified by the get_current_blog_id() check.

    There are also a ton of other conditionals available for WP_Query(), which will check where you are in the site and allow you to output specific code for each condition.

    Plugins are great, but if you choose one that doesn’t get updated regularly enough, you could be in for some security issues – which is why I like coding things out by hand. 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Full page scrolling with mousewheel.’ is closed to new replies.