使用Javascript更改CSS参数
我有以下CSS:使用Javascript更改CSS参数,javascript,css,Javascript,Css,我有以下CSS: .makebig { -webkit-animation-name: cssAnimation; -webkit-animation-duration: 1s; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: ease; -webkit-animation-fill-mode: forwards; } @-webkit-keyframes c
.makebig {
-webkit-animation-name: cssAnimation;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease;
-webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes cssAnimation {
from {
-webkit-transform: rotate(0deg) scale(1) skew(0deg) translate(0px);
}
to {
-webkit-transform: rotate(0deg) scale(2) skew(0deg) translate(150px);
}
}
.makesmall {
-webkit-animation-name: cssAnimation1;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease;
-webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes cssAnimation1 {
from {
-webkit-transform: rotate(0deg) scale(2) skew(0deg) translate(150px);
}
to {
-webkit-transform: rotate(0deg) scale(1) skew(0deg) translate(0px);
}
}
这个Javascript:
<script>
function ani(fns1) {
if (document.getElementById('fns1').getAttribute('clicked') == 'false')
{
document.getElementById('fns1').className = 'makebig';
document.getElementById('fns1').setAttribute('clicked', true);
} else {
document.getElementById('fns1').className = 'makesmall';
document.getElementById('fns1').setAttribute('clicked', false);
}
}
</script>
功能ani(fns1){
if(document.getElementById('fns1').getAttribute('clicked')='false'))
{
document.getElementById('fns1')。className='makebig';
document.getElementById('fns1').setAttribute('clicked',true);
}否则{
document.getElementById('fns1')。className='makesmall';
document.getElementById('fns1').setAttribute('clicked',false);
}
}
该代码将对象缩放两次。如何根据对象发送不同的“缩放”参数
我用它来放大图像,并在第二次点击时转到原始比例。
我的图像在文本中具有不同的大小和位置,因此我需要使它们在屏幕中心缩放。一个选项是使用过渡而不是动画
.makebig {
transition: 1s transform ease;
}
然后,您可以使用js分别在每个元素上设置所需的端点变换,浏览器将相应地对其设置动画您可以硬编码几个css类和动画以满足您的需要:
@-webkit-keyframes scale-1 {
from {
-webkit-transform: rotate(0deg) scale(1) skew(0deg) translate(0px);
}
to {
-webkit-transform: rotate(0deg) scale(2) skew(0deg) translate(150px);
}
}
@-webkit-keyframes scale-2 {
from {
-webkit-transform: rotate(0deg) scale(2) skew(0deg) translate(0px);
}
to {
-webkit-transform: rotate(0deg) scale(3) skew(0deg) translate(150px);
}
}
#element {
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease;
-webkit-animation-fill-mode: forwards;
}
#element.scale-1 {
-webkit-animation-name: scale-1;
}
#element.scale-2 {
-webkit-animation-name: scale-1;
}
只需使用js中的类名:
element.className = 'scale-1';
// after some logic
element.className = 'scale-2';
我只使用JS和CSS,但对于IOS appgion_13,不能这样做,因为我还需要计算对象的大小、位置(向左或向右浮动)以及可能需要修改的其他参数。不确定它是否适合。我用全文修改了我的第一个问题。你觉得对我来说行吗?我是为IOS浏览器做的。我不确定我是否理解发生了什么变化。这是一把小提琴。你可以很容易地从那里推断出目标和大小的参数。这能让事情更清楚吗?