将Javascript变量发送到.css({transform:translate(var,var)}) [英] send Javascript variable to .css({transform: translate (var,var)})

查看:75
本文介绍了将Javascript变量发送到.css({transform:translate(var,var)})的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过transform属性将div向右移动136px,所以我写道: `

I wanted to move a div 136px to right with transform property so i wrote: `

$(".the_div").css({"transform":"translate(136px,0px)"});

并且the_div类包含

and the_div class contains

.the_div
{
  transition-duration:2s;
}

,它起作用了,但是现在我想发送一个javascript变量而不是136px. 那可能吗?我怎样才能做到这一点? 像

and it worked but now i want to send a javascript variable instead of 136px. is that possible? how can i do that? a variable like

var my_width = window.innerwidth * 0.1;

我写了

$(".the_div").css({"transform":"translate(my_width+'px',0px)"});

,它显然没有用. 您是否有想法将div的十分之一屏幕宽度向右移动(使用transform属性)?

and it obviously didnt work. do you have an idea to move a div One-tenth of screen width to right (using transform property)?

推荐答案

只需在javascript " + my_width + "

simply you just need concatenate variable in string in javascript " + my_width + "

$(".the_div").css({"transform":"translate(" + my_width + "px,0px)"});

这篇关于将Javascript变量发送到.css({transform:translate(var,var)})的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆