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>
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With