亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果我的菜單在 header.php 中,如何滾動到 index.php 中的特定位置

如果我的菜單在 header.php 中,如何滾動到 index.php 中的特定位置

PHP
滄海一幻覺 2023-03-26 16:24:19
我有 4 個文件:加載頁眉、內容和頁腳的主文件夾中的 index.php。<?php  include('header.php');  echo $this->content();  include('footer.php');?>在主文件夾的 header.php 中,我也有這個:<div class="header-nav">  <div class="container">    <div class="navbar-wrapper">      <div class="navbar navbar-expand-lg">        <div id="mobileMenuMain" class="collapse navbar-collapse o2 fe">          <nav class="main-nav-menu main-menu-nav navbar-arrow">            <ul class="main-nav">              <li>                <a href="<?php echo base_url(); ?>" title="home">                  <?=lang('01')?>                </a>              </li>              <?=menu(1);?>          </nav>          <!--/.nav-collapse -->        </div>        <?php if( ! empty($phone) ) { ?>        <div class="navbar-phone d-none d-lg-block o1">          <i class="material-icons">phone</i>          <?php echo trans('0438');?> :          <?php echo $phone; ?>        </div>        <?php } ?>      </div>    </div>  </div></div>以及加載多個腳本、iframe 甚至加載其他 php 文件的主要內容文件。這個 index.php 文件的位置位于主文件夾的子文件夾 views/home/ 里面:<style>  .home_hidden {    display: none !important  }    .form-search-main-01 .col-md-6,  .form-search-main-01 .col-md-5,  .form-search-main-01 .col-md-4,  .form-search-main-01 .col-md-3,  .form-search-main-01 .col-md-2 {    width: 100% !important;    flex: 0 0 100%;    max-width: 100%;  }
查看完整描述

2 回答

?
BIG陽

TA貢獻1859條經驗 獲得超6個贊

您的鏈接和內容位于不同的 PHP 文件中并不重要,因為您鏈接到 URL,并且您仍然可以使用錨點將它們鏈接在一起,只要您可以為它們分配通用 ID:https:?//developer.mozilla.org/en -US/docs/Web/HTML/Element/a#Linking_to_an_element_on_the_same_page

您還可以使用 CSS 屬性scroll-behavior: smooth;以獲得更好看的滾動效果(或使用 JavaScript執行相同操作)


查看完整回答
反對 回復 2023-03-26
?
揚帆大魚

TA貢獻1799條經驗 獲得超9個贊

您只需在 JavaScript 中調用一個函數即可:


<!-- JavaScript part: -->

<script type="text/javascript">

? ?function scrollTo(id){

? ? ? var element = document.getElementById(id)


? ? ? // For scrolling to the top of the container:

? ? ? element.scrollIntoView(True)


? ? ? // Alternatively, for scrolling to the bottom of the container:

? ? ? element.scrollIntoView(False)

? ?}

</script>


<!-- Your container you want to scroll to: -->


<div id="container1">

? ?<!-- Content of container here -->

</div>


<!-- Link for scrolling to the container, can also be included with include from php like you do it in your navbar: -->


<a href="javascript: scrollTo('container1')">

? ?Go to container1

</a>

我希望它對你有用。

查看完整回答
反對 回復 2023-03-26
  • 2 回答
  • 0 關注
  • 130 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號