使用mouseenter进行水平平移,mouseleave功能不起作用

时间:2017-12-09 13:08:20

标签: javascript jquery html css

当我将鼠标悬停在列表中时,我想要将一些文本水平翻译。在这种情况下,当我将鼠标悬停在“#java”时,我想要“.java1”翻译。

$(document).ready(function() {
  $("#java").on("mouseenter", function() {
    $(".java1").transition({
      x: "+=70"
    }, 10);
  });

  $("#java").on("mouseleave", function() {
    $(".java1").transition({
      x: "-=70"
    }, 10);
  });
});
@media (min-width:601px) {
  .quarter {
    width: 24.99999%!important;
  }
  .third {
    width: 33.33333%!important;
  }
  .twothird {
    width: 66.66666%!important;
  }
}

p {
  color: #757575!important;
}

ul {
  text-align: left;
}

li {
  color: #333333!important;
  text-decoration: none;
  list-style-type: none;
  float: left;
  padding-left: 17px;
  padding-right: 17px;
  padding-bottom: 10px;
  margin-top: 3px;
  margin-right: 2px;
  height: 30px;
}

.box {
  width: 100px;
  height: 30px;
  top: 750px;
  position: absolute;
  text-align: left;
  border-radius: 5px;
  float: left;
  margin-left: -50px;
}

.box-container {
  background-color: #f1f1f1;
  color: #009688;
  padding: 5px;
}

.content {
  max-width: 980px;
  margin: auto;
}

.center {
  text-align: center!important;
}

.round-xlarge {
  border-radius: 16px;
}

.teal {
  color: #fff!important;
  background-color: #009688!important;
}

.hover-white:hover {
  color: #000!important;
  background-color: #fff!important;
}

.margin-right {  
   margin-right : 16px!important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box">
  <div class="box-container">
    <p style="text-indent: 5px;" class="java1">public</p>
    <p style="text-indent: 5px;" class="java1">static</p>
    <p style="text-indent: 5px;" class="java1">void</p>
    <p style="text-indent: 5px;" class="java1">main</p>
    <p style="text-indent: 5px;" class="java1">(String[] args)</p>
  </div>
</div>

<div class="content">
  <div class="third center">
    <div class="center">
      <ul>
        <p><i class="fa fa-asterisk margin-right teal-text"></i>My Skill Set</p>
        <li class="round-xlarge teal hover-white" style="width : 23%" id="java">Java</li>
        <li class="round-xlarge teal hover-white" style="width : 43%">Spring MVC</li>
        <li class="round-xlarge teal hover-white" style="width : 28%">HTML5</li>
        <li class="round-xlarge teal hover-white" style="width : 23%">CSS</li>
        <li class="round-xlarge teal hover-white" style="width : 40%">Javascript</li>
        <li class="round-xlarge teal hover-white" style="width : 28%">jQuery</li>
        <p>...................................................</p>
      </ul>
      <ul>
        <p><i class="fa fa-globe margin-right teal-text"></i>Language</p>
        <li class="round-xlarge teal hover-white" style="width : 30%">English</li>
        <li class="round-xlarge teal hover-white" style="width : 38%">Indonesia</li>
        <li class="round-xlarge teal hover-white" style="width : 26%">Korea</li>
      </ul>
    </div>
  </div>
</div>

这些框隐藏在负边距内,我希望它在将鼠标悬停在#java中后出现。

但是盒子不为所动。我实在无法指出脚本有什么问题?请帮助,谢谢!

1 个答案:

答案 0 :(得分:1)

您必须在jQuery中使用css方法并定位transform css属性,我正在向您发送示例

$(document).ready(function() {
  $("#java").on("mouseenter", function() {
    $(".java1").css('transform','translateX(-70px)');
  });

  $("#java").on("mouseleave", function() {
    $(".java1").css('transform','translateX(70px)');
  });
});
@media (min-width:601px) {
  .quarter {
    width: 24.99999%!important;
  }
  .third {
    width: 33.33333%!important;
  }
  .twothird {
    width: 66.66666%!important;
  }
}

p {
  color: #757575!important;
}

ul {
  text-align: left;
}

li {
  color: #333333!important;
  text-decoration: none;
  list-style-type: none;
  float: left;
  padding-left: 17px;
  padding-right: 17px;
  padding-bottom: 10px;
  margin-top: 3px;
  margin-right: 2px;
  height: 30px;
}

.box {
  width: 100px;
  height: 30px;
  top: 750px;
  position: absolute;
  text-align: left;
  border-radius: 5px;
  float: left;
  margin-left: -50px;
}

.box-container {
  background-color: #f1f1f1;
  color: #009688;
  padding: 5px;
}

.content {
  max-width: 980px;
  margin: auto;
}

.center {
  text-align: center!important;
}

.round-xlarge {
  border-radius: 16px;
}

.teal {
  color: #fff!important;
  background-color: #009688!important;
}

.hover-white:hover {
  color: #000!important;
  background-color: #fff!important;
}

.margin-right {  
   margin-right : 16px!important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box">
  <div class="box-container">
    <p style="text-indent: 5px;" class="java1">public</p>
    <p style="text-indent: 5px;" class="java1">static</p>
    <p style="text-indent: 5px;" class="java1">void</p>
    <p style="text-indent: 5px;" class="java1">main</p>
    <p style="text-indent: 5px;" class="java1">(String[] args)</p>
  </div>
</div>

<div class="content">
  <div class="third center">
    <div class="center">
      <ul>
        <p><i class="fa fa-asterisk margin-right teal-text"></i>My Skill Set</p>
        <li class="round-xlarge teal hover-white" style="width : 23%" id="java">Java</li>
        <li class="round-xlarge teal hover-white" style="width : 43%">Spring MVC</li>
        <li class="round-xlarge teal hover-white" style="width : 28%">HTML5</li>
        <li class="round-xlarge teal hover-white" style="width : 23%">CSS</li>
        <li class="round-xlarge teal hover-white" style="width : 40%">Javascript</li>
        <li class="round-xlarge teal hover-white" style="width : 28%">jQuery</li>
        <p>...................................................</p>
      </ul>
      <ul>
        <p><i class="fa fa-globe margin-right teal-text"></i>Language</p>
        <li class="round-xlarge teal hover-white" style="width : 30%">English</li>
        <li class="round-xlarge teal hover-white" style="width : 38%">Indonesia</li>
        <li class="round-xlarge teal hover-white" style="width : 26%">Korea</li>
      </ul>
    </div>
  </div>
</div>