hover延迟菜单

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>hover延迟效果</title>
<style type="text/css">
*{ padding:0; margin:0; list-style:none;font-size:12px;}
.mytab { background:#FF9900; 600px; margin-top: 100px; margin-right: auto; margin-left: auto; height: 230px; }
.mytab .title li { float: left; 100px; height: 30px; line-height: 30px; text-align: center; background: #099; border: 1px solid #FFF; margin-left: 14px; margin-top: 14px; }
.mytab .content li { line-height: 200px; text-align: center; height: 200px; 600px; clear: both; }
.mytab .title li.cur { color:#000; background: #FFF; font-weight: bold; border: 1px solid #000; }
a { color:#FFF}
.mytab .title li.cur a{ color:#000;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script>
$(function(){
    $(".title li").hover(function(){
        var index = $(".title li").index($(this));
        function way(){
            $(".title li").removeClass("cur").eq(index).addClass("cur");
            $(".content li").hide().eq(index).show();
        }
        timer=setTimeout(way,500);
    },function(){
        clearTimeout(timer);
    });
});
</script>
</head>
<body>
<div class="mytab">
  <ul class="title">
    <li class="cur"><a href="#">标题1</a></li>
    <li><a href="#">标题2</a></li>
    <li><a href="#">标题3</a></li>
    <li><a href="#">标题4</a></li>
    <li><a href="#">标题5</a></li>
  </ul>
    <ul class="content">
    <li>内容1</li>
    <li style="display:none;">内容内容2</li>
    <li style="display:none;">内容内容内容3</li>
    <li style="display:none;">内容内容内容内容4</li>
    <li style="display:none;">内容内容内容内容内容5</li>
  </ul>
</div>
</body>
</html>

原文地址:https://www.cnblogs.com/lglijing/p/3363006.html