我似乎在任何地方都找不到解决办法。基本上,我有一个带有针的米规,当它挂在上面时,它会旋转。我在CSS上工作得很好,不过如果有人能指导我如何用Javascript来做这件事,我很感激。
最重要的是,我需要号码上升到(就像汽车计量器) onmouseover,然后使用innerHTML将onmouseout放下来。那么,如何使用Javascript中的一系列数字呢?我需要从0到270。
(预先谢谢:)
HTML:
<div id="all">
<svg viewBox="0 0 113 111">
<style>
.st3{fill:#17ceff}.st4{fill:none}
</style>
<path d="M64.2 56.3c0 4.4-3.6 8-8 8-1.4 0-2.7-.4-3.9-1L31.7 80.6l17.5-20.5c-.6-1.1-1-2.4-1-3.8 0-4.4 3.6-8 8-8s8 3.5 8 8z" fill="#252626" stroke="#fff" stroke-width=".47" stroke-miterlimit="10" id="needle"/>
<div class="result" id="result">0</div>
</svg>
</div>CSS:
#needle {
transform-origin: inherit;
transition: 0.70s;
}
#needle:hover {
transition: 0.70s;
transform: rotate(270deg);
}发布于 2020-01-17 18:16:25
<div class="whole-container">
<div class="meter">0</div>
<div class="needle"></div>
</div>Jquery
var inte;
$('.whole-container').on('mouseover', function () {
clearInterval(inte);
var i = parseInt($('.meter').text());
inte = setInterval(() => {
$('.meter').text(i);
$('.needle').css('transform', 'rotate(' + i + 'deg)');
if (i == 270) clearInterval(inte);
i++;
}, 100);
});
$('.whole-container').on('mouseout', function () {
clearInterval(inte);
var i = parseInt($('.meter').text());
inte = setInterval(() => {
$('.meter').text(i);
$('.needle').css('transform', 'rotate(' + i + 'deg)');
if (i == 0) clearInterval(inte);
i--;
}, 100);
});请根据需要对html和脚本类/id进行更改
https://stackoverflow.com/questions/59792082
复制相似问题