Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery CSS assigning negative values

This is my jQuery code:

<script type="text/javascript" src="js/jquery.js">
</script>
<script type="text/javascript">
 $(document).ready(function() {
     get_font_size();
     set_sidebar();

});
function get_font_size()
{
var b=$(window).width();
var side_size=b*260/1440;
b=b-side_size;
$("#sidebar").css({"width":side_size});
$("#alexa-widget img").css({"width":side_size});
$(".fb-like-box").attr("data-width",side_size); 
}
function set_sidebar()
{
var b=$(window).width();
var font_size=b*65/1440;
var font_size_2=b*133/1440;
var margin_top=b*10/1440;
margin_top*=-1;
margin_top=Math.round(margin_top);
$("#my_tabs li").css({"font-size":font_size});
$("#header").css({"font-size":font_size_2,"margin-top":margin_top});

}
</script>

Everything works fine except the margin-top property.I can't assign margin-top to a negative value.It fails but font size and other properties work's fine.Why jquery css settings fails with negative values?If I do the the same inside css it work's perfect.I need this to alter the webpage according to screen resolutions So I can't do that inside CSS.I need jQuery fix for this.I already have viewport meta tag in my code so please don't suggest viewport or media query solutions.I have checked the margin_top variable with alert(margin_top) and it shows me a correct negative value as desired so the calculation takes place correctly only the css setting part fails.Please help me fix this.Thank You.

like image 433
user1613360 Avatar asked Sep 13 '26 13:09

user1613360


1 Answers

What's wrong with doing it like this?

$('div').css({marginTop:-100});​

Not everything needs to be stringly typed.

like image 116
Jezen Thomas Avatar answered Sep 16 '26 02:09

Jezen Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!