当前位置:   article > 正文

div 实现上拉固定在顶部_div上拉

div上拉
 //导航上拉固定
        var scro
        navdaohan = function (id, obj) {
            console.log("开启监听置顶")
            var obj = document.getElementById(id)
            var T = obj.offsetTop;
            while (obj = obj.offsetParent) {
                T += obj.offsetTop;
            }
            scro = T
        }
        navscriogundon = function (id, scro) {
            var obj = document.getElementById(id)
            var scrotop = document.documentElement.scrollTop || document.body.scrollTop
            if (scrotop > scro - 120) {
                obj.style.position = "fixed"
                obj.style.top = "120px"
                var czid = document.getElementById('tmdtid')
                if (!czid) {
                    var div = document.createElement('div')
                    div.style.height = "201px"
                    div.id = "tmdtid"
                    $("#like_shop").prepend(div)
                }
            } else {
                obj.style.position = "relative"
                obj.style.top = "0"
                $("#tmdtid").remove()
            }
        }
        navdaohan("tm_shousuo_nav")
        
        window.onscroll = function () {           
            navscriogundon("tm_shousuo_nav", scro)

        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/1009010
推荐阅读
相关标签
  

闽ICP备14008679号