EDIT2:这是控制台日志。图像正在转换为画布(HTML5),我需要以某种方式将其返回给全局变量。建议?Javascript - 全球与本地变量之间的混淆
<img id="mainIllustration" alt="main illustration" src="Img/Model01.png">
Illust...o_03.js (line 24)
<canvas id="mainIllustration" class="" width="278" height="659" style="" title="" tabindex="-1">
Illust...o_03.js (line 32)
<img id="mainIllustration" alt="main illustration" src="Img/Model01.png">
Illust...o_03.js (line 24)
<canvas id="mainIllustration" class="" width="278" height="659" style="" title="" tabindex="-1">
Illust...o_03.js (line 32)
<img id="mainIllustration" alt="main illustration" src="Img/Model01.png">
Illust...o_03.js (line 24)
<canvas id="mainIllustration" class="" width="278" height="659" style="" title="" tabindex="-1">
编辑1:我开始不知道这个问题是否与Pixastic,但事实上,它操纵的形象,这是我必须要返回到全局变量图像(eMainIllustration)。我将如何实现这一目标?
原始消息:
所有,
进出口使用pixastic库和我变得非常由一个看似很简单的事情,全局/局部变量混淆。
我有以下两组代码,其中一个变量是全局定义的(最终是我想要的)&另一个变量是局部定义的。
下面的第一个代码正常工作,变量(eMainIllustration)是本地定义的,并且该函数运行良好。
var eDisplayTableSlideState = false;
function displayTableSlideIn()
{
// eMainIllustration is locally defined
var eMainIllustration = document.getElementById("mainIllustration");
if (eDisplayTableSlideState === false)
{
$("#displayTable").animate ({top: "-=33px", left: "+=66px", width: "-=198px", height: "-=48px"}, 750, "swing",function()
{
Pixastic.process (eMainIllustration,"blurfast", {amount: 0.1});
return (eDisplayTableSlideState = true);
} else
{
$("#displayTable").animate ({top: "+=33px", left: "-=66px", width: "+=198px", height: "+=48px"}, 500, "swing",function()
{
Pixastic.revert(eMainIllustration);
});
return (eDisplayTableSlideState = false);
}
}
然而,当我设置变量(eMainIllustration)全球范围内,如果函数的声明工程第一,但是在功能上的“其他”部分pixastic.revert代码没有。为什么?
// eMainIllustration is locally defined
var eMainIllustration = document.getElementById("mainIllustration");
var eDisplayTableSlideState = false;
function displayTableSlideIn()
{
if (eDisplayTableSlideState === false)
{
$("#displayTable").animate ({top: "-=33px", left: "+=66px", width: "-=198px", height: "-=48px"}, 750, "swing",function()
{
Pixastic.process (eMainIllustration,"blurfast", {amount: 0.1});
return (eDisplayTableSlideState = true);
} else
{
$("#displayTable").animate ({top: "+=33px", left: "-=66px", width: "+=198px", height: "+=48px"}, 500, "swing",function()
{
Pixastic.revert(eMainIllustration);
});
return (eDisplayTableSlideState = false);
}
}
我不知道这是因为我没有在功能上半年(如有),通过返回返回改变(eMainIllustration)的状态。那是对的吗?我将如何实现这一目标?
最好,
我想知道为什么这么多人让JavaScript看起来像Java/C#:) –
1)当说些什么“不起作用”时总是要更加明确; 2)在if语句中与布尔值比较是一般反模式 – hugomg