Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

[Van2Shout addon] How can I keep the chat scrolled to the bottom?

I'd like to keep the chat locked to the bottom of the div, especially when posting a new chat message. Thoughts, @lifeisfoo + @caerostris?

Tagged:

Best Answer

Answers

  • This might not be suefull but i am using Firefox and it does not scroll to the bottom. The code says it should work, but it doesn't :(

  • Hey guys I have fixed the problem!!!!!!!!!!!!!!!

    well on my website anyway.

    I changed

    var obj = document.getElementById("van2shoutscroll"); //the slider currently is at the bottom ==> make it stay there after adding new posts if(obj.scrollTop == (obj.scrollHeight - obj.offsetHeight)) { var scrolldown = true; } else { var scrolldown = false; }
    to

    var obj = document.getElementById("van2shoutscroll"); //the slider currently is at the bottom ==> make it stay there after adding new posts if(obj.scrollTop == (obj.scrollHeight - obj.offsetHeight)) { var scrolldown = false; } else { var scrolldown = true; }

  • @woft said:
    Hey guys I have fixed the problem!!!!!!!!!!!!!!!

    well on my website anyway.

    I changed

    var obj = document.getElementById("van2shoutscroll"); //the slider currently is at the bottom ==> make it stay there after adding new posts if(obj.scrollTop == (obj.scrollHeight - obj.offsetHeight)) { var scrolldown = true; } else { var scrolldown = false; }
    to

    var obj = document.getElementById("van2shoutscroll"); //the slider currently is at the bottom ==> make it stay there after adding new posts if(obj.scrollTop == (obj.scrollHeight - obj.offsetHeight)) { var scrolldown = false; } else { var scrolldown = true; }

    Just to clarify, this code to change is located in the Van2Shout Plugin folder then Views/discussionscontroller_local.php

  • woftwoft
    edited July 2014

    Hello just wanted to update again, so I recently needed to be able to scroll the shoutbox up, but the interval for the updating of the shoutbox kept scrolling the shoutbox down before I found what i was looking for.

    I modified the code so that it only scrolled the shoutbox down after the initial load of the page.

    Here is the code I modified.

    All of this was done inside of the file views/discussionscontroller_local.php

    First of all you need to find

    function UpdateShoutbox()
    {
    

    It should be the first function called.

    Then delete

    var obj = document.getElementById("van2shoutscroll");
    
    //the slider currently is at the bottom ==> make it stay there after adding new posts
    if(obj.scrollTop == (obj.scrollHeight - obj.offsetHeight)) {
      var scrolldown = true;
    }
    else
    {
      var scrolldown = false;
    }
    

    Also delete

    if(scrolldown == true)
    {
      obj.scrollTop = obj.scrollHeight ;
    }
    

    This should be towards the end of the first function (function UpdateShoutbox())

    Then After jQuery(document).ready(function($) { UpdateShoutbox(); });

    Add jQuery(document).ready(function($) { UpdateShoutboxScroll(); }); on the next line.

    Then after the function UpdateShoutbox() code casing, so that means the final } which is around line 73 you need to add the new function.

    Copy and paste this function

    function UpdateShoutboxScroll()
    {
      setTimeout(scrollDown, 300)
    
      function scrollDown() {
        var obj = document.getElementById("van2shoutscroll");
        //the slider currently is at the bottom ==> make it stay there after adding new posts
        obj.scrollTop = obj.scrollHeight;
      }
    } 
    

    there before the function SubmitMessage()

    This will then mean that once the shoutbox loads the scroll bar will go down to the bottom but it will not load scroll down again until the page is re-loaded.

    The important thing to make this function work is the setTimeout(scrollDown, 300) as the scroll bar will not scroll down properly until all the content (i.e. the posts) are loaded into the shoutbox.

    This works for the most current release of the Van2Shout.

    @caerostris what do you think?

    Note, coding isn't formatting properly :neutral_face:

Sign In or Register to comment.