当前位置:  开发笔记 > 编程语言 > 正文

如何使用Scroll top方法

如何解决《如何使用Scrolltop方法》经验,为你挑选了0个好方法。

滚动标题应按照jQuery中的指示滑动/向上滑动,但是,在移动iOS中,这不会发生并且标题在屏幕顶部抖动?

这适用于大型浏览器上的Chrome,Mozilla Firefox,Internet Explorer和Safari.

这是因为滚动顶部方法的错误使用而发生的吗?我该如何纠正?

jQuery(document).ready(function ($) {
var lastScrollTop = 0;
$(window).scrollTop(0);

$(window).on('scroll', function() {
    var header = $('header');
    var content = $('content');
    var headerBg = $('.header-bg');
    var headerCnt = $('.header-content');
    var scrollTop = $(window).scrollTop();
    var dynHeaderVisible = false;
  
    if (lastScrollTop > scrollTop) {
      if (scrollTop <= 400) {
        headerBg.css("height", 0);
        headerCnt.css('color', 'white');
      } else {
        headerBg.css("height", 80);
        headerCnt.css("height", 80);
        headerCnt.css('color', 'black');
      }
    } else {
      // Down
      if (scrollTop > 350) {
        console.log ("hi");
        headerCnt.css("height", 0);
        headerBg.css("height", 0);
      }
    }
    
    lastScrollTop = scrollTop;
});

$.fn.isOnScreen = function(){
    var element = this.get(0);
    var bounds = element.getBoundingClientRect();
    return bounds.top < window.innerHeight && bounds.bottom > 0;
}
});
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  list-style: none;
  text-decoration: none;
  font-size:1em;
  font-family: Helvetica Neue, Helvetica, Arial, Sans-serif;
  }
	a {
    background:transparent;
    border:none;
    letter-spacing:0.15em;
    text-transform:uppercase;
    transition: .3s color;
	transition: .3s height;
	}


header {
  display: block;
  position: fixed;
  height: 80px;
  width: 100%;
}

header ul {
  z-index: 20;
}

.header-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: transparent;
}

.header-bg,
.header-content {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  text-align: center;
}

.header-bg {
  z-index: 100;
  color: gray;
  background-color: white;
  border-bottom: 1px solid black;
  transition: .3s height;
  height: 0;
}

.header-content {
  z-index: 200;
  transition: .3s color;
  color: white;
  background-color: transparent;
  height: 80px;
  transition: .3s height;
  overflow: hidden;
  list-style: none;
}

.logo {
    position: absolute;
    left: 47%;
	color: inherit;
    display: inline-block;
    width: 15px;
    height: 15px;
    padding: 18px;
    cursor: pointer;
    font-size:.8em;
    letter-spacing:0.05em;
	transition: .3s color;
	}


    
女女的家_747
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有