Socket
Book a DemoInstallSign in
Socket

feed-view

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feed-view

feed-view provides chat like scroll behaviour. The element's scroll, sticks to the bottom when new elements are added and doesn't jump when new elements are added above the element's scrolltop.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

feed-view

feed-view provides chat like scroll behaviour. The element's scroll, sticks to the bottom when new elements are added and doesn't jump when new elements are added above the element's scrolltop.

GitHub license GitHub issues Twitter

You've created an chat an and you want to add simple chat like scroll behaviour:

Example chat view

You can use this simple 1kb module to manage scroll behaviour for you. This module works for any html container that receives new children dynamically. If the scrolled all the way to the bottom, the bottom will stick. When new elements are added on above the current scroll view, this module will maintain the right amount of scroll.

Installation

Node

npm i -S feed-view
const FeedView = require('feed-view');
// or
import FeedView from 'feed-view'; // if you're using es6

Browser

CDN: https://cdn.jsdelivr.net/npm/feed-view/dist/feed-view.min.js

<script src="https://cdn.jsdelivr.net/npm/feed-view/dist/feed-view.min.js"></script>
<script>
  // "FeedView" is now a global variable
</script>

Usage

var container = document.querySelector('#container'); // the scrolling element
var feedView = new FeedView(container);

console.log(view.container); // the scrolling element
console.log(view.sticky); // is the scrolling element currently sticked to the bottom

Everytime you add an element or right after you've added multiple elements, call ".update()" on the feediew instance. This scrolls the scrolling element if nessecary and updates the state.

setTimeout(() => {
  container.appendChild(document.createTextNode('Message 1'));
  feedView.update();
}, 1000);

setTimeout(() => {
  container.appendChild(document.createTextNode('Message 2'));
container.appendChild(document.createTextNode('Message 3'));
  feedView.update();
}, 1000);

Keywords

webpack

FAQs

Package last updated on 13 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts