Как создать перетаскивание в стиле iOS, используя Hammer JS и CSS? - PullRequest
1 голос
/ 11 февраля 2020

Я пытаюсь создать модальную таблицу iOS 'style', которая будет всплывать, а затем пользователи могут перетащить ее вниз, и модальная таблица будет следовать жесту касания пользователя, а затем исчезнет с экрана, используя Hammer JS.

Мне удалось создать модальный лист, и я в некоторой степени реализовал Hammer JS.

Когда пользователь «смахивает» вниз по модальному листу , он исчезнет, ​​но не будет следовать жесту смахивания / прикосновения, пока не скрылся. это просто исчезает, что делает его немного неуклюжим.

$(document).on('click', '.button', function() {
  $('.addreFinder').css('bottom', '0');
  $('.sheet-backdrop').addClass('backdrop-in');
});

///custom modal sheet///
$('.c-modal').each(function() {
  var mc = new Hammer(this);

  mc.get('swipe').set({
    direction: Hammer.DIRECTION_ALL
  });

  mc.on("swipedown", function(ev) {
    console.log('dragged');
    $('.modal-in').css('bottom', '-1850px');
    $('.sheet-backdrop').removeClass('backdrop-in');
  });
});
.sheet-modal.modal-in {
  position: absolute;
  bottom: -1850px;
  left: 0;
  width: 100%;
  padding: 20px;
  transition: bottom 300ms cubic-bezier(0.17, 0.04, 0.03, 0.94);
  display: block;
  transform: translate3d(0, 0, 0);
  z-index: 13200;
}

.sheet-modal.modal-in,
.sheet-modal.modal-out {
  transition-duration: .3s;
}

.demo-sheet-swipe-to-close,
.demo-sheet-swipe-to-step {
  --f7-sheet-bg-color: #fff;
  --f7-sheet-border-color: transparent;
  border-radius: 15px 15px 0 0;
  overflow: hidden;
}

.sheet-modal {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 60%;
  display: none;
  box-sizing: border-box;
  transition-property: transform;
  transform: translate3d(0, 100%, 0);
  background: var(--f7-sheet-bg-color);
  z-index: 12500;
  will-change: transform;
}

.swipe-handler {
  height: 16px;
  position: absolute;
  left: 0;
  width: 100%;
  top: 0;
  background: #fff;
  cursor: pointer;
  z-index: 10;
}

.page-content {
  will-change: scroll-position;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
  height: 100%;
  position: relative;
  z-index: 1;
  padding-top: calc(var(--f7-page-navbar-offset, 0px) + var(--f7-page-toolbar-top-offset, 0px) + var(--f7-page-subnavbar-offset, 0px) + var(--f7-page-searchbar-offset, 0px) + var(--f7-page-content-extra-padding-top, 0px));
  padding-bottom: calc(var(--f7-page-toolbar-bottom-offset, 0px) + var(--f7-safe-area-bottom) + var(--f7-page-content-extra-padding-bottom, 0px));
}

.swipe-handler:after {
  content: '';
  width: 36px;
  height: 6px;
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -18px;
  margin-top: -3px;
  border-radius: 3px;
  background: #666;
}

.block-title-large {
  font-size: 20px;
  color: #000;
  line-height: 40px;
  padding: 10px;
  margin-top: 20px;
}

.block {
  box-sizing: border-box;
  position: relative;
  z-index: 1;
  color: #000;
  padding: 10px;
}

.sheet-backdrop.backdrop-in {
  visibility: visible;
  opacity: 1;
}

.sheet-backdrop {
  z-index: 11000;
}

.actions-backdrop,
.custom-modal-backdrop,
.dialog-backdrop,
.popover-backdrop,
.popup-backdrop,
.preloader-backdrop,
.sheet-backdrop {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, .4);
  z-index: 13000;
  visibility: hidden;
  opacity: 0;
  transition-duration: .4s;
}

.bbody {
  width: 100%;
  box-sizing: border-box;
  margin-top: 50px;
}

.wrapper {
  text-align: center;
  position: relative;
  height: 80px;
  font-size: 0;
  top: 50%;
  transform: translateY(-50%);
}

.search {
  padding: 0 30px;
  font-size: 18px;
  width: 80%;
  max-width: 400px;
  height: 80px;
  border: 1px solid #b3b3b3;
  border-radius: 20px 0 0 20px;
  box-sizing: border-box;
  font-size: 13px;
  vertical-align: top;
  display: inline-block;
}

.submit {
  cursor: pointer;
  border: none;
  background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADgCAMAAADCMfHtAAAAh1BMVEUAAAD////5+fn19fXw8PDJycn8/Py/v7/o6OjX19f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UvpOcKlLyTwis1caDAn2DCq+E39nmW1Nz+lmaEtn9dDNexLmyMR7pd9/G/B/5A7/xej9tXzU7g4v24+ioDOF/jZiQZG+2BP8AAAAASUVORK5CYII=') no-repeat center center, #1e1e20;
  background-size: 35px 35px;
  border-radius: 0 20px 20px 0;
  padding: 15px 25px;
  display: inline-block;
  width: 20%;
  height: 80px;
  box-sizing: border-box;
  font-size: 13px;
  vertical-align: top;
}

.pac-container {
  width: 100%;
}

.pac-item {
  cursor: pointer;
  padding: 0 4px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  line-height: 30px;
  vertical-align: middle;
  text-align: left;
  border-top: 1px solid #e6e6e6;
  color: #999;
  width: 100%;
}

.pac-icon {
  width: 15px;
  height: 20px;
  margin-right: 7px;
  margin-top: 6px;
  display: inline-block;
  vertical-align: top;
  background-image: url(https://maps.gstatic.com/mapfiles/api-3/images/autocomplete-icons.png);
  background-size: 34px;
}

.pac-icon-marker {
  background-position: -1px -161px;
}

.addressFinderTexts>* {
  margin-top: 10px;
}

.addressFinderTexts p {
  font-size: 12px;
}

.useMyCureentLOcationBtn {
  width: 80%;
  height: 25px;
  line-height: 25px;
  display: inline-block;
  background: #ffaf06;
  color: #fff;
  font-size: 12px;
  margin-top: 15px;
  overflow: hidden;
}

.addressFinderTexts {
  width: 100%;
  margin-top: 20px;
  min-height: 380px;
  height: auto;
  text-align: center;
  padding: 10px;
  box-sizing: border-box;
  color: #ccc;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.js"></script>
<div class="sheet-backdrop"></div>
<div class="c-modal sheet-modal demo-sheet-swipe-to-close modal-in addreFinder" id="addressFinder">
  <div class="sheet-modal-inner">
    <div class="swipe-handler"></div>
    <div class="page-content">
      <div class="block">
        <div class="bbody">
          Drag me down to hide me
        </div>
      </div>
    </div>
  </div>
</div>
<button class="button">Click Here To show modal</button>

Надеюсь, я правильно объяснил ситуацию, чтобы кто-то смог мне помочь.

...