I tried almost every solution i found from this website and from other but with no success. What i am doing is rotating a button using CSS3 animation. I am doing this by having the button linked(using "a" element) and then enabling the animation using the pseudo element :target(almost equal to onclick event works in this case).
My problem is that when i click to the button at the first time a hash-tag(#btnq1 in my case) is being added to the URL.
Now, the actual problem, is that i cannot remove this hash-tag when i reload the whole page or if i want to click to that button one more time and re-run the animation. I tried solutions from some Stackoverflow questions like this or this but didn't got any good result.
See below my code:
You can ignore the initial phase of the animation named q1. HTML code:
<header>
<div id="title">
Just a title
</div>
</header>
<main>
Not important text
<div id="q1">
<div class="q1once">
<a href="#btnq1"><button type="button" name="" value="" id="btnq1">Click to rotate</button></a>
</div>
</div>
</main>
CSS code:
#q1{
height:100%;
}
.q1once{
width:20%;
height:15%;
position:absolute;
left:-50%;
animation-name:q1;
animation-delay:3s;
animation-iteration-count:1;
animation-duration:1.5s;
animation-fill-mode:forwards;
}
#btnq1:target{
animation-name:q1leave;
animation-iteration-count:1;
animation-duration:4s;
}
@keyframes q1{
50%{
transform:translate(440%) scaleX(3);
}
100%{
transform:translate(450%) scale(1.5,2);
}
}
@keyframes q1leave{
0%{transform:rotate(0deg);
opacity:1;
}
100%{
opacity:0;
transform:rotate(360deg);
}
}
You can check my updated jsfiddle as well.
Adding window.location.hash=''
on load of the page is a good partial solution because it removes the hashtag when i reload the page. However, it doesn't remove the hashtag after i click at the button at the first time. I want this to happen in order to be able to rotate the button more than once.