好长的名字。。。

效果是 点击元素,通过改变类名的方式让其改变颜色+移动动画效果,这里用的是v-bind和@click

废话不说 show me the code!

  <div id="app">
<div>
<p :class='isOk?classA:classB' @click='ooo2()'>这是一个神奇的网站</p>
</div>
</div>

:class是 v-bind:class的缩写,给class绑定上事件,然后通过三元表达式判断事件

idOk是一个标志位,类似于第二篇博文写的flag,是判断符。

那么问题来了,它是怎么判断的呢?当时写 时候本来想在oo2()这个函数里写

//isOk?this.style.className='redd':this.className='blue'

非常辣鸡的写法。。。不知道是什么脑回路 判断要绑定在class上 用click判断isOK的值是真是假

var newv = new Vue({
el:'#app',
data:function (){
return {isOk:false, classA:'redd',classB:'blue'}
},
methods:{
ooo2:function (){ this.isOk = !this.isOk
//isOk?this.style.className='redd':this.className='blue'
console.log(this.isOk)
}
}
})

值得注意的是 data里面是给属性赋值,在methods方法里面才能调用到它。因为我刚上手vue,还没摸清楚什么里面写什么。。所以一开始就这几行代码搞了半天,尴尬惹

这里是动画样式

    .redd{
color:red;
font-size: 24px;
position: absolute;
top:;
/*transition:all 1s ease;*/
animation:mymove 1s;
animation-fill-mode:forwards; } @keyframes mymove {
from{left:0px;}
to{left:100px;}
} .blue{
color: blue;
font-size: 16px;
position: absolute;
top:;
animation:mymove2 1s;
animation-fill-mode:forwards;
} @keyframes mymove2 {
from{left: 100px}
to{left:0px}
}

【VUE】@click加上v-bind绑定切换类名及动画事件的更多相关文章

  1. Vue中,给当前元素添加类名移除兄弟元素类名的方法

    在Vue中,给当前元素添加类名移除兄弟元素类名的方法 今天在项目中需要做一个效果,点击对应的li改变当前的color,其他的li取消颜色,在jQuery中这很容易,由于之前已经引入了jQuery,所以 ...

  2. 黑马vue---46、vue使用过渡类名实现动画

    黑马vue---46.vue使用过渡类名实现动画 一.总结 一句话总结: vue动画的过渡类名的时间点中没有设置样式的话就是默认的样式 使用 transition 元素,把 需要被动画控制的元素,包裹 ...

  3. jquery中bind()绑定多个事件

    bind()绑定事件 $(selector).bind(event,data,function): 参数event为事件名称(如"click,mouseover....."),da ...

  4. 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合

    [源码下载] 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合 作 ...

  5. 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧

    [源码下载] 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧 作者:webabcd 介绍背水一战 Wind ...

  6. 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧

    背水一战 Windows 10 之 绑定 x:Bind 绑定 x:Bind 绑定之 x:Phase 使用绑定过程中的一些技巧 示例1.演示 x:Bind 绑定的相关知识点Bind/BindDemo.x ...

  7. 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合

    背水一战 Windows 10 之 绑定 通过 Binding 绑定对象 通过 x:Bind 绑定对象 通过 Binding 绑定集合 通过 x:Bind 绑定集合 示例1.演示如何通过 Bindin ...

  8. vue 如何在循环中绑定v-model

    vue 如何在循环中绑定v-model 我现在有这么一个需求,页面上有多项输入框,但是具体有多少项,我也不知道,它是通过"新增一项"按钮点击事件,点击一下,就新增一项:如下图这个样 ...

  9. 第11课 std::bind和std::function(2)_std::bind绑定器

    1. 温故知新:std::bind1st和std::bind2nd (1)bind1st.bind2nd首先它们都是函数模板,用于将参数绑定到可调用对象(如函数.仿函数等)的第1个或第2个参数上. ( ...

随机推荐

  1. WebSocket协议详解

    转自 http://www.cnblogs.com/lizhenghn/p/5155933.html 1. websocket 是什么 websocket 是html5提出的一个协议规范,参考rfc6 ...

  2. linux django 知识点 安装mysql数据库 和 pycharm

     django 命令及相关知识点 1. 启动 pycharm 命令:sh pycharm.sh 2. 创建 django 项目 : django-admin.py startproject Hello ...

  3. Beetl模板引擎入门教程

    最近项目中有个邮件发送的需求,不过要求发送的HTML格式的邮件.由于Beetl对java语言的良好支持和很好的性能,我们决定使用Beetl作为我们的模板引擎. Beetl官网已经有了很详细的教程,所以 ...

  4. SQL NULL

    表 select CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name= 'Alliance' selec ...

  5. js键盘按钮keyCode及示例大全

    以功能区分布 以 keycode 编号顺序分布 keycode 0 = keycode 1 = keycode 2 = keycode 3 = keycode 4 = keycode 5 = keyc ...

  6. HDU 2546 饭卡(0-1背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=2546 题意: 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金 ...

  7. codeforces 352 div 2 C.Recycling Bottles 贪心

    C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. c++ 判断数组元素是否都是奇数(all_of)

    #include <iostream> // std::cout #include <algorithm> // std::all_of #include <array& ...

  9. Linux 设置定时任务 清空日志

    Step 1:前提是linux服务器安装了crond 定时任务需要crond服务的支持 1.启动方法 service crond restart 2.该服务默认是开机启动的 取消定时任务 1.全部取消 ...

  10. Ubuntu 添加,删除ppa

    PPA,英文全称为 Personal Package Archives,即个人软件包档案.是 Ubuntu Launchpad 网站提供的一项源服务,允许个人用户上传软件源代码,通过 Launchpa ...