【问题标题】:Fixed element inside Iscroll固定 Iscroll 内的元素
【发布时间】:2018-05-30 03:29:29
【问题描述】:

我有一个很大的 Iscroll 页面。我无法使用位置修复元素:如果它在 Iscroll 内,则已修复。我想这与 Iscroll 正在实施的过渡有关。有人遇到过吗?

我想修复“FIXTHIS”元素。但不幸的是,它会随着内容滚动。

JS 小提琴:https://jsfiddle.net/10amw389/1/

<div id="wrapper">
<div id="scroller">
    <div class="fixthis">FIX THIS</div>
    <ul>
        <li><a href="javascript:myScroll.scrollToElement(document.querySelector('#scroller li:nth-child(10)'))">Scroll to element 10</a></li>
        <li>Pretty row 2</li>
        <li>Pretty row 3</li>
        <li>Pretty row 4</li>
        <li>Pretty row 5</li>
        <li>Pretty row 6</li>
        <li>Pretty row 7</li>
        <li>Pretty row 8</li>
        <li>Pretty row 9</li>
        <li><a href="javascript:myScroll.scrollToElement(document.querySelector('#scroller li:nth-child(25)'), null, null, true)">Center element 25 to screen</a></li>
        <li>Pretty row 11</li>
        <li>Pretty row 12</li>
        <li>Pretty row 13</li>
        <li>Pretty row 14</li>
        <li>Pretty row 15</li>
    </ul>
</div>

JS

var myScroll;

function loaded () {
    myScroll = new IScroll('#wrapper', { mouseWheel: true, click: true,     HWCompositing: false});
}

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

loaded();

CSS

.fixthis {
  position: fixed;
  width: 100%;
  text-align: center;
  padding: 25px;
  background: #009BFF;
  color: #FFFFFF;
}

* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

html {
  -ms-touch-action: none;
}

body,ul,li {
  padding: 0;
  margin: 0;
  border: 0;
}

body {
  font-size: 12px;
  font-family: ubuntu, helvetica, arial;
  overflow: hidden; /* this is important to prevent the whole page to bounce */
}

#wrapper {
  position: absolute;
  z-index: 1;
  top: 45px;
  bottom: 48px;
  left: 0;
  width: 100%;
  background: #ccc;
  overflow: hidden;
}

#scroller {
  position: absolute;
  z-index: 1;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
  width: 100%;
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  -o-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: none;
  -moz-text-size-adjust: none;
  -ms-text-size-adjust: none;
  -o-text-size-adjust: none;
  text-size-adjust: none;
}

#scroller ul {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
  text-align: left;
}

#scroller li {
  padding: 0 10px;
  height: 40px;
  line-height: 40px;
  border-bottom: 1px solid #ccc;
  border-top: 1px solid #fff;
  background-color: #fafafa;
  font-size: 14px;
}

任何指针都会有所帮助

【问题讨论】:

  • 只是一个简单的问题。如果您希望它像标题一样固定,那么为什么不能将它放在scroller div 的顶部?
  • 我也在找同样的,其实里面翻译的div位置固定没用。
  • 您在“滚动”元素上的“已加载”功能设置内联 CSS,类似于“transform: translate(0px, -200px)”,这是造成此问题的主要原因。

标签: html css iscroll


【解决方案1】:

请在滚动 div 结束后将 fixthis 移到右侧,并将 z-index 设置为高于您想要的值。

【讨论】:

    猜你喜欢
    • 2011-07-26
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多