如何在css中使用jQuery变量?

tha*_*har -4 javascript css jquery

如何使用存储在var height中的值作为margin-top的值?

<script>
    $(document).ready(function(){
      var height = $(window).height() / 2;

      $("a").click(function(){

        $("#loader").css({"margin-top:", ***height});

      });

    });
</script>
Run Code Online (Sandbox Code Playgroud)

提前致谢...

Bil*_*oat 5

像这样:

<script>
    $(document).ready(function(){
      var height = $(window).height() / 2;

      $("a").click(function(){

        $("#loader").css('margin-top', height+'px');

      });

    });
</script>
Run Code Online (Sandbox Code Playgroud)

演示:http://jsfiddle.net/MtEjP/