简体   繁体   English

jQuery CSS的图像左变化取决于div宽度

[英]Jquery css left change of image depending on div width

I have input which is dynamic from a JSON feed which populates a div with various names which are different in lengths. 我有一个JSON提要动态输入的内容,该JSON提要使用不同长度的各种名称填充div。

There is an image which has been set to an absolute position which cannot be changed. 存在已设置为无法更改的绝对位置的图像。 Although I need to dynamically change the CSS left value of the image to whatever the width of the dynamic text that comes in + 10px . 尽管我需要将图片的CSS左值动态地更改为+ 10px的动态文本的宽度。

var _origin_width = $('#dynamic_text').width() + $('#the_imae').width(); 

So they are side by side like so 所以他们像这样并排

Dynamic Text | Image

I'm having trouble getting this to work. 我很难让它正常工作。

Try this: 尝试这个:

//get the width of content +10 in px
var dynamic_width = $('#dynamic_text').width()+10+'px';
//now set the css
$('#the_imae').css('left',dynamic_width)

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

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