>  기사  >  php教程  >  인터레이스 색상 변경 효과를 얻는 두 가지 방법 [실용]

인터레이스 색상 변경 효과를 얻는 두 가지 방법 [실용]

高洛峰
高洛峰원래의
2016-12-05 09:43:221383검색

인터레이스 색상 교대를 구현하는 순수 CSS 방법, 강조 색상 위에 마우스를 놓음:

<html>
<head>
 <title></title>
 <style type="text/css">
 ul{list-style:none}
 
 li:nth-child(odd){background-color:#eee}
 li:hover{background-color:Yellow}
 </style>
</head>
<body>
 <ul>
 <li>111</li>
 <li>111</li>
 <li>111</li>
 <li>111</li>
 <li>111</li>
 <li>111</li>
 <li>111</li>
 </ul>
</body>
</html>

인터레이스 색상 교대를 구현하는 js 방법, 강조 색상 위에 마우스를 얹음:

<html>
<head>
 <title></title>
 <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
 <style type="text/css">
 .alter-item {
  background-color: #eee;
 }
 
 .hightlight {
  background-color: Yellow;
 }
 </style>
 
 <script type="text/javascript">
 $(function () {
  //隔行颜色
  $("ul li:odd").addClass("alter-item");
 
  method1();
 });
 
 //方法1:
 function method1() {
  $("ul li").hover(function () {
  $(this).addClass("hightlight");
  }, function () {
  $(this).removeClass("hightlight")
  });
 }
 
 //方法2:
 function method2() {
  $("ul li").mouseover(function () {
  $(this).addClass("hightlight").siblings().removeClass("hightlight");
  });
 }
 </script>
</head>
<body>
 <ul>
 <li>111</li>
 <li>222222222</li>
 <li>111</li>
 <li>444444444444444444444</li>
 <li>111</li>
 <li>111</li>
 <li>111</li>
 </ul>
</body>
</html>


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.