【VUE】@click加上v-bind绑定切换类名及动画事件
好长的名字。。。
效果是 点击元素,通过改变类名的方式让其改变颜色+移动动画效果,这里用的是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绑定切换类名及动画事件的更多相关文章
- Vue中,给当前元素添加类名移除兄弟元素类名的方法
在Vue中,给当前元素添加类名移除兄弟元素类名的方法 今天在项目中需要做一个效果,点击对应的li改变当前的color,其他的li取消颜色,在jQuery中这很容易,由于之前已经引入了jQuery,所以 ...
- 黑马vue---46、vue使用过渡类名实现动画
黑马vue---46.vue使用过渡类名实现动画 一.总结 一句话总结: vue动画的过渡类名的时间点中没有设置样式的话就是默认的样式 使用 transition 元素,把 需要被动画控制的元素,包裹 ...
- jquery中bind()绑定多个事件
bind()绑定事件 $(selector).bind(event,data,function): 参数event为事件名称(如"click,mouseover....."),da ...
- 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合
[源码下载] 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合 作 ...
- 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧
[源码下载] 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧 作者:webabcd 介绍背水一战 Wind ...
- 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧
背水一战 Windows 10 之 绑定 x:Bind 绑定 x:Bind 绑定之 x:Phase 使用绑定过程中的一些技巧 示例1.演示 x:Bind 绑定的相关知识点Bind/BindDemo.x ...
- 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合
背水一战 Windows 10 之 绑定 通过 Binding 绑定对象 通过 x:Bind 绑定对象 通过 Binding 绑定集合 通过 x:Bind 绑定集合 示例1.演示如何通过 Bindin ...
- vue 如何在循环中绑定v-model
vue 如何在循环中绑定v-model 我现在有这么一个需求,页面上有多项输入框,但是具体有多少项,我也不知道,它是通过"新增一项"按钮点击事件,点击一下,就新增一项:如下图这个样 ...
- 第11课 std::bind和std::function(2)_std::bind绑定器
1. 温故知新:std::bind1st和std::bind2nd (1)bind1st.bind2nd首先它们都是函数模板,用于将参数绑定到可调用对象(如函数.仿函数等)的第1个或第2个参数上. ( ...
随机推荐
- c/c++ 动态申请数组(转载)
转载:http://blog.csdn.net/hondely/article/details/6779887 转载:http://bbs.csdn.net/topics/390721031 转载:h ...
- linux网络编程--网络编程的基本函数介绍与使用【转】
本文转载自:http://blog.csdn.net/yusiguyuan/article/details/17538499 我们深谙信息交流的价值,那网络中进程之间如何通信,如我们每天打开浏览器浏览 ...
- Leetcode ——Partition Equal Subset Sum
Question Given a non-empty array containing only positive integers, find if the array can be partiti ...
- 1、webpack编译打包Sass编译的css进js文件
cnpm install css-loader --save-dev //css-loader 是将css打包进js cnpm install style-loader --save-dev ...
- C#学习笔记(九):函数、代码查询和调试
代码查询和调试 代码查询 using System; using System.Collections.Generic; using System.Linq; using System.Text; u ...
- 【java工具类】java做的一个xml转Excel工具,基于maven工程
说明:适合数据库导出为xml时转成Excel 本工具将上传至GitHub:https://github.com/xiaostudy/xiaostudyAPI3 doc4j的maven依赖 <!- ...
- POJ 2152 Fire(树形dp)
http://poj.org/problem?id=2152 题意: n个节点组成的树,要在树一些点上建立消防站,每个点建站都有个cost[i],每个点如果不在当前的点上建站,也要依赖其他的消防站,并 ...
- 使用wsHttpBinding构建Message安全模式和UserName授权
http://www.cnblogs.com/artech/archive/2011/05/22/authentication_01.html https://www.cnblogs.com/Fran ...
- C#删除和清空文件夹的程序
/// <summary> /// 清空指定的文件夹,但不删除文件夹 /// </summary> /// <param name="dir"> ...
- 【NOI2013】树的计数
Description 我们知道一棵有根树可以进行深度优先遍历(DFS)以及广度优先遍历(BFS)来生成这棵树的DFS序以及BFS序.两棵不同的树的DFS序有可能相同,并且它们的BFS序也有可能相同, ...