Javascript 更改按键上的css样式。(Vue.js)
我希望每当用户按下某个键绑定时,该元素的css样式的值就会改变Javascript 更改按键上的css样式。(Vue.js),javascript,css,vue.js,Javascript,Css,Vue.js,我希望每当用户按下某个键绑定时,该元素的css样式的值就会改变 <textarea id="check" v-model="text" v-on:keydown.ctrl.up="decreaseFont" > 这是我的CSS div textarea { position: relative; font-size: $fontSize; color: white; height: 100
<textarea id="check"
v-model="text"
v-on:keydown.ctrl.up="decreaseFont"
>
这是我的CSS
div textarea {
position: relative;
font-size: $fontSize;
color: white;
height: 100vh;
width: 100%;
outline: none;
border: none;
margin: 0;
padding: 0;
resize: none;
font-family: "Courier New", Courier, monospace;
}
另外,我希望textview能够在没有滚动条的情况下显示整个屏幕。这就是为什么我用100vh作为高度。但我仍然得到一个滚动条
我将正文的边距和填充重置为0
使用
var-app=新的Vue({
el:“#应用程序”,
数据:{
文本:“”,
字体大小:空
},
方法:{
decreaseFont(){
这个.fontSize--;
}
},
已创建:函数(){
var el=document.getElementById('check');
var style=window.getComputedStyle(el,null).getPropertyValue('font-size');
this.fontSize=parseFloat(样式);
}
})
divtextarea{
位置:相对位置;
字体大小:16px;
高度:100vh;
宽度:100%;
保证金:0;
填充:0;
调整大小:无;
字体系列:“Courier New”,Courier,monospace;
}
使用
var-app=新的Vue({
el:“#应用程序”,
数据:{
文本:“”,
字体大小:空
},
方法:{
decreaseFont(){
这个.fontSize--;
}
},
已创建:函数(){
var el=document.getElementById('check');
var style=window.getComputedStyle(el,null).getPropertyValue('font-size');
this.fontSize=parseFloat(样式);
}
})
divtextarea{
位置:相对位置;
字体大小:16px;
高度:100vh;
宽度:100%;
保证金:0;
填充:0;
调整大小:无;
字体系列:“Courier New”,Courier,monospace;
}
看看:
<template>
<div>
<textarea
id="check"
v-model="text"
v-on:keydown.enter="decrease = decrease-1"
:style="{'font-size': decrease+'px'}"
/>
</div>
</template>
<script>
export default {
name: "HelloWorld",
data() {
return {
text: null,
decrease: 30
};
}
};
</script>
<style>
body {
margin: 0;
}
</style>
<style scoped>
div textarea {
position: relative;
color: black;
height: 99vh;
width: 100%;
outline: none;
border: none;
overflow: hidden;
margin: 0;
padding: 0;
resize: none;
font-family: "Courier New", Courier, monospace;
}
</style>
导出默认值{
名称:“HelloWorld”,
数据(){
返回{
文本:空,
减少:30
};
}
};
身体{
保证金:0;
}
分区文本区{
位置:相对位置;
颜色:黑色;
高度:99vh;
宽度:100%;
大纲:无;
边界:无;
溢出:隐藏;
保证金:0;
填充:0;
调整大小:无;
字体系列:“Courier New”,Courier,monospace;
}
我创建了一个,这样你可以看看它是如何工作的
请注意,出于演示目的,我在[code>enter键上更改了字体大小。看看:
<template>
<div>
<textarea
id="check"
v-model="text"
v-on:keydown.enter="decrease = decrease-1"
:style="{'font-size': decrease+'px'}"
/>
</div>
</template>
<script>
export default {
name: "HelloWorld",
data() {
return {
text: null,
decrease: 30
};
}
};
</script>
<style>
body {
margin: 0;
}
</style>
<style scoped>
div textarea {
position: relative;
color: black;
height: 99vh;
width: 100%;
outline: none;
border: none;
overflow: hidden;
margin: 0;
padding: 0;
resize: none;
font-family: "Courier New", Courier, monospace;
}
</style>
导出默认值{
名称:“HelloWorld”,
数据(){
返回{
文本:空,
减少:30
};
}
};
身体{
保证金:0;
}
分区文本区{
位置:相对位置;
颜色:黑色;
高度:99vh;
宽度:100%;
大纲:无;
边界:无;
溢出:隐藏;
保证金:0;
填充:0;
调整大小:无;
字体系列:“Courier New”,Courier,monospace;
}
我创建了一个,这样你可以看看它是如何工作的
请注意,出于演示目的,我在
enter
键上更改了字体大小