yp秋水伊人

导航

Jquery--动画

 

动画:

1、show(),hide()

2、.stop() .slideDown();  向下。 .stop().slideUp();  向上 (可以做下拉)        .stop() 执行之前加 停止

<script type="text/javascript">
$("#div1").hover(function () {/*复合事件 移入移出*/
$("#div2").stop() .slideDown();
}, function () {
$("#div2").stop().slideUp();
});
</script>

3、.fadeIn();    .fadeOut();  淡入淡出效果

4、自定义动画:

animate({left:"300px",top:"300px"....},1000,function(){回调函数});   1000指的是 时间(秒)

停止动画,防止动画积累, .stop(true)  不加true也可

<script type="text/javascript">
$("#div2").click(function () {
$(this).animate({ left: "600px", top: "300px" }, 1000, function () {
$(this).css("background-color","red"); 移动指定位置变成红色
});
});
</script>

 

实例:下拉菜单

<style type="text/css">
        .div {
        position:relative;
        width:120px;
        height:60px;
        overflow:hidden;/*超出部分隐藏*/
        float:left;
        margin-left:10px;
        }
        .div1 {
        position:relative;
        width:120px;
        height:60px;
        background-color:red;
       
        }
        .div2 {
        position:relative;
        width:120px;
        height:400px;
        background-color:green;
       /*display:none;隐藏*/
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div class="div">
           <div class="div1">   </div>
           <div class="div2"></div>
        </div>
        <div class="div">
           <div class="div1">   </div>
           <div class="div2"></div>
        </div>
       
        <div class="div">
           <div class="div1">   </div>
           <div class="div2"></div>
        </div>
        

    </form>
</body>
</html>
<script type="text/javascript">
    $(".div").hover(function () {
        $(this).stop().animate({height:"460px"},500);
    }, function () {
        $(this).stop().animate({ height:"60px"}, 500);
    });
</script>

 

大图滚动:

 

<style type="text/css">
        .div1 {
        position:relative;
        width:400px;
        height:400px;
        left:100px;
        background-color:red;
        overflow:hidden;
        }
        #datu {
        position:relative;
        width:1600px;
        height:100%;
        }
            #datu img {
            position:relative;
            float:left;
          width:400px;
          height:400px;
            
            }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="div1">
        <div id="datu">
            <img src="Images/dota_chenmo1.jpg" />
            <img src="Images/dota_img3.jpg" />
            <img src="Images/dota_img4.jpg" />
            <img src="Images/dota_img5.jpg" />
        </div>
    </div>
    </form>
</body>
</html>
<script type="text/javascript">
    var count = 0;/*定义一个数为0,每点击一下就是下一张图*/
   
      var time1=  window.setInterval(function () {/*自动换图,每隔两秒*/
            count++;/*加1,加1...*/
            if (count >= 4)/*判断到了第四张再从第一张走*/ {
                count = 0;
            }
            var pxx = count * -400;/*定义一个数,左边多少*/
            $("#datu").animate({ left: pxx }, 1000);
        }, 2000);
      $(".div1").mouseover(function () {
          window.clearInterval(time1);
      });
     
      
</script>

 

 

 

<script type="text/javascript">
    var count = 0;
    $("#div1").click(function () {
        count++;
        $("#datu").animate({ left: count * -400 }, 500, function () {
            if (count >= 4) {
                count = 0;
                $("#datu").css("left","0");
            }
        });
    });
   
</script>

 

 

 移入图片变大:

<style type="text/css">
        #div1 {
        width:100px;
        height:100px;
        background-color:red;
        
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="div1"></div>
    </form>
</body>
</html>
<script type="text/javascript">
    $("#div1").hover(function () {//鼠标移入图变大并且渐变色,先引入Color包引入,必须放到下面
        $(this).animate({width:"300",height:"300",backgroundColor:"green"},500);
    }, function () {
        $(this).animate({ width: "100", height: "100", backgroundColor: "red" }, 500);
    });
</script>

 

posted on 2016-10-21 15:52  yp秋水伊人  阅读(264)  评论(0编辑  收藏  举报