Forum Discussion

ZacharyMehalick's avatar
ZacharyMehalick
Community Member
2 years ago

Javascript scrollIntoView not working correctly

Hi so I'm trying to recreate this:
https://www.youtube.com/watch?v=c_WjEe0qzUo&feature=youtu.be

I've changed the javascript to all be on one line but regardless it doesn't work correctly like it does in the video and I don't understand why. It just somewhat scrolls down not even to the objects that it supposed to.

The thing is that when I execute the script in the console while having the published file open it works correctly. Can anyone tell me why this is happening? I've attached my storyline file for reference.

 

Edit:

My issue ended up being that the buttons that you click cannot be in the scroll box they have to be outside/floating on top of it otherwise the script won't work properly.

  • you have to add the "names of the objects" for the search to the "Alternate Text"

    document.querySelectorAll('[data-acc-text="section2"]')[0].scrollIntoView();

    • ZacharyMehalick's avatar
      ZacharyMehalick
      Community Member

      If you scroll down further in the scroll box you'll see that there's similarly colored boxes that have the requisite "Alternate Text". The colored boxes at the top should scroll to each one of the similar color below. Otherwise the published file wouldn't have them doing anything at all rather than just slightly scrolling downwards.

    • ZacharyMehalick's avatar
      ZacharyMehalick
      Community Member

      I have figured out my issue, apparently if the buttons are within the scroll box then it will not work properly. They have to be outside of it. Thank you all.

  • NorahBerry's avatar
    NorahBerry
    Community Member
    Zachary Mehalick

    Hi so I'm trying to recreate this:
    https://www.youtube.com/watch?v=c_WjEe0qzUo&feature=youtu.be five nights at freddy's

    I've changed the javascript to all be on one line but regardless it doesn't work correctly like it does in the video and I don't understand why. It just somewhat scrolls down not even to the objects that it supposed to.

    The thing is that when I execute the script in the console while having the published file open it works correctly. Can anyone tell me why this is happening? I've attached my storyline file for reference.

     

    Edit:

    My issue ended up being that the buttons that you click cannot be in the scroll box they have to be outside/floating on top of it otherwise the script won't work properly.

    Open the browser's developer console (usually by pressing F12) and look for any error messages that might indicate issues with your JavaScript code.
    These error messages can provide valuable clues about syntax errors, variable scope problems, or other issues preventing the code from working as expected.

    Use browser developer tools to set breakpoints in your code and step through it line by line. This can help you see what values are being assigned to variables and how the code is executing.
    Consider using a debugging library like console.log statements to print intermediate values and trace the script's execution flow to identify where things are going wrong.