开发者

jquery .css applying in chrome or FireFox

开发者 https://www.devze.com 2023-01-14 11:47 出处:网络
I am using Jquery to apply some top and left positioning. When doing so, in IE it works perfectly.Unfortunately, it doesn\'t work in Firefox or Chrome.

I am using Jquery to apply some top and left positioning.

When doing so, in IE it works perfectly. Unfortunately, it doesn't work in Firefox or Chrome.

In IE, when inspecting the code it shows inline style开发者_如何学Cs on the div for the left and top. When looking at chrome and firefox, there are no inline styles for the divs's.

Here is some code:

var offsets = $("#cssOffsets").val();           
var offsetsArray;  
offsetsArray = offsets.split(":");  
$('#lid').css({'top':offsetsArray[1],'left':offsetsArray[0]});

cssOffsets is a string like 137:10

The #lid div exists.

Any ideas on why it would actually work in IE and not the others?

I am using the latest version of Chrome and FireFox, and of JQuery.

Thanks!


I think its because you're not specifying the px value.

$('#lid').css({'top':offsetsArray[1]+'px','left':offsetsArray[0]+'px'});


Just a guess, I think you need to specify the unit: px for example. So, when you fix that, you get:

$('#lid').css({
  top: offsetsArray[1] + "px",
  left: offsetsArray[0] + "px"
});


$('#lid').offset({ top: offsetsArray[1], left: offsetsArray[0] });

The .offset() setter method allows us to reposition an element.

0

精彩评论

暂无评论...
验证码 换一张
取 消