私はバスケットボールのSVGコートを作った。このsvgでは、私に有益な2つの重要な道があります:と#threepoint_area_b
と#inside_area_b
と#threepoint_area_b
です。変数に依存する重複svgパスイベント
#inside_area_a
は、#threepoint_area_b
と重複し、#inside_area_b
は、#threepoint_area_a
と重なっている。 jQueryでは変数に応じて1つのペア(aまたはb)のみをクリック可能にしたいと考えています。たとえば、
if(poss=="home"){
//#inside_area_a and #threepoint_area_a click functions
}
else //#inside_area_b and #threepoint_area_b click functions
これはどのようにjQueryで行うことができますか?
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 435.7 234.4" style="enable-background:new 0 0 435.7 234.4;" xml:space="preserve">
<style type="text/css">
svg {
height: 100%;
}
.st0 {
fill: none;
stroke: #010101;
stroke-width: 3;
}
#inside_area_a {
fill: transparent;
}
#inside_area_b {
fill: transparent;
}
#inside_area_a:hover {
fill: #1abc9c;
}
#inside_area_b:hover {
fill: #1abc9c;
}
</style>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 435.7 234.4" style="enable-background:new 0 0 435.7 234.4;" xml:space="preserve">
<style type="text/css">
svg {
height: 100%;
}
.st0 {
fill: none;
stroke: #010101;
stroke-width: 3;
}
</style>
<rect id="XMLID_28_" x="5.2" y="24.3" class="st0" width="0" height="186.7" />
<path id="inside_area_a" class="st0" d="M29.1,211c52.4,0,94.9-41.8,94.9-93.4S81.5,24.3,29.1,24.3H5.2V211H29.1z" />
<path id="threepoint_area_a" class="st0" d="M5.3,24L5.3,24l0-0.7L5.3,24h23.9c52.4,0,94.9,41.8,94.9,93.4s-42.5,93.4-94.9,93.4H5.3
\t \t \t \t \t \t \t \t \t v0.6l0-0.6v18.7h425.4V5.3H5.3V24z" />
<path id="inside_area_b" class="st0" d="M430.5,23.6v188.1V211h-23.9c-52.4,0-94.9-41.8-94.9-93.4s42.5-93.4,94.9-93.4h23.9" />
<path id="threepoint_area_b" class="st0" d="M430.4,210.4L430.4,210.4l0,0.7L430.4,210.4h-23.9c-52.4,0-94.9-41.8-94.9-93.4
\t \t \t \t \t \t \t \t \t s42.5-93.4,94.9-93.4h23.9V23l0,0.6V5H5v224.1h425.4V210.4L430.4,210.4z" />
<line id="center_line" class="st0" x1="217.8" y1="231.9" x2="217.8" y2="3.4" />
<ellipse id="center_circle" class="st0" cx="217.8" cy="117.6" rx="27.3" ry="26.9" />
<line id="freethrow_line_a" class="st0" x1="93.3" y1="144.5" x2="93.3" y2="90.8" />
<line id="freethrow_line_b" class="st0" x1="342.4" y1="144.5" x2="342.4" y2="90.8" />
<path id="freethrow_circle_a" class="st0" d="M93.3,90.8c15.1,0,27.3,12,27.3,26.9s-12.2,26.9-27.3,26.9" />
<path id="freethrow_circle_b" class="st0" d="M342.4,144.5c-15.1,0-27.3-12-27.3-26.9s12.2-26.9,27.3-26.9" />
<line id="freethrow_lane_line_a_left" class="st0" x1="93.3" y1="144.5" x2="4.6" y2="144.9" />
<line id="freethrow_lane_line_a_right_dashes" class="st0" x1="4.4" y1="90.8" x2="93.8" y2="90.8" />
<line id="freethrow_lane_line_b_left_dashes" class="st0" x1="431.1" y1="144.5" x2="342" y2="144.5" />
<line id="freethrow_lane_line_b_right_dashes" class="st0" x1="430.6" y1="90.8" x2="342.2" y2="90.8" />
<line id="basket_board_a" class="st0" x1="23.4" y1="131.1" x2="23.4" y2="104.2" />
<line id="basket_board_b" class="st0" x1="412.3" y1="131.1" x2="412.3" y2="104.2" />
<line id="basket_holder_a" class="st0" x1="23.4" y1="117.6" x2="27.9" y2="117.6" />
<line id="basket_holder_b" class="st0" x1="412.3" y1="117.6" x2="407.7" y2="117.6" />
<ellipse id="XMLID_27_" class="st0" cx="31.7" cy="117.6" rx="3.8" ry="3.7" />
<ellipse id="basket_b" class="st0" cx="403.9" cy="117.6" rx="3.8" ry="3.7" />
</svg>
私はパスが、私はそれを置くべきで「クリック」イベントを、追加したいと思いますか?条件がアクティブである。 –
私の答えの更新を参照してください。 (私はあなたの質問を適切に理解することを願っています) –
ありがとう、それは私が尋ねた以上です:) –