LM Rig
LM Rig

Reputation: 21

Hover is still active after action on the phone

EDIT: Anyone please?

I got this from somewhere but when I tap on it on the phone (on PC it's ok) it stays with hover attributes = no BG and black colour to the next website refresh:

HTML

<a id="back2Top" title="Top" href="#">&#10148;</a>

CSS

#back2Top {
    width: 40px;
    line-height: 40px;
    overflow: hidden;
    z-index: 999;
    display: none;
    cursor: pointer;
    transition: background-color 0.2s linear;
    -moz-transform: rotate(270deg);
    -webkit-transform: rotate(270deg);
    -o-transform: rotate(270deg);
    -ms-transform: rotate(270deg);
    transform: rotate(270deg);
    position: fixed;
    bottom: 39px;
    right: 0;
    background-color: #8db500;
    color: #fff;
    text-align: center;
    font-size: 30px;
    text-decoration: none;
}
#back2Top:hover {
    background-color: transparent;
    color: #000;
}
@media only screen and (max-width: 767px) {
#back2Top {
    bottom: 0px;
}}

And JS

$(window).scroll(function() {
    var height = $(window).scrollTop();
    if (height > 100) {
        $('#back2Top').fadeIn();
        $('.open').css('background', 'rgba(141, 181, 0, 0.5)'); //these 3 are for something different
        $('.closed').css('background', 'rgba(201, 0, 10, 0.5)');
        $('.warn').css('background', 'rgba(255, 113, 0, 0.5)');

    } else {
        $('#back2Top').fadeOut();
        $('.open').css('background', 'rgba(141, 181, 0, 1)'); //these 3 are for something different
        $('.closed').css('background', 'rgba(201, 0, 10, 1)');
        $('.warn').css('background', 'rgba(255, 113, 0, 1)');
    }
});
$(document).ready(function() {

    $("#back2Top").click(function(event) {
        event.preventDefault();
        $("html, body").animate({ scrollTop: 0 }, "slow");
        return false;
    });

});

What is wrong there? Or what I did wrong? ×I don't know what to add more here, it won't let me post it because of mostly code.× Thank you.

Upvotes: 0

Views: 81

Answers (1)

Shivam Sharma
Shivam Sharma

Reputation: 421

If I'm right then you're trying to make an icon to go to the Top. Here, I'm sharing a simple code for that, you'll understand easily.

window.onscroll = function () { myFunction() };

var goToTop = document.getElementById("goToTop");

function myFunction() {
  if (window.pageYOffset >= 30) {
    goToTop.classList.add("sticky")
  } else {
    goToTop.classList.remove("sticky");
  }
}
body{
height:1500px;
width:100vw;
}
.goToTop{
    height:69px;
    width:69px;
    border-radius: 50%;
    background:white;
    position:fixed;
    right:30px;
    bottom:20px;
    z-index:1000;
    display:none;
}
.goToTop img{
    width:70px;
}
.goToTop.sticky{
    display: inline-block;
}
<body id="body">
  <div class="goToTop" id="goToTop">
      <a href="#body">
        <img src="https://img.icons8.com/ios/50/000000/collapse-arrow--v1.png"/>
      </a>
  </div>
</body>

OR
If I'm wrong Or You want me to fix your code only, then let me know in the comments.

Upvotes: 1

Related Questions