Working with CSS, top propery in JQuery

前端 未结 3 1183
余生分开走
余生分开走 2021-01-29 10:52

I want to change top position of class bbb after 100 ms, but it took out that .css(top) does not work.

Please help.



&l         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 11:43

    Just like @jhpratt mentioned. You need to add position:relative to the .bbb class.

    See below.

    $(function myFunction() {
      setTimeout(alertFunc, 500);
    });
    
    function alertFunc() {
      var b = $('.bbb').first();
      b.css('top', 100 + 'px');
    }
    .bbb {
      position: relative;
      border: 1px solid red;
    }
    
    
    
    Bobobo

提交回复
热议问题