Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Total Page Scroll Control

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 61 total)
  • Author
    Posts
  • #253008
    Funkaholik
    Participant

    Hi there
    i’m working here on Total Page Scroll Control=))
    it’s almost complete but i still have some stuff to do.

    what i’m trying to acomplish:
    1. if you land on the page first nav-link should be active – done.
    2. if you click another nav-link it should become active – done
    3. if you click a certain nav-link page should scroll to a certain element – done
    4. when you scroll to a certain element (say #id) anchored link nav-link should become active – not done
    5. when you scroll to a certain element (say #id) .hidden-by-default element should become visible – not done

    What i don’t like here in general is JQuery)) Don’t know why but i like to hadle things without Bootstrap & JQuery.
    But if i took out JQuery slow scroll disappears how i can add some slow scroll transitions?

    P.S. Since we have html5 tag nav can we stack nav links without this stooped ul li ?)
    And how not supported browsers will render it then?

    #253009
    Shikkediel
    Participant

    Here’s some code I adapted for a topic on SO that handles smooth scrolling with vanilla JS:

    codepen.io/rOyVZd

    #253014
    Funkaholik
    Participant

    Damn .. lots of actual coding.
    I’ll better stick with JQuery instead.,)

    But in terms of handling page scroll with navbar can you recommend something for 4 and 5?

    #253016
    Shikkediel
    Participant

    I’ll have to look into it a bit more (answer edited)…

    #253021
    Mottie
    Member

    Smooth scrolling will eventually become available to all browsers, and all you would need to do is add a css property, see scroll-behavior.

    Current browser support @ http://caniuse.com/#feat=css-scroll-behavior

    For now, you can use this polyfill to add support: https://github.com/iamdustan/smoothscroll

    #253025
    Funkaholik
    Participant

    Hey .. that’s a great feature.
    Checked it already.
    But for now i just need my nav links to become active as you scroll to a certain element.
    And some hidden elements to become visible. And job is done=)

    #253026
    Shikkediel
    Participant

    when you scroll to a certain element (say #id) anchored link nav-link should become active – not done

    Isn’t this the code at the bottom? Could be a bit shorter though – and you could combine it:

    $(function() {
      $('.scroll').click(function(e) {
        $('.active').removeClass('active');
        $(this).addClass('active');
        var destination = $(this).attr('href');
        e.preventDefault(); //-- the hell is this e --//
        $('html, body').animate({
          scrollTop: $(destination).offset().top
        }, 750);
      });
    });
    
    #253027
    Shikkediel
    Participant

    Could you maybe elaborate on the fifth point – is this hidden div connected of the other anchored content somehow? Or should it be shown whenever it comes into view of the screen…

    Edit – if you use .scroll for both, it’s not a good idea to name the other elements like this.

    codepen.io/NpYepa

    #253028
    Funkaholik
    Participant

    yep .. but it becomes active only if you click on a nav link
    but if you just scroll the page first nav link always will be active,
    and i want it to change .. say you’ve scrolled to a div with id = “two” and second nav link now active and so on.

    And about hidden element .. let’s put it into a second div like so and make it visible as you scroll to that div.
    You saw that transitions/animation that happens after you scroll to a certain area?

    #253029
    Shikkediel
    Participant

    it’s not a good idea to name the other elements like this

    Actually, you could if you have a reason for it:

    $('.scroll').not('.frames').click(function(e) {
    

    What you describe in your previous post becomes complicated very quickly…
    I know because it took a while to coordinate this pen:

    http://codepen.io/Shikkediel/pen/avdyWx

    I’ll have a look if I can adapt it to your use case without too much hassle.

    Did not notice the transition you mentioned by the way.

    #253031
    Shikkediel
    Participant

    Here’s a fork with some adjustments:

    codepen.io/JWLzOZ

    #253032
    Funkaholik
    Participant

    Yoooooo .. great job on this one, Mr. Total Scroll Control.,)

    #253033
    Shikkediel
    Participant

    Lol, you don’t wanna know how many hours I spent on the scroll event in general. It’s pretty ridiculous.

    #253034
    Funkaholik
    Participant

    At least you didn’t spent those hours looking for a typo in your code, like i remember did a few times. That’s definitely not a good way to spent time!)
    Anyway thanx again ^_^

    #253035
    Shikkediel
    Participant

    No problem, let me know if you hit a stump when you try to adapt it further.
    I’ve spent several days on a few lines of PHP once, so I know the feeling. :-/

Viewing 15 posts - 1 through 15 (of 61 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.