raphael .click和.unclick援助

时间:2012-08-01 18:16:10

标签: click raphael

所以我一直在使用raphael来创建一个用户界面,并且想要这样,如果有人点击一个圆圈,它会突出显示圆圈,或者对圆圈做一些视觉上有趣的事情,注意它已被选中。我对此的视觉方面并不十分担心。我试图找到一种方法来实现这一点,似乎没有任何工作。这很简单。至少我是这么认为的,但事实证明这让我很头疼。我会提供代码,但我现在所拥有的是一团糟。如果你想要它,我会添加它。

function elemClick(el)
            {
                el.click(function(){
                    circleSelectedArray[0] = true;

                });

                el.unclick(function(){
                    circleSelectedArray[0] = false;
                });


            }

1 个答案:

答案 0 :(得分:4)

您无法同时绑定点击并取消绑定....

el.click(fn) means that you are binding a click event to that element like the way you have which is fine ....
el.unclick(fn) means that you are unbinding a click function from that element.

USE - >如果你这样el.unclick(),所有点击事件都将从该元素中解除绑定     如果你想使用一个功能......

 function yourFunc(){
    console.log('you clicked me !')}
    el.click(yourFunc); // now when you click this el console will show the phrase
    //when you unbind the function
    el.unclick(yourFunc);

我只是预感到您可能正在尝试使用mousedown和mouseup事件......

编辑:符合您的要求

function sel_unsel(){
if(this.data('selected') == false){
   this.data('selected', true);
   // do here what you want when element is selected
   }else if(this.data('selected') == true){
   this.data('selected', false);
   //do here what you want when element is unselected
   }
   }
function elemClick(el){
     el.data('selected',false);
el.click(sel_unsel);}