不同分辨率手機上使盒子適中居中顯示

具體代碼如下:

//可能會產生閃爍問題,所以首先將盒子隱藏
   $(function () {

            elementCenter();
            $(window).resize(function () {
            elementCenter();
            })

            function elementCenter() {
            $('.box').click(function () {

            var height = $(window).height() - $('.box').height()

            $(this).offset({
            top: height / 2,
            }).css({
            display: 'block'
            })

            })

            $('.box').trigger("click")
            }

        })
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章