-3
A
回答
0
您將需要更具體的瞭解究竟是什麼,你都試過,什麼是不工作的。但是,這應該讓你開始。本示例使用sgv,但可以很容易地將其轉換爲面向方法的更多div。
目標是在圓圈位於中心區域時點擊切換按鈕。祝你好運!
注意:這可能只適用於chrome。
document.getElementById("toggler").addEventListener("click", function(){
var el = document.querySelector("circle");
var className = "stopped";
el.classList.toggle(className);
if (!el.classList.contains(className)) { return }
var currentCX = parseFloat(getComputedStyle(el).getPropertyValue("cx"));
if (currentCX >= 240 && currentCX <= 260) {
console.log("hit");
} else {
console.log("miss");
}
});
@keyframes sweep {
from { cx: 5; }
to { cx: 495; }
}
circle{
animation-duration: 3s;
animation-timing-function: ease-in-out;
animation-name: sweep;
animation-iteration-count: infinite;
animation-direction: alternate;
}
circle.stopped{
animation-play-state: paused;
}
<svg id="lineWithDots" width="500px" height="20px">
<g transform="translate(0,10)">
<rect width="490" height="2" y="-1" x="5" />
<rect width="20" height="10" y="-5" x="240" />
<circle r="4" cx="5" stroke="rgb(0, 0, 0)" fill="rgb(255, 255, 255)" />
</g>
</svg>
<div>
<button id="toggler">toggle</button>
</div>
相關問題
- 1. 如何從資源創建工具欄?
- 2. 如何用PURE JavaScript創建加載欄?
- 3. 如何在javascript中動態創建導航欄
- 4. 如何在Android中創建評分欄?
- 5. 如何在android中創建導航欄?
- 6. 如何在Internet Explorer中創建邊欄
- 7. 如何在python3.5中創建菜單欄
- 8. 如何在XPages中創建搜索欄?
- 9. 如何在JSF中創建菜單欄
- 10. 如何在SSRS中創建'上下'欄?
- 11. 如何獲取在Javascript中創建的元素的源代碼?
- 12. 如何在ASP.NET 3.5中創建RSS源?
- 13. 如何創建範圍欄?
- 14. 如何創建選項欄
- 15. 如何在標題欄中創建工具欄?
- 16. 如何在c#中的任務欄上創建工具欄?
- 17. 如何在DHTMLX中創建底部工具欄(狀態欄)?
- 18. 如何在Android中創建傾斜的操作欄(工具欄)?
- 19. 如何創建在JavaScript
- 20. 如何創建在JavaScript
- 21. 如何在iOS上創建標籤欄?
- 22. 如何在Firefox上創建工具欄?
- 23. 如何在Windows資源管理器工具欄中創建自定義按鈕
- 24. 如何在JavaScript中創建https請求?
- 25. 如何在JavaScript中創建枚舉?
- 26. 如何在javascript中創建表格
- 27. 如何在javascript中創建flash按鈕
- 28. 如何在Javascript中創建一個類?
- 29. 如何在JavaScript中創建新行?
- 30. 如何在javascript中創建DOM窗口?
歡迎堆棧溢出。請查看[問]。看起來你忘了實際提出問題,而是發佈了工作請求。請更改您的問題,以包括[您嘗試過的](http://whathaveyoutried.com),並確保實際詢問您正在努力的部分。 – zzzzBov