我正在循環一個對象並在Raphael中創建圈子。在我創建的每個圈子上,我附加了一個單擊事件和一個mouseover事件。但是,當我使用「this」將圓移動到前面,例如this.toFront()時,則我的.click函數不起作用。如果我對this.toFront()發表評論,那麼我的點擊功能按預期工作。當使用「this」時,函數會丟失上下文 - Raphael JS
你能幫我理解我做錯了什麼嗎?
//dummy variables for example
var x_coord = '31';
var y_coord = '50';
var diameter = '80';
var opportunityUrl = 'http://www.google.com';
var fillColorStart = '#000';
var fillColorEnd = '#FF0000';
var p = paper.circle(x_coord, y_coord, diameter)
.data("i", i)
.click(function() {
alert(opportunityUrl);
})
.mouseover(function() {
this.toFront();
})
.attr({"fill": "90-"+fillColorStart+":5-"+fillColorEnd+":95","fill-opacity": 0.5})
.glow({color: "#4b4b4b", width: 7})
好酷。你有什麼想法,然後瞄準那個元素而不打破事件鏈? –
也許在創建對象並在'p'中存儲引用之後添加事件處理函數?然後你可以用'p.toFront();'而不是'this.toFront();'。 –
好的,謝謝你的幫助。我會仔細看看的。 –