Raphael.js - if / else语句没有切换点击 [英] Raphael.js - if / else statement not toggling on click

查看:145
本文介绍了Raphael.js - if / else语句没有切换点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个盒子,我希望它们在它们之间切换,并在第二次点击时关闭。目前它在它们之间切换很好(IF部分),但是当我点击同一个框以切换它时如果不起作用(else if部分似乎不起作用)。我想我需要重构if语句。任何帮助是极大的赞赏。

I have 3 boxes and I want them to switch between them and also toggle off on a second click. Currently it switches between them fine (the IF part), but when I click on the same box to toggle it off if doesn't work (the "else if" part doesn't seem to work). I think I need to restructure the if-statement. Any help is greatly appreciated.

这是JS小提琴:
http ://jsfiddle.net/FFdjS/5/

这是元素点击if-statement之一:

Here is one of the element's click if-statement:

box1.click(function() {
    if (box1.attr(strOff)) {
        box1.attr(strOn);
        box2.attr(strOff);
        box3.attr(strOff);
    } else if (box1.attr(strOn)) {
               box1.attr(strOff);
    } else {}
});


推荐答案

Element.attr(。 ..)在将对象作为参数传递时设置属性。返回元素。如果你想要谷歌它 - 使用这样的东西:

Element.attr(...) sets the attribute when object is passed as argument. Returns Element. If you want to toogle it - use something like this:

box1.click(function() {
    if (box1.attr('stroke-width') == 1) {
        box1.attr(strOn);
        box2.attr(strOff);
        box3.attr(strOff);
    } else if (box1.attr('stroke-width') == 5) {
           box1.attr(strOff);
    } else {}
});

关于 jsFiddle

这篇关于Raphael.js - if / else语句没有切换点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆