javascript - Why does element load with blank opacity? And why does my js cancel the hover effect? -


i have element should fade out when clicked , fade in when it's space clicked again. additionally, opacity should 0.9 (rather 1) when visible.

there's 2 problems code. hover selector seems break click element , js executes. (once unfades element loses hover effect.) second weird, js accounts it: element has opacity == "" reason! think might because hover effect confusing js actual value of opacity should be.

function giterdone(element){   var op = element.style.opacity;   if(op != 0){     fade(element);     return;   } else if(op == "" || op == null){     element.style.opacity = 1;     giterdone(element);     return;   } else {     unfade(element);     return;   } }  function fade(element) {   //works fine :) }  function unfade(element) {   //works fine :) } 

here relevant css:

.sm-box{     float:left;     width: 100px;     height: 100px;     margin: 0px;     background-repeat:no-repeat !important;     background-position:center !important;   }   .sm-box:hover{     opacity: 0.9;     filter: alpha(opacity=90);   } 

and here element in natural habitat:

<body> <div class="container">   <div class="sm-box"></div>   <div class="sm-box"></div>   <div class="sm-box"></div>   <div id="elem" class="sm-box" onclick="giterdone(this)"></div> </div> </body> 

so yeah js , css not playing nice together. reason js pulling element in blank opacity, , breaking hover opacity effect afterwards.

let's see if understand seek here:

you want div in nature opacity 1. when hover on it, want jump opacity 0.9. if click it, should fade away. if click again should fade in again.

first problem see that, probably, hover css definition , js execution not comunicating well, because hover not event on javascript event model, js code, once click, div has opacity 1.

to fix i'd use mousemove events switch between opacity 1 , 0.9


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -