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

JavaScript

 
QuestionCheckbox checked Java script and c# Pin
sujeet3215-Jun-13 22:43
sujeet3215-Jun-13 22:43 
AnswerRe: Checkbox checked Java script and c# Pin
Dennis E White6-Jun-13 12:01
professionalDennis E White6-Jun-13 12:01 
Questionproblem with anonymus func with parameters Pin
imbaro2-Jun-13 21:27
imbaro2-Jun-13 21:27 
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 
I'm still having problems:

0) The code will not get the width of the _image.
1) This in turn causes _scale to be "Infinity" (because _imageWidth is 0 when I try to do the division to determine _scale's value
2) Finally, the _context isn't drawing the _image.

If you want to try the code, I'm using jQuery 2.0 (prior versions back to 1.83 should work fine). Other than that, it's completely self-contained.

XML
<body>
    <div id="canvasesDiv" style="position:relative; width:416px; height:512px; border:1px solid black; background-color:silver;"></div>
</body>


JavaScript
function doIt()
{
    var _filename      = "http://paddedwall.org/2012mustang/images/blacklights_03.jpg";
    var _divName       = "#canvasesDiv";
    var _sceneWidth    = $(_divName).width();
    var	_sceneHeight   = $(_divName).height();
    var _imageWidth    = 0;
    var _image = $('<img />').attr({'id': 'backgroundImage', 'src' : _filename})[0];
    $(_image).load(function()
    {
        if (this.complete === true)
        {
            _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($(_image)[0], 0, 0);
}

".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997


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 
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 

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.