#javascript #html #jquery #css #svg
.ham {
cursor: pointer;
-webkit-tap-highlight-color: transparent;
transition: transform 400ms;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
.hamRotate.active {
transform: rotate(45deg);
}
.hamRotate180.active {
transform: rotate(180deg);
}
.line {
fill:none;
transition: stroke-dasharray 400ms, stroke-dashoffset 400ms;
stroke:#000;
stroke-width:5.5;
stroke-linecap:round;
}
.ham1 .top {
stroke-dasharray: 40 139;
}
.ham1 .bottom {
stroke-dasharray: 40 180;
}
.ham1.active .top {
stroke-dashoffset: -98px;
}
.ham1.active .bottom {
stroke-dashoffset: -138px;
}
Но мне надо что бы при нажатии на другую кнопку срабатывала анимация для этого пишу
$('#filter-menu-button').click(function(){
$('.hamRotate').toggleClass("active");
});
Но не работает
Ответы
Ответ 1
jQuery может работать с SVG только с версии 3+. Вы можете изменить .toggleClass() на .attr() или использовать .classList.toggle(). Ниже пример кода с решением через .classList.toggle() function toggleButton() { document.querySelector('.hamRotate').classList.toggle('active'); } document.querySelector('.hamRotate').addEventListener('click', toggleButton, false); document.querySelector('#filter-menu-button').addEventListener('click', toggleButton, false); .ham { cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform 400ms; -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; user-select: none; } .hamRotate.active { transform: rotate(45deg); } .hamRotate180.active { transform: rotate(180deg); } .line { fill: none; transition: stroke-dasharray 400ms, stroke-dashoffset 400ms; stroke: #000; stroke-width: 5.5; stroke-linecap: round; } .ham1 .top { stroke-dasharray: 40 139; } .ham1 .bottom { stroke-dasharray: 40 180; } .ham1.active .top { stroke-dashoffset: -98px; } .ham1.active .bottom { stroke-dashoffset: -138px; }
Комментариев нет:
Отправить комментарий