CSS跟随鼠标效果

时间:2017-09-07 04:13:19

标签: javascript html css

如何创建鼠标跟随效果,如带有箭头的图片,箭头是线鼠标跟随对象,而红色框是效果发生的宽度。

enter image description here

1 个答案:

答案 0 :(得分:2)

我认为你在谈论这种菜单



#cssmenu ul {
  list-style: none;
  margin: 0;
  padding: 0;
  line-height: 1;
  display: block;
  zoom: 1;
}

#cssmenu ul:after {
  content: " ";
  display: block;
  font-size: 0;
  height: 0;
  clear: both;
  visibility: hidden;
}

#cssmenu ul li {
  display: inline-block;
  padding: 0;
  margin: 0;
}

#cssmenu.align-right ul li {
  float: right;
}

#cssmenu.align-center ul {
  text-align: center;
}

#cssmenu ul li a {
  color: #434351;
  text-decoration: none;
  display: block;
  padding: 15px 25px;
  font-family: 'Open Sans', sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 14px;
  position: relative;
  -webkit-transition: color .25s;
  -moz-transition: color .25s;
  -ms-transition: color .25s;
  -o-transition: color .25s;
  transition: color .25s;
}

#cssmenu ul li a:hover {
  color: #333333;
}

#cssmenu ul li a:hover:before {
  width: 100%;
}

#cssmenu ul li a:before {
  content: "";
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  height: 3px;
  width: 0;
  background: #434351;
  -webkit-transition: width .25s;
  -moz-transition: width .25s;
  -ms-transition: width .25s;
  -o-transition: width .25s;
  transition: width .25s;
}

#cssmenu ul li.last>a:after,
#cssmenu ul li:last-child>a:after {
  display: none;
}

#cssmenu ul li.active a {
  color: #434351;
}

#cssmenu ul li.active a:before {
  width: 100%;
}

#cssmenu.align-right li.last>a:after,
#cssmenu.align-right li:last-child>a:after {
  display: block;
}

#cssmenu.align-right li:first-child a:after {
  display: none;
}

@media screen and (max-width: 768px) {
  #cssmenu ul li {
    float: none;
    display: block;
  }
  #cssmenu ul li a {
    width: 100%;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    border-bottom: 1px solid #fb998c;
  }
  #cssmenu ul li.last>a,
  #cssmenu ul li:last-child>a {
    border: 0;
  }
  #cssmenu ul li a:after {
    display: none;
  }
  #cssmenu ul li a:before {
    display: none;
  }
}

<div id='cssmenu'>
  <ul>
    <li class='active'><a href='#'><span>Home</span></a></li>
    <li><a href='#'><span>Products</span></a></li>
    <li><a href='#'><span>Company</span></a></li>
    <li class='last'><a href='#'><span>Contact</span></a></li>
  </ul>
</div>
&#13;
&#13;
&#13;