Coder Social home page Coder Social logo

Comments (2)

sarboc avatar sarboc commented on August 13, 2024

Hi there! Here's how I tackled the issue in a project I recently worked on:

  function scrolling() {
      var lastScrollTop = 0;

      $(window).scroll(function() {
        var current = $(this).scrollTop();

        if (current > lastScrollTop) {
          // downscrolling!
         (put downscrolling stuff here)
        } else {
          //upscrolling!
          (put upscrolling stuff here)
        }

        lastScrollTop = current;
      });
    }

Curious if others have better solutions...

from skrollr-menu.

agualbbus avatar agualbbus commented on August 13, 2024

sarboc thanks for your reply, I couldn't use your snippet because the handleLink function runs before the scrolling event, but it inspire me and I finally I came with this:

<a href="#slide4" data-menu-top="250"></a>(position in percentage value without "p")

handleLink: function(link) {
    var target=parseInt(link.getAttribute('data-menu-top')),//percentage position of target
        currentTop = $(window).scrollTop();

    currentTop=Math.round(sizes.bodyH()) * currentTop / 100; //convert to percentage 
    target=(currentTop < target) ? String(target+1)+'p' : String(target-1)+'p';

    //console.log(target);

    return target;//ex: 251p

},

Need to improve yet, sometimes that -+1p gives an undesired offset, but I achived the main goal that was to fire the event that high lights those links.

from skrollr-menu.

Related Issues (20)

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.