Guest User

Untitled

a guest
May 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. var processor = {
  2. timeoutId:null,
  3. performProcessoring:function(){
  4. // do something
  5. },
  6. process:function(){
  7. clearTimeout(this.timeoutId);
  8. var that = this;
  9. this.timeoutId = setTimeout(function(){
  10. that.performProcessoring();
  11. },100)
  12. }
  13. }
  14. /** throttle**/
  15. function throttle(method,context){
  16. clearTimeout(method.tId);
  17. method.tId = setTimeout(function(){
  18. method.call(context);
  19. },100)
  20. }
  21.  
  22. //example
  23. function resizeDiv(){
  24.  
  25.  
  26. }
  27.  
  28. window.onresize = function(){
  29. throttle(resizeDiv)
  30. }
Add Comment
Please, Sign In to add comment