Full Code of ameesme/SlimScroller.js for AI

master 1362f512e432 cached
8 files
15.4 KB
3.9k tokens
1 requests
Download .txt
Repository: ameesme/SlimScroller.js
Branch: master
Commit: 1362f512e432
Files: 8
Total size: 15.4 KB

Directory structure:
gitextract_mp77rv2z/

├── LICENSE
├── README.md
├── demo.html
├── dist/
│   └── init.js
├── install.json
├── package.json
└── src/
    ├── slimScroller.full.js
    └── slimScroller.js

================================================
FILE CONTENTS
================================================

================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2015 Mees Boeijen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



================================================
FILE: README.md
================================================
# slimScroller.js
![](http://forthebadge.com/images/badges/built-with-love.svg)

Smoothly scroll to positions on your website, under 350 bytes, no dependencies.

## Two versions
### [SlimScroller Base](https://github.com/ameesme/SlimScroller.js/blob/master/dist/slimScroller.min.js)
    343 bytes gzipped
    580 bytes uncompressed

The base version includes support for one type of scroll-target:
- CSS selector ( eg. `slimScroller.scroll("p:first-of-type")` )

### [SlimScroller Full](https://github.com/ameesme/SlimScroller.js/blob/master/dist/slimScroller.full.min.js)
    570  bytes gzipped
    1030 bytes uncompressed
The full version includes support for three types of scroll-targets:
- Position in pixels ( eg. `slimScroller.scroll(200)` )
- CSS selector ( eg. `slimScroller.scroll("p:first-of-type")` )
- Direct JavaScript HTML-element ( eg. `slimScroller.scroll(document.querySelector(p#hi))` )

### Hasthags
Want to bind SlimScroller to all anchor-tags on a page? Run `slimScroller.bind()` when the dom finishes loading. Only supported on [SlimScroller Full](https://github.com/ameesme/SlimScroller.js/blob/master/dist/slimScroller.full.min.js).

## How to use
Just use the `slimScroller.scroll`-function with the following parameters.
- `Required` Scroll-target (according to SlimScroller-version)
- `Optional` Scroll-duration (`ms`)
- `Optional` Horizontal-scrolling instead of vertical (`boolean`)
- `Optional` Callback-function with final scroll-position as parameter

### NPM
Run `npm install slimscroller`.

### Hosted
#### Base
```<script src="https://amees.me/files/public/SlimScroller.js/dist/slimScroller.min.js"></script>```

#### Full
```<script src="https://amees.me/files/public/SlimScroller.js/dist/slimScroller.full.min.js"></script>```

## Demo
[View here](https://amees.me/files/public/SlimScroller.js/demo.html).

## NPM
Run `npm install slimscroller`.

##License (MIT)
Copyright © 2016 Mees Boeijen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


================================================
FILE: demo.html
================================================
<html>
	<head>
		<title>slimScroller.js Demo</title>
		<!-- These styles are not required for the actual plugin. Just for the demo. -->
		<style>
			body{
				padding: 0;
				margin: 0;
			}
			p{
				font-family: sans-serif;
				line-height: 25px;
			}
		</style>
	</head>
	<body>
		<button onclick='slimScroller.scroll(300)'>Scroll to 300px</button>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<a href='#testPar'>Scroll to a paragraph via an anchor-tag.</a>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<button onclick='slimScroller.scroll("p:last-of-type")'>Scroll to last paragraph selector</button>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p id='testPar'>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>
		<button onclick='slimScroller.scroll(document.querySelector("button:first-of-type"))'>Scroll to first button JS-element</button>

		<script src='src/slimScroller.full.js'></script>
		<script>
			window.addEventListener('load', function (){
				return slimScroller.bind(false, function (position){
					console.log('The current position is '+position);
				});
			});
		</script>
	</body>
</html>

================================================
FILE: dist/init.js
================================================
// This script is only used for installation via Eager.
document.addEventListener("DOMContentLoaded", function(event) { 
	slimScroller.bind();
});

================================================
FILE: install.json
================================================
{
	"resources": {
		"body": [
			{
				"type": "script",
				"src": "dist/slimScroller.min.js"
			},
			{
				"type": "script",
				"src": "dist/init.js"
			}
		]
	}
}

================================================
FILE: package.json
================================================
{
  "name": "slimscroller",
  "version": "2.0.4",
  "description": "Slim smooth-scrolling under 350 bytes (gzipped), with no other dependencies.",
  "main": "dist/slimScroller.full.min.js",
  "author": "Mees Boeijen <mees@amees.me> (https://amees.me)",
  "license": "MIT",
  "homepage": "https://github.com/ameesme/SlimScroller.js",
  "repository": "https://github.com/ameesme/SlimScroller.js",
  "keywords": ["tiny", "smooth scroll", "no dependencies"]
}


================================================
FILE: src/slimScroller.full.js
================================================
var slimScroller = function (){
    'use strict';

    var elapsed, horizontal;
    var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;

    var scroll = function (target, horizontal, durationTime, callbackFunction, scrollTarget) {
        var scrollTargetReference = (scrollTarget && scrollTarget instanceof Element) || window;
        var duration = durationTime || 500;
        var horizontal = horizontal || false;
        var callback = callbackFunction || false;
        var startPosition = (horizontal) ? window.pageXOffset : window.pageYOffset;
        var total = (horizontal) ? pageXOffset.scrollWidth : pageXOffset.scrollHeight;
        var targetPosition = (parsePosition(target) > total) ? total : parsePosition(target);

        var clock = Date.now();
        step(duration, horizontal, callback, startPosition, total, targetPosition, scrollTarget, clock)();
    };
    var easeInOutCubic = function (time) {
        return (time < 0.5) ? 4 * time * time * time : (time - 1) * (2 * time - 2) * (2 * time - 2) + 1;
    };
    var calculatePosition = function (elapsed, duration, targetPosition, startPosition) {
        return (elapsed > duration) ? targetPosition : startPosition + (targetPosition - startPosition) * easeInOutCubic(elapsed / duration);
    };
    var parsePosition = function (target){
        var parseNumber = parseInt(target);
        var parseElement = target.offsetLeft;
        var parseSelector;
        try{
            parseSelector = document.querySelector(target);
        }catch(e){}

        if (parseNumber) {
            // Target is pixel value
            return parseNumber;
        }else if(parseSelector){
            // Target is CSS-selector
            return (horizontal) ? document.querySelector(target).offsetLeft : document.querySelector(target).offsetTop;
        }else if(parseElement !== undefined){
            // Target is HTML-element
            return (horizontal) ? parseElement : target.offsetTop;
        }else{
            // Unknown type
            throw new Error('Unknown type as target');
        }
    };
    var step = function (duration, horizontal, callback, startPosition, total, targetPosition, scrollTarget, clock) {
        return function() {
            elapsed = Date.now() - clock;
            var stepPosition = calculatePosition(elapsed, duration, targetPosition, startPosition);
            var scrollTargetReference = (scrollTarget && scrollTarget instanceof Element) || window;
    
            if (horizontal){
                scrollTargetReference.scroll(stepPosition, 0);
            }else{
                scrollTargetReference.scroll(0, stepPosition);
            }
            if (elapsed > duration) {
                if (callback) {
                    callback([window.scrollX,window.scrollY]);
                }
            } else {
                requestAnimationFrame(step(duration, horizontal, callback, startPosition, total, targetPosition, scrollTarget, clock));
            }
        }
    };
    var bind = function (time, callbackFunction) {
        var allAnchors = document.querySelectorAll('a');
        var i;
        for (i = 0; i < allAnchors.length; i++) {
            if (allAnchors[i].href == window.location.href.split('#')[0] + '#' + allAnchors[i].href.split('#')[1]) {
                allAnchors[i].addEventListener('click', function (event) {
                    event.preventDefault();
                    slimScroller.scroll('#'+event.target.href.split('#')[1], null, time, callbackFunction);
                    window.location.href = event.target.href;
                    return;
                });
            }
        }
    };
    return {
        scroll: scroll,
        bind: bind
    };
}();


================================================
FILE: src/slimScroller.js
================================================
var slimScroller = function (){
    'use strict';

    var targetPosition,horizontal,clock,elapsed,duration,startPosition,total,callback,elementPosition;
    var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;

    var scroll = function (target, horizontal, durationTime, callbackFunction) {
        duration = durationTime || 500;
        horizontal = horizontal || false;
        callback = callbackFunction || false;
        startPosition = (horizontal) ? window.pageXOffset : window.pageYOffset;
        total = (horizontal) ? document.body.scrollWidth : document.body.scrollHeight;
        elementPosition =(horizontal) ? document.querySelector(target).offsetLeft : document.querySelector(target).offsetTop;
        targetPosition = (elementPosition > total) ? total : elementPosition;

        clock = Date.now();
        step();
    };
    var easeInOutCubic = function (time) {
        return (time < 0.5) ? 4 * time * time * time : (time - 1) * (2 * time - 2) * (2 * time - 2) + 1;
    };
    var calculatePosition = function () {
        return (elapsed > duration) ? targetPosition : startPosition + (targetPosition - startPosition) * easeInOutCubic(elapsed / duration);
    };
    var step = function () {
        elapsed = Date.now() - clock;
        var stepPosition = calculatePosition();

        if (horizontal){
            window.scroll(stepPosition, 0);
        }else{
            window.scroll(0, stepPosition);
        }
        if (elapsed > duration) {
            if (callback) {
                callback([window.scrollX,window.scrollY]);
            }
        } else {
            requestAnimationFrame(step);
        }
    };
    return {
        scroll: scroll
    };
}();
Download .txt
gitextract_mp77rv2z/

├── LICENSE
├── README.md
├── demo.html
├── dist/
│   └── init.js
├── install.json
├── package.json
└── src/
    ├── slimScroller.full.js
    └── slimScroller.js
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (17K chars).
[
  {
    "path": "LICENSE",
    "chars": 1080,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2015 Mees Boeijen\n\nPermission is hereby granted, free of charge, to any person obta"
  },
  {
    "path": "README.md",
    "chars": 2955,
    "preview": "# slimScroller.js\n![](http://forthebadge.com/images/badges/built-with-love.svg)\n\nSmoothly scroll to positions on your we"
  },
  {
    "path": "demo.html",
    "chars": 5339,
    "preview": "<html>\n\t<head>\n\t\t<title>slimScroller.js Demo</title>\n\t\t<!-- These styles are not required for the actual plugin. Just fo"
  },
  {
    "path": "dist/init.js",
    "chars": 146,
    "preview": "// This script is only used for installation via Eager.\ndocument.addEventListener(\"DOMContentLoaded\", function(event) { "
  },
  {
    "path": "install.json",
    "chars": 167,
    "preview": "{\n\t\"resources\": {\n\t\t\"body\": [\n\t\t\t{\n\t\t\t\t\"type\": \"script\",\n\t\t\t\t\"src\": \"dist/slimScroller.min.js\"\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"type\": \"s"
  },
  {
    "path": "package.json",
    "chars": 456,
    "preview": "{\n  \"name\": \"slimscroller\",\n  \"version\": \"2.0.4\",\n  \"description\": \"Slim smooth-scrolling under 350 bytes (gzipped), wit"
  },
  {
    "path": "src/slimScroller.full.js",
    "chars": 3808,
    "preview": "var slimScroller = function (){\n    'use strict';\n\n    var elapsed, horizontal;\n    var requestAnimationFrame = window.r"
  },
  {
    "path": "src/slimScroller.js",
    "chars": 1780,
    "preview": "var slimScroller = function (){\n    'use strict';\n\n    var targetPosition,horizontal,clock,elapsed,duration,startPositio"
  }
]

About this extraction

This page contains the full source code of the ameesme/SlimScroller.js GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (15.4 KB), approximately 3.9k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!