Giter Site home page Giter Site logo

infinite-scroll-stimulus-js's Introduction

README

This README would normally document whatever steps are necessary to get the application up and running.

Things you may want to cover:

  • Ruby version

  • System dependencies

  • Configuration

  • Database creation

  • Database initialization

  • How to run the test suite

  • Services (job queues, cache servers, search engines, etc.)

  • Deployment instructions

  • ...

infinite-scroll-stimulus-js's People

Contributors

excid3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

infinite-scroll-stimulus-js's Issues

Note to jsbundling/esbuild users (Rails is not defined)

You will probably need this in your application.js ๐Ÿ‘

// Infinite scroll requires Rails to be globally defined
// https://github.com/rails/rails/issues/36686
import Rails from "@rails/ujs";
window.Rails = Rails;

if(Rails.fire(document, "rails:attachBindings")) {
  Rails.start();
}

Force Scroll function to load only once.

Chris,

Thanks for the code and the video, I appreciate your work!

I am working on the implementation of infinite-scroll in my Django + Stimulusjs app. In my controller I am using your original solution:

var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.offsetHeight)

if (window.pageYOffset >= height - window.innerHeight) {
  this.loadMore(url, entries, pagination)
}

This is supposed to call loadMore when the user scrolls all the way to the bottom. It works fine (https://builtwithdjango.com). The problem I am running into is when browsing with Safari the loadMore function is called more than once, which causes the stimulus-controller add same sites (from same page) multiple times. I end up with duplicates.

Is there a way to tell my controller to call loadMore function only once.

P.S. If I was to change the if statement to run the controller little bit higher than the bottom of the page, say 50px:

if (window.pageYOffset >= height - window.innerHeight - 50) {
  this.loadMore(url, entries, pagination)
}

This would also cause the script to be called more than once. I'm not sure how to stop this behavior. Do you happen to know how to fix this? Thanks a ton in advance.

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.