2013-06-11 3 views
0

이벤트를 클릭 한 후에 표시하기 때문에 Raphael 세트에 id를 설정하고 싶습니다. set.id = -1 :이 방법으로 ID를 설정하는"Raphaeljs set"에 id를 설정하십시오.

function show(){ 
     var element = space2Draw.getById(-1); 
     element.show(); 

    } 
} 

불가능 :

내 페이지에서
var divResult = document.getElementById('printResult'); 
var space2Draw = Raphael(divResult, 1600, 900); 
var st = space2Draw.set(); 

st.push(
    space2Draw.circle(newXCoordinates, newYCoordinates, 20).click((function (valore) { 
     return function() { 
      window.open("index-point.html?id=" + (valore) + "&type=" + type + "&description=" + description + "&name=" + name); 
     } 
    }(valore))).mouseover(function() { 
     this.attr({ 'cursor': 'pointer' }); 
     this.attr({ 'opacity': '.50' }); 
    }).mouseout(function() { 
     this.attr({ 'opacity': '1' }); 
    }) 

      ); 

내가 버튼이 있습니다

이 내 설정되어 있습니까? ID를 설정 한 다음 해당 세트를 어떻게 찾을 수 있습니까?

도움을 미리 감사드립니다.

답변

1

아마도 Raphael data() 함수를 사용하여 요소/세트에 데이터를 할당 할 수 있습니다.

예 :

// you can keep global var for your id and increment it within your code 
var id = 0; 

var p = Raphael(100, 100, 500, 500), 
    r = p.rect(150, 150, 80, 40, 5).attr({fill: 'red'}), 
    c = p.circle(200, 200, 70).attr({fill: 'blue'}); 

var set = p.set(r,c).data("id", id); 
id++; 

// then in your click event to get the id you can do 
var whichSet = this.data("id"); 

// data("id") will return you the global id variable 

행운

2

당신은 나중에 액세스 할 요소에 대한 클래스를 추가 할 setAttribute()를 사용하여 시도하고 자신의 CSS의 propperties을 수정할 수 있습니다. 첫 번째 단계는 각 요소의 클래스를 변경하는 것입니다 :

myElement.node.setAttribute("class", "class_name"); 

불행하게도, 라파엘 당신이 한 번에 전체 세트에 대해이 작업을 수행 할 수 있도록 고유 한 HTML 개체로 세트를 처리 할 수 ​​없습니다. 당신은 당신이 순서에서 만든 클래스의 CSS 속성을 수정할 수 있습니다, jQuery를 사용하여, 다음

for (var i=0; i<st.length; i++) { 
    st[i].node.setAttribute("class", "class_name"); 
} 

: 대신,주기 위해 함께 아마도 당신의 세트에 각 요소에 대해 같은 것을이 작업을 수행해야 할 수도 있습니다 귀하의 세트에 요소를 표시합니다.

function show(){ 
    $('.class_name').css('display', 'block'); 
} 

이 정보가 도움이되기를 바랍니다.

+0

나는 시도했다 : st.node.setAttribute ("id", "element_id") 오류가있다 : 잡히지 않은 TypeError : 정의되지 않은 메서드 'setAttribute'를 호출 할 수 없다 – ilamaiolo

+0

이것을 설명하기 위해 내 대답을 다시 작성했다. Raphael은 집합을 하나의 개체로 취급 할 수 없으므로 setAttribute 메서드는 적용 할 수 없습니다. 대신, 집합의 각 객체를 변경해야합니다 (그리고 CSS 클래스를 할당해야합니다). 더 자세한 설명은 위를 참조하십시오. – gatotkaca

관련 문제