Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8030293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:43:06+00:00 2026-06-05T00:43:06+00:00

class MakeCanvas constructor : (elemId,width,height,@slideTimeThrottled) -> @ctx = document.getElementById(elemId).getContext ‘2d’ @ctx.canvas.width = width @ctx.canvas.height

  • 0
class MakeCanvas
    constructor : (elemId,width,height,@slideTimeThrottled) ->      
        @ctx = document.getElementById(elemId).getContext '2d'  
        @ctx.canvas.width   = width 
        @ctx.canvas.height  = height
        @ctx.canvas.style.marginTop = (((height / 2) * -1)+(43 / 2))+'px'

        @aniInterval = null 
        clearInterval @aniInterval  
        @frameNum    = 0

    drawFrame : ->
        console.log 'drawFrame not overwritten'

    animate : ->
        clearInterval @aniInterval
        @frameNum    = 0
        @aniInterval = setInterval (=>
            @ctx.clearRect 0, 0, @ctx.canvas.width, @ctx.canvas.height
            @drawFrame()
            @frameNum++
            @stop() if @frameNum > @slideTimeThrottled
        ), frameRate
    stop    : ->
        clearInterval @aniInterval

I’m using a coffeescript class to try and automate some basic functions of the canvas. The above code works just fine for the most part, but I would really like to start using requestanimationframe instead of setInterval.

I would like to use the polyfill posted here: https://gist.github.com/1579671

Unfortunately I am just not getting it. How could this class be re-written to function the same and use requestanimationframe instead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:43:09+00:00Added an answer on June 5, 2026 at 12:43 am
    # requestAnimationFrame() shim by Paul Irish
    # http://paulirish.com/2011/requestanimationframe-for-smart-animating/
    
    window.requestAnimFrame = (->
      window.requestAnimationFrame or window.webkitRequestAnimationFrame or                         window.mozRequestAnimationFrame or window.oRequestAnimationFrame or window.msRequestAnimationFrame or (callback, element) ->
        window.setTimeout callback, 1000 / 60
    )()
    
    # Behaves the same as setInterval except uses requestAnimationFrame() where possible for better performance
    # @param {function} fn The callback function
    # @param {int} delay The delay in milliseconds
    
    window.requestInterval = (fn, delay) ->
    
      return window.setInterval(fn, delay) if not window.requestAnimationFrame and not         window.webkitRequestAnimationFrame and not (window.mozRequestAnimationFrame and     window.mozCancelRequestAnimationFrame) and not window.oRequestAnimationFrame and not     window.msRequestAnimationFrame
    
      start = new Date().getTime()
      handle = {}
    
      theLoop = ->
        current = new Date().getTime()
        delta = current - start
        if delta >= delay
          fn.call()
          start = new Date().getTime()
        handle.value = requestAnimFrame(theLoop)  
    
      handle.value = requestAnimFrame(theLoop)
      return handle
    # Behaves the same as clearInterval except uses cancelRequestAnimationFrame() where possible for better performance
    # @param {int|object} fn The callback function
    
    window.clearRequestInterval = (handle) ->
      (if window.cancelAnimationFrame then window.cancelAnimationFrame(handle.value) else (if     window.webkitCancelAnimationFrame then window.webkitCancelAnimationFrame(handle.value) else     (if window.webkitCancelRequestAnimationFrame then     window.webkitCancelRequestAnimationFrame(handle.value) else (if     window.mozCancelRequestAnimationFrame then window.mozCancelRequestAnimationFrame(handle.value)     else (if window.oCancelRequestAnimationFrame then     window.oCancelRequestAnimationFrame(handle.value) else (if window.msCancelRequestAnimationFrame then window.msCancelRequestAnimationFrame(handle.value)         else clearInterval(handle)))))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Class A calls the public method f() in the Constructor. Class B overrides method
class A{ public A(){ System.out.println(in A); } } public class SampleClass{ public static void
Class A { string name; IList<A> minorList = new List<A>(); } IList<A> majorList =
class BaseA{}; , class DerivedB{}; class DerivedC{}; DerivedB can be derived from BaseA :
class A { String s4 = abc; static public void main(String[]args ) { String
class Node { int x,y; Node *left, *right; Node(int x, int y); Node(); };
class ShortInputException(Exception): '''A user-defined exception class.''' def __init__(self, length, atleast): Exception.__init__(self) self.length = length
class A(object): _all = set() def __new__(cls): obj = super(A,cls).__new__(cls) cls._all.add(obj) return obj class
class Subscription < ActiveRecord::Base validates :feed_id, presence: true, uniqueness: true now that I verify
class Employee{ // salary variable is a private static variable private static double salary;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.