Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Waypoint at bottom does not move down after appending

My waypoint which is triggered at 100% when scrolling down works the first time. Html is appended to div#mylist above the waypoint. Scroll back up the page and down again and it will append more. After a few times, it is noticable that the waypoint is not longer trigger at 100% of the page scroll, but virtually where the div#waypoint was to start with before ever appending. You can see by how the scroll bar shrinks that the waypoint was hit. You can also see that the div#mywaypoint is always at the bottom.

How can I have the waypoint act at 100% everytime after each append?

Here is the jsFiddle

The code
I have a waypoint set to trigger at 100%. I have two divs. One with the content and the other to trigger the waypoint.

$('#mywaypoint').waypoint(function (direction)
{
    if (direction != "down") return;
    for(var i = 0; i < 20; i++)
    {
        $('#mylist').append(i + ' - goodbye<br />');
    }
    $('#mylist').append('------<br />');
}, { offset: '100%' });

<div id="mylist"> 
    // {repeated 20 or more times as initial html}
    hello<br />
</div>
<div id='mywaypoint'></div>
like image 765
Valamas Avatar asked Sep 09 '13 01:09

Valamas


People also ask

What is a move type waypoint?

This waypoint type will change the group's active waypoint to the nearest waypoint other than the group's previous waypoint. Note that the automatically created first waypoint (the leader's initial position as seen in the map editor) is considered as a Move type waypoint and can be used by the cycle waypoint.

What happens when a waypoint is placed on a vehicle?

If the waypoint is placed upon a vehicle driven by a friendly unit that is not capable of carrying the entire group, and the group already has vehicles capable of carrying the entire group, as many units as possible will board the waypoint vehicle and the remainder board the original transport.

What happens when a group arrives at a waypoint?

The group will move to the waypoint, and then disembark from any vehicles its members are in. Helicopters will land on the closest helipad within 500 metres of the waypoint. If any group members other than the leader are in a vehicle of another group, that vehicle will stop to let them out.

How does the'get out'waypoint work?

If the Get Out waypoint is placed on an object, the group will move to the location of that object at the instant the Get Out waypoint becomes its current waypoint, then disembark as normal. This waypoint works in conjunction with the 'Guarded by' trigger type, see that topic above for more details.


1 Answers

A recalculation of the waypoint position needs to be made after the list is added.

The API documentation suggests that this is done using the refresh command:

$.waypoints('refresh');

However, refreshing right after the function causes (at least in my tests) many lists to be appended immediately.

I suspect that this has to do with the UI paint events not being rendered/flushed until the function execution ends or until some buffer is exhausted.

Therefore, moving the refresh out of execution order using a timeout seems to do the trick:

setTimeout(function(){$.waypoints('refresh');},10);

See my jsFiddle, which seems to be working correctly.

like image 72
MasterAM Avatar answered Nov 15 '22 07:11

MasterAM