Click here to Skip to main content
15,895,462 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: problem with anonymus func with parameters Pin
dusty_dex3-Jun-13 5:42
dusty_dex3-Jun-13 5:42 
QuestionRe: problem with anonymus func with parameters Pin
ZurdoDev3-Jun-13 7:29
professionalZurdoDev3-Jun-13 7:29 
AnswerRe: problem with anonymus func with parameters Pin
#realJSOP6-Jun-13 4:35
mve#realJSOP6-Jun-13 4:35 
Questionhow to toggle between textbox and textarea by jquery Pin
mhd.sbt30-May-13 8:21
mhd.sbt30-May-13 8:21 
QuestionAs simple as I can make it Pin
#realJSOP30-May-13 8:03
mve#realJSOP30-May-13 8:03 
AnswerRe: As simple as I can make it Pin
Manfred Rudolf Bihy30-May-13 8:24
professionalManfred Rudolf Bihy30-May-13 8:24 
GeneralRe: As simple as I can make it Pin
#realJSOP30-May-13 11:53
mve#realJSOP30-May-13 11:53 
AnswerRe: As simple as I can make it Pin
Richard Deeming30-May-13 8:34
mveRichard Deeming30-May-13 8:34 
I'm not particularly familiar with the <canvas> tag, but I can see why your _imageWidth is zero: the load(function(){ ... }) method is adding the function as a handler to the image's load event. It won't get called until the image has loaded, which won't happen immediately.

Try putting the rest of your code in the callback:
JavaScript
function doIt()
{
    var _filename      = "http://paddedwall.org/2012mustang/images/blacklights_03.jpg";
    var _divName       = "#canvasesDiv";
    var _sceneWidth    = $(_divName).width();
    var _sceneHeight   = $(_divName).height();

    $('<img />').attr({'id': 'backgroundImage', 'src' : _filename}).load(function()
    {
        if (this.complete === true)
        {
            var _imageWidth = this.width;
            if (_imageWidth === 0)
            {
                _imageWidth = _sceneWidth;
            }

            var _scale = _sceneWidth / _imageWidth;
            var _canvas = $("<canvas>Not html5</canvas>");
            _canvas.css('width', _sceneWidth);
            _canvas.css('height', _sceneHeight);
            _canvas.attr('id', "backgroundCanvas");
            _canvas.css('width', _sceneWidth);
            _canvas.css('height', _sceneHeight);
            _canvas.css('position', 'absolute');
            _canvas.css('top', 0);
            _canvas.css('left', 0);
            _canvas.css('z-index', 0);
            _canvas.css("display", "block");
            $(_divName).append(_canvas[0]);

            var _context = _canvas[0].getContext('2d');
            _context.setTransform(1, 0, 0, 1, 0, 0);
            _context.scale(_scale, _scale);
            _context.drawImage(this, 0, 0);
        }
    });
}

http://jsfiddle.net/hXqMG/[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: As simple as I can make it Pin
Manfred Rudolf Bihy30-May-13 8:42
professionalManfred Rudolf Bihy30-May-13 8:42 
GeneralRe: As simple as I can make it Pin
Richard Deeming30-May-13 8:46
mveRichard Deeming30-May-13 8:46 
GeneralRe: As simple as I can make it Pin
Manfred Rudolf Bihy30-May-13 8:49
professionalManfred Rudolf Bihy30-May-13 8:49 
GeneralRe: As simple as I can make it Pin
Richard Deeming30-May-13 8:51
mveRichard Deeming30-May-13 8:51 
GeneralRe: As simple as I can make it Pin
Manfred Rudolf Bihy30-May-13 8:53
professionalManfred Rudolf Bihy30-May-13 8:53 
GeneralRe: As simple as I can make it Pin
#realJSOP30-May-13 11:54
mve#realJSOP30-May-13 11:54 
GeneralRe: As simple as I can make it Pin
Manfred Rudolf Bihy31-May-13 1:35
professionalManfred Rudolf Bihy31-May-13 1:35 
GeneralRe: As simple as I can make it Pin
#realJSOP1-Jun-13 2:24
mve#realJSOP1-Jun-13 2:24 
GeneralRe: As simple as I can make it Pin
Richard Deeming3-Jun-13 2:00
mveRichard Deeming3-Jun-13 2:00 
GeneralRe: As simple as I can make it Pin
#realJSOP5-Jun-13 8:56
mve#realJSOP5-Jun-13 8:56 
GeneralRe: As simple as I can make it Pin
Richard Deeming5-Jun-13 9:12
mveRichard Deeming5-Jun-13 9:12 
GeneralRe: As simple as I can make it Pin
#realJSOP5-Jun-13 10:54
mve#realJSOP5-Jun-13 10:54 
GeneralRe: As simple as I can make it Pin
Richard Deeming5-Jun-13 11:02
mveRichard Deeming5-Jun-13 11:02 
GeneralRe: As simple as I can make it Pin
#realJSOP6-Jun-13 2:54
mve#realJSOP6-Jun-13 2:54 
QuestionNeed help with ajax request Pin
marcusKam27-May-13 0:03
marcusKam27-May-13 0:03 
AnswerRe: Need help with ajax request Pin
Dennis E White28-May-13 4:29
professionalDennis E White28-May-13 4:29 
GeneralRe: Need help with ajax request Pin
marcusKam29-May-13 10:29
marcusKam29-May-13 10:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.