te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Add content above viewport and scroll up - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add content above viewport and scroll up - Stack Overflow

programmeradmin3浏览0评论

Im trying to make an animation where I add content that is supposed to be located above the page. When the content is added I want it to appear above the page and then scroll upwards. However when I add my content everything else is instead pushed down. Here is where I get stuck:

const el = (sel, par = document) => par.querySelector(sel);
const els = (sel, par = document) => par.querySelectorAll(sel);


const elBody = el("body");
const elTop = el("#top");

const toggleContact = () => {
  elBody.classList.toggle("is-show-contact");
  if (elBody.classList.contains("is-show-contact")) {
    elTop.scrollIntoView({
      behavior: "smooth",
      block: "start"
    });
  }
};

els(".btn-contact").forEach((elBtn) => {
  elBtn.addEventListener("click", toggleContact);
});
* {
  margin: 0;
  box-sizing: border-box;
}

.box {
  height: 100dvh;
}

#top {
  position: relative;
  overflow: auto;
  background: #ddd;
  transition: height 1s;
  height: 0dvh;

  .is-show-contact & {
    height: 100dvh;
  }
}
img{
  width:100%;
}
<div id="top">
  <h2>CONTACT FORM</h2>
   <img src = ".jpg?sz=256">
  <button class="btn-contact" type="button">Close</button>
</div>

<div class="box">
  <p>Scroll down as well...</p>
  <button class="btn-contact" type="button">Contact</button>
</div>

<div class="box">
  <button class="btn-contact" type="button">Contact</button>
</div>

<div class="box">
  <button class="btn-contact" type="button">Contact</button>
</div>

<div class="box">
  <button class="btn-contact" type="button">Contact</button>
</div>

Im trying to make an animation where I add content that is supposed to be located above the page. When the content is added I want it to appear above the page and then scroll upwards. However when I add my content everything else is instead pushed down. Here is where I get stuck:

const el = (sel, par = document) => par.querySelector(sel);
const els = (sel, par = document) => par.querySelectorAll(sel);


const elBody = el("body");
const elTop = el("#top");

const toggleContact = () => {
  elBody.classList.toggle("is-show-contact");
  if (elBody.classList.contains("is-show-contact")) {
    elTop.scrollIntoView({
      behavior: "smooth",
      block: "start"
    });
  }
};

els(".btn-contact").forEach((elBtn) => {
  elBtn.addEventListener("click", toggleContact);
});
* {
  margin: 0;
  box-sizing: border-box;
}

.box {
  height: 100dvh;
}

#top {
  position: relative;
  overflow: auto;
  background: #ddd;
  transition: height 1s;
  height: 0dvh;

  .is-show-contact & {
    height: 100dvh;
  }
}
img{
  width:100%;
}
<div id="top">
  <h2>CONTACT FORM</h2>
   <img src = "https://lh3.googleusercontent/-NREkKmTtXX0/AAAAAAAAAAI/AAAAAAAAADg/w2IRnCo5AwQ/photo.jpg?sz=256">
  <button class="btn-contact" type="button">Close</button>
</div>

<div class="box">
  <p>Scroll down as well...</p>
  <button class="btn-contact" type="button">Contact</button>
</div>

<div class="box">
  <button class="btn-contact" type="button">Contact</button>
</div>

<div class="box">
  <button class="btn-contact" type="button">Contact</button>
</div>

<div class="box">
  <button class="btn-contact" type="button">Contact</button>
</div>

I got the idea from a page called yearofmoo, a website that contains codingguides and videos. If you want to check it out the animation happens when you press contact in the menu. Have anyone acheived something simiular? I think I can manage the scroll myself, my question is how I can the content above the viewpoint.

Share Improve this question edited Feb 17 at 15:08 Jack the man asked Feb 17 at 13:45 Jack the manJack the man 318 bronze badges 4
  • 1 Consider using scrollIntoView – evolutionxbox Commented Feb 17 at 14:02
  • 1 I'm not seeing the distinction between "I want it to appear above the page and then scroll upwards" and "it's like a curtain coming down" (which you don't want). That's exactly what your example site does - pull a curtain down containing the form. – fdomn-m Commented Feb 17 at 17:19
  • I don't see how this behavior actually works unless the contact form is actually located at the bottom...?
发布评论

评论列表(0)

  1. 暂无评论