How to center image in the specific div according to current viewport position?

前端 未结 5 2089
时光说笑
时光说笑 2021-02-14 20:37

I am trying create nice animation during loading content using ajax. I want to use display icon during reloading div with \"Content\", however I can\'t figured out is it possibl

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-14 20:53

    You do not need to do so much of scripting to assign it a position. You can do it with simple css.

    Just make the loader relative to its parent. Assign a height and width and do the following css part.

    .loader{
        position: relative;
        top: -half of the height;
        left: -half of the width;
        margin-top: 50%;
        margin-left: 50%;
    }
    

    works with every device

提交回复
热议问题