CSS :hover works only when mouse moves

前端 未结 3 1529
粉色の甜心
粉色の甜心 2021-01-04 08:39

I created a very basic sample:

HTML

CSS

#bla {         


        
3条回答
  •  旧时难觅i
    2021-01-04 09:00

    While you can use opacity, @BrianPhillips mentioned, it doesn't work in IE 8. I don't know of a pure CSS solution, but here's a concise enough Javascript workaround:

    window.onmousemove=function(event){
        ev = event || window.event;
        if (event.pageX <= 400 && event.pageY <= 400){
            document.getElementById('bla').style.backgroundColor= "red";
        } else {
            document.getElementById('bla').style.backgroundColor= "green";
        }
    }
    setTimeout(function() {
         document.getElementById('bla').style.display="block";
    },2000)
    

    Demo

提交回复
热议问题