class mFooter {
    constructor() {
        this.$toTop = $('#toTop')

        this.init()
    }
    init() {
        if (toTop.length == 0) return

        this.checkScrollTop()
        this.setEvent()
    }
    setEvent() {
        this.$toTop.click(function () {
            $('html,body').animate({
                scrollTop: 0
            })
        })

        $(window).scroll(this.checkScrollTop.bind(this))
    }
    setToTop(state) {
        if (state == 'show' && this.$toTop.is(':hidden'))
            this.$toTop.show()
        else if (state == 'hide' && this.$toTop.is(':visible'))
            this.$toTop.hide()
    }
    checkScrollTop() {
        var scrollTop = document.body.scrollTop
        if (scrollTop >= 300)
            this.setToTop('show')
        else
            this.setToTop('hide')
    }
}

$(() => {
    new mFooter
})