javascript - jQuery If .hasClass, then enable .hover -


i have 2 divs: .left , .right.

what want, when .active class isn't linked these divs, enable .hover function. if:

if (!($("#panel-left").hasclass("active") || $("#panel-right").hasclass("active"))) {} 

but doesn't work, if change condition true, or false, script doesn't realize . looks remembers value of condition page load, not changes after that.

if (!($("#panel-left").hasclass("active") || $("#panel-right").hasclass("active"))) {          $(".left").hover(function(){              $(".left").css("margin-left", "-10%");              }, function(){              $(".left").css("margin-left", "-50%");          });          $(".left").hover(function(){              $(".right").css("margin-left", "90%");              }, function(){              $(".right").css("margin-left", "50%");          });          //animace praveho panelu          $(".right").hover(function(){              $(".left").css("margin-left", "-90%");              }, function(){              $(".left").css("margin-left", "-50%");          });          $(".right").hover(function(){              $(".right").css("margin-left", "10%");              }, function(){              $(".right").css("margin-left", "50%");          });      }            $(".left").click(function () {          $(".left").addclass("active");          $(".right").removeclass("active");          $(".left").css("margin-left", "-10%");          $(".right").css("margin-left", "90%");                });      $(".right").click(function () {          $(".right").addclass("active");          $(".left").removeclass("active");          $(".left").css("margin-left", "-90%");          $(".right").css("margin-left", "10%");      });
body {     line-height: 1;     overflow-x: hidden;  }  html,body, input, textarea{      height: 100%;  }    .container{      width: 100%;      height: 100%;      background-color: aqua;     }           .half{          display: inline;          position: absolute;          width: 100%;          height: 100%;          transition-duration: .5s;          transition-timing-function: ease-in-out;      }            .left{          margin-left: -50%;          background-color: antiquewhite;      }      .right{          margin-left: 50%;          background-color: cadetblue;      }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="container">              <div class="half left" id="panel-left">                                </div>              <div class="half right" id="panel-right">                                </div>          </div>

goal:

hover works, when page loaded, once click on 1 of these divs,

$(".right").click(function () {   $(".right").addclass("active"); }); 

so in logic, .active added .right, hover wouldn't work anymore... does.

function clicked() {   var bool = ($("#panel-left").hasclass("active") || $("#panel-right").hasclass("active"));   return bool;   }  $(".left").hover(function() {   if (!clicked()) ;     $(".left").css("margin-left", "-10%"); }, function() {   if (!clicked())     $(".left").css("margin-left", "-50%"); }); $(".left").hover(function() {   if (!clicked())     $(".right").css("margin-left", "90%"); }, function() {   if (!clicked())     $(".right").css("margin-left", "50%"); }); //animace praveho panelu $(".right").hover(function() {   if (!clicked())     $(".left").css("margin-left", "-90%"); }, function() {   if (!clicked())     $(".left").css("margin-left", "-50%"); }); $(".right").hover(function() {   if (!clicked())     $(".right").css("margin-left", "10%"); }, function() {   if (!clicked())     $(".right").css("margin-left", "50%"); });   $(".left").click(function() {   $(".left").addclass("active");   $(".right").removeclass("active");   $(".left").css("margin-left", "-10%");   $(".right").css("margin-left", "90%");  }); $(".right").click(function() {   $(".right").addclass("active");   $(".left").removeclass("active");   $(".left").css("margin-left", "-90%");   $(".right").css("margin-left", "10%"); }); 

can optimized, @ least want. hope helps, , luck!


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -