PHP code example of coderius / yii2-smooth-scroll

1. Go to this page and download the library: Download coderius/yii2-smooth-scroll library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

coderius / yii2-smooth-scroll example snippets


 echo coderius\smoothScroll\SmoothScroll::widget([]); 

 
    echo coderius\smoothScroll\SmoothScroll::widget([
        // 'selector' => false,
        'clientOptions' => [
            'speed' => '1500',
            'speedAsDuration' => true,
            'easing' => 'easeInQuint',
            'customEasing' => new \yii\web\JsExpression(
                'function (time) {
                    return time < 0.5 ? 2 * time * time : -1 + (4 - 2 * time) * time;
                }'
            ),
            'clip' => true,
            // History
            'updateURL' => true, // Update the URL on scroll
	        'popstate' => true, // Animate scrolling with the forward/backward browser buttons (n (event) {

                // The event type
                console.log('type:', event.type);
            
                // The anchor element being scrolled to
                console.log('anchor:', event.detail.anchor);
            
                // The anchor link that triggered the scroll
                console.log('toggle:', event.detail.toggle);
            
            };";

            return $script;
        },
        'endClientJs' => function($self){
            $script = "console.log(" . $self->getScrollVarName() . ")";

            return $script;
        },
        
        /**
        * This script will be generated if you specify the elements of the array 
        * as in the example below.
        *
        * document.addEventListener('scrollStart', logScrollEvent, false);
        * document.addEventListener('scrollStop', logScrollEvent, false);
        * document.addEventListener('scrollCancel', logScrollEvent, false);
        **/
        'clientEvents' => [
            'scrollStart' => ['logScrollEvent', false],
            'scrollStop' => ['logScrollEvent', false],
            'scrollCancel' => ['logScrollEvent', false],
        ],
    ]); 

php composer.phar