---
title: "jquery自定义动画"
author: "一纸红颜岂值倾尽天下"
date: "2014-10-10T10:53:50Z"
tags: ["animate", "jQuery"]
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2014-10-10T10:54:15Z"
id: 2126998
url: "https://lqis.iteye.com/blog/2126998"
---

使用jquery实现自定义动画方法

   使用animate 实现动画 

css样式

```
//定义图片属性
img{position:relative;}//定位 
```

 

 

代码

```
$(function () {

          
//            $("img").hover(function () {
//
//                $(this).animate({left:"+=2px"},200).animate({left:"-=2px"},200);
//
//            }, function () {
//
//            });
            $("img").click(function () {

                $(this).animate({left:"+=3px"},200).animate({left:"-=3px"},200);

            });
            
        });
```

 

 

html代码

```
<img src="xxxx.jpg">
```