Align background image middle and center

后端 未结 4 1190
予麋鹿
予麋鹿 2021-01-24 06:38

Here\'s the html:


      
4条回答
  •  孤独总比滥情好
    2021-01-24 07:12

    Use a simple JQuery fn called center ( Usage: $(element).center() ):

         jQuery.fn.center = function() {
            this.css("position","absolute");
            this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
            this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
            this.css("bottom", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
            return this;
          }
        $(document).ready(function(){
    $(#imgUtility).center();
    )};
    

    With the HTML:

     
    

提交回复
热议问题