Giter VIP home page Giter VIP logo

electron-retain-webview-scroll's Introduction

Electron Scroller

Electron Scroller is a package designed to manage scrolling of historical pages in <webview> tags. Webviews in electron manage page history, offering forward and back, but when navigating to the pages, the scroll position is lost. This package allows you to maintain the scroll position and automatically reposition the page to the proper scroll position upon navigation (back, forward, reload).

Installation

To install Electron Scroller, use npm. The preferred method is to install Electron Scroller as an dependency in your app:

npm install --save electron-scroller

Quick Start

It is necessary to include Electron Scroller in two places in your app:

  1. In your render javascript (called via a <script> in the HTML source)
  2. In the preload file (specified in the <webview preload="file.js")

Example HTML

<!DOCTYPE html>
<html>
<head>
  <title>Browser</title>
</head>
<body>
  <div id="buttonBar">
    ...
  </div>
  <div id="browser">
    <webview id="browserView" preload="preload.js"></webview>
  </div>
  <script src="browser.js"></script>
</body>
</html>

Render Javascript

Require the package and use the add() method. Pass to add() a string containing a single CSS selector that describes the specific webview to be managed. If only a single webview exists, the selector is not required. Because the Scroller hooks into the methods of the webview, it may be best to call add() early in the process and before configuring the webview. In this example, in the file browser.js:

const scroller = require('electron-scroller')

onload = function() {
  let selector = '#browserView'
  scroller.add(selector)
  // The selector is not required if there is only a single webview:
  // scroller.add()
}

Preload Javascript

The Scroller has to be included in the preload file by calling the preload() method. It is not necessary to pass the selector. In this example, in the file preload.js:

require('electron-scroller').preload()

License

ISC

electron-retain-webview-scroll's People

Contributors

praneetrohida avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.