Element.insertBefore(el)
插入当前元素到给定元素的前面。也就是Element
到el
的前面。
参数
el
元素。被插入的元素。
返回值
元素。返回父元素。
使用
<svg id="svg" width="100" height="100"></svg>
<input id="button" type="button" value="点击改变圈圈的顺序">
var svg = Snap("#svg");
var c1 = svg.paper.circle(50, 50, 40).attr({
fill: "#f00" // 红色
});
var c2 = svg.paper.circle(100, 50, 40).attr({
fill: "#00f" // 蓝色
});
// 事件
$("#button").on("click", function() {
c2.insertAfter(c1);
});
HTML变化
默认:
点击按钮后: