Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery mobile jQuery Mobile:使标题在向下滚动时隐藏,在向上滚动时显示_Jquery Mobile - Fatal编程技术网

Jquery mobile jQuery Mobile:使标题在向下滚动时隐藏,在向上滚动时显示

Jquery mobile jQuery Mobile:使标题在向下滚动时隐藏,在向上滚动时显示,jquery-mobile,Jquery Mobile,我们在许多移动应用程序中看到的一个常见现象是,当用户向下滚动页面时,标题消失,当他们向上滚动页面时,标题出现。我们如何在jQuery Mobile中实现这一点?(我在回答下面我自己的问题)Sean Bannisters解决方案的变体,使用Bootstrap 4和一个过渡: JS: CSS: /** * Header scroll control * When the user scrolls down the page hide the header, when they scroll up

我们在许多移动应用程序中看到的一个常见现象是,当用户向下滚动页面时,标题消失,当他们向上滚动页面时,标题出现。我们如何在jQuery Mobile中实现这一点?(我在回答下面我自己的问题)

Sean Bannisters解决方案的变体,使用Bootstrap 4和一个过渡:

JS:

CSS:

/**
 * Header scroll control
 * When the user scrolls down the page hide the header, when they scroll up show it.
 */
var lastScrollPosition;

$(document).scroll( function() {
  var scrollPosition = $(this).scrollTop();

  // Scrolling down
  if (scrollPosition > lastScrollPosition){
    // If the header is currently showing
    if (!$('[data-role=header].ui-fixed-hidden').length) {
      $('[data-role=header]').toolbar('hide');
    }
  } 

  // Scrolling up
  else {
    // If the header is currently hidden
    if ($('[data-role=header].ui-fixed-hidden').length) {
      $('[data-role=header]').toolbar('show');
    }
  }

  lastScrollPosition = scrollPosition;  
});
    var lastScrollPosition;
    var headerHeight;
    $(document).scroll( function() {
        var scrollPosition = $(this).scrollTop();
        if (scrollPosition > lastScrollPosition){ // Scrolling down
            if ($('.sticky-top.show').length) {
                $('.sticky-top').removeClass('show');
                headerHeight = -$('.sticky-top').height() + 'px';
                $('.sticky-top').css('top', headerHeight);
            }
        } else {  // Scrolling up
            if (!$('.sticky-top.show').length) {
                $('.sticky-top').addClass('show');
                $('.sticky-top').css('top', '0');
            }
        }
        lastScrollPosition = scrollPosition;
    });
.sticky-top { transition: top 0.3s; }