if 语句悬停语法错误消息
我想说的是,如果运动向下并且运动达到一定长度,则使图像的不透明度变暗,但使用此代码我收到语法错误:
function touchMove(event) {
event.preventDefault();
if ( event.touches.length == 1 ) && (swipeDirection == 'down') && (swipeLength >= 90) && (swipeLength <= 120){
curX = event.touches[0].pageX;
curY = event.touches[0].pageY;
('1.png').hover(function() {
$(this).stop().animate({ "opacity": .5 });
}}
// OPTIONAL ACTION: draw the results to the page
updateReadout(2)
} else {
touchCancel(event);
}
}
I'm trying to say if the movement is down and the movement is a certain length then make the opacity of the image darker but with this code I'm getting a syntax error:
function touchMove(event) {
event.preventDefault();
if ( event.touches.length == 1 ) && (swipeDirection == 'down') && (swipeLength >= 90) && (swipeLength <= 120){
curX = event.touches[0].pageX;
curY = event.touches[0].pageY;
('1.png').hover(function() {
$(this).stop().animate({ "opacity": .5 });
}}
// OPTIONAL ACTION: draw the results to the page
updateReadout(2)
} else {
touchCancel(event);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我给你的代码进行了 JSLint 旋转
有几个语法错误(缺少)和;除其他事项外)。另外, updateReadout(2) 调用位于
if
之外,然后是一个孤独的else
,所以我根据我认为它应该如何工作的方式修复了这个问题,但你绝对应该双重检查。I gave your code a JSLint spin
There were several syntax errors (missing ) and ; among other things). Also, the updateReadout(2) call was outside the
if
and then followed by a lonelyelse
, so I fixed that according to how I figured it should work but you should definitely double check.有关语法错误的更多详细信息会有所帮助。
乍一看,虽然您需要一组括号来对 if 语句进行分组
其次,您使用的选择器
1.png
我假设是图像元素的 src ?在这种情况下应该是但是根据图像名称进行选择是非常不可靠的。例如,上面的内容会匹配 1.png,还有 11.png、21.png 等。如果您可以将其更改为类或 id 选择器,或者从触摸的元素遍历 DOM 来查找图像。
代码中可能存在其他问题,但这应该可以解决语法问题。
A little more detail as to what the syntax error is would be helpful.
On first glance though you need a set of brackets to group your if statement
Secondly the selector you're using
1.png
i assume is the src of the image element? In which case it should beHowever selecting based on the image name is very unreliable. For example, the above would match 1.png, and also 11.png, 21.png etc. If you can change this to be a class or id selector, or traverse the DOM from the touched element to find the image.
There could possibly be other issues in the code, but that should hopefully fix the syntax problems.
应该是
括号问题
should be
parentheses issues
在这一部分中:
以及修复选择器(根据 Rory 的回答),最后一行应该是
});
:In this part:
as well as fixing the selector (per Rory's answer), the last line should be
});
: