if 语句悬停语法错误消息

发布于 2024-11-04 13:08:49 字数 640 浏览 2 评论 0原文

我想说的是,如果运动向下并且运动达到一定长度,则使图像的不透明度变暗,但使用此代码我收到语法错误:

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

瞳孔里扚悲伤 2024-11-11 13:08:49

我给你的代码进行了 JSLint 旋转

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);
    }
}

有几个语法错误(缺少)和;除其他事项外)。另外, updateReadout(2) 调用位于 if 之外,然后是一个孤独的 else,所以我根据我认为它应该如何工作的方式修复了这个问题,但你绝对应该双重检查。

I gave your code a JSLint spin

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);
    }
}

There were several syntax errors (missing ) and ; among other things). Also, the updateReadout(2) call was outside the if and then followed by a lonely else, so I fixed that according to how I figured it should work but you should definitely double check.

安人多梦 2024-11-11 13:08:49

有关语法错误的更多详细信息会有所帮助。

乍一看,虽然您需要一组括号来对 if 语句进行分组

    if ((event.touches.length == 1) && (swipeDirection == 'down') && (swipeLength >= 90) && (swipeLength <= 120)) {

其次,您使用的选择器 1.png 我假设是图像元素的 src ?在这种情况下应该是

$('IMG[src*=1.png]').hover(function() {

但是根据图像名称进行选择是非常不可靠的。例如,上面的内容会匹配 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

    if ((event.touches.length == 1) && (swipeDirection == 'down') && (swipeLength >= 90) && (swipeLength <= 120)) {

Secondly the selector you're using 1.png i assume is the src of the image element? In which case it should be

$('IMG[src*=1.png]').hover(function() {

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

那请放手 2024-11-11 13:08:49
if ( event.touches.length == 1 ) && (swipeDirection == 'down') && (swipeLength >= 90) && (swipeLength <= 120){

应该是

if ( event.touches.length == 1 && swipeDirection == 'down' && swipeLength >= 90 && swipeLength <= 120){

括号问题

if ( event.touches.length == 1 ) && (swipeDirection == 'down') && (swipeLength >= 90) && (swipeLength <= 120){

should be

if ( event.touches.length == 1 && swipeDirection == 'down' && swipeLength >= 90 && swipeLength <= 120){

parentheses issues

空宴 2024-11-11 13:08:49

在这一部分中:

('1.png').hover(function() {
            $(this).stop().animate({ "opacity": .5 });
        }}

以及修复选择器(根据 Rory 的回答),最后一行应该是 });

$('IMG[src*=1.png]').hover(function() {
    $(this).stop().animate({ "opacity": .5 });
});

In this part:

('1.png').hover(function() {
            $(this).stop().animate({ "opacity": .5 });
        }}

as well as fixing the selector (per Rory's answer), the last line should be });:

$('IMG[src*=1.png]').hover(function() {
    $(this).stop().animate({ "opacity": .5 });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文