简体   繁体   English

如何在javascript中内联css

[英]How to inline css in javascript

I have used tables and aligned images in each row. 我在每一行都使用了表格和对齐的图像。 On key press I want to zoom the images at the center. 按键时我想缩放中心的图像。 Here is the link: http://fiddle.jshell.net/7Wn47/ 这是链接: http//fiddle.jshell.net/7Wn47/

I want the below code to be put in single line 我希望下面的代码放在一行

image1.style.width="600px";
image1.style.height="320px";
image1.style.transition="2s";

Something like: 就像是:

image1.setAttribute('style', 'width: 600px; height: 320px; translate(0,150px);z index:1;transition: 2s;transition-delay: 4s');  

But this is not working. 但这不起作用。 But if I use: -webkit-transform:scale(1) 但如果我使用:-webkit-transform:scale(1)

instead of: width: 600px; 而不是:宽度:600px; height: 320px; 身高:320px; it works, but doesn't overlap properly. 它有效,但没有正确重叠。

In my link: Press key 1 to zoom first image-see how it zooms Press key 2 to zoom second image- see how it zooms 在我的链接中:按键1缩放第一张图像 - 看它如何缩放按键2缩放第二张图像 - 看它如何缩放

There is a difference right? 有区别对吗?

I don't mind to stick with second one, but the bottom part of the image which is zooming is awkward(Hope it could zoom like top part of the image) 我不介意坚持使用第二个,但是缩放图像的底部是笨拙的(希望它可以像图像的顶部一样放大)

kindly help 善意的帮助

Try using cssText, incase if you try to change the css in stylesheet 如果您尝试更改样式表中的css,请尝试使用cssText

image1.style.cssText = 'width: 600px; height: 320px; 
                        translate(0,150px);z index:1;transition: 2s;transition-delay: 4s';

Incase jQuery 加入jQuery

$('#image1id').css({
  width: 600px,
  height: 320px,
  translate(0,150px),
  zIndex:1,
  transition: 2s,
  transitionDelay: 4s
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM