Jquery Run Once .one() In Viewport
I am making a progressbar and want it to play when it is in viewport. I got this working but the code is now executed every time and I need it to run only once. Because it creates
Solution 1:
You can use $.Callbacks()
with "once"
as parameter.
(function ($) {
$(document).ready(function() {
function runOnce() {
// Function that makes sure it only runs once.
// -----------I need to use .one() here but how?
// The location of the progressbar code for now lets put a alert in.
alert("run only once");
}
var callbacks = $.Callbacks("once");
callbacks.add(runOnce);
// Function that checks if it is in view.
$("<?php echo '#progress' . $module->id ?>").waypoint(function() {
callbacks.fire(runOnce);
}, {
offset: '50%'
});
});
})(jQuery);
Post a Comment for "Jquery Run Once .one() In Viewport"