简体   繁体   English

文章按钮和菜单上的readmore.js

[英]readmore.js on an article button and menu

I have a page which has several short articles and a sidenav which scrolls down to an article based on it's id. 我有一个页面,其中包含几篇简短的文章和一个sidenav,可根据其ID向下滚动到文章。 The articles have been truncated using readmore.js, so they all have a 'Read More' button. 文章已使用readmore.js进行了截断,因此它们都有一个“阅读更多”按钮。

The sidenav link scrolls down to the truncated version. sidenav链接向下滚动到截断的版本。 I would like it to go straight to the full length of the article, but since they are all on the same page I'm not sure how to go on about it. 我希望直接阅读本文的全文,但是由于它们都在同一页上,所以我不确定该如何进行下去。

My code looks like this: 我的代码如下所示:

<!--sidenav-->

<ul class="sidenav-list navtree-list" id="navtree-0">
  <li >
    <a href="#article1" class="sidenav-item">
      <h2><?php echo $page->header1() ?></h2>
    </a>
  </li>
  <li >
    <a href="#article2" class="sidenav-item">
      <h2><?php echo $page->header2() ?></h2>
    </a>
</li>

<!--articles-->
<div class="container-fluid content-desktop">

<h3 id="article1"><?php echo $page->header1() ?></h3>
  <article data-readmore>
    <?php echo $page->description1()->kirbytext()?> 
  </article>

<h3 id="article2"><?php echo $page->header2() ?></h3>
  <article data-readmore>
    <?php echo $page->description2()->kirbytext()?>
  </article>

Any suggestions will be really appreciated! 任何建议将不胜感激!

Now this could normally be solved by using .readmore('toggle') , something like this 现在通常可以使用.readmore('toggle')解决此问题,例如

$(document).ready(function() {
  $('.sidenav-item').click(function() {
      $($(this).attr('href')).next().readmore('toggle');
  })
});

This will find the header with the matching id, take the .next() element which should be the <article> , and expand it with .readmore('toggle') once you click the navigation. 这将找到具有匹配ID的标头,采用应为<article>.next()元素,并在单击导航后使用.readmore('toggle')对其进行扩展。

However , there is currently a bug in readmore.js preventing this. 但是目前在readmore.js中存在一个错误可以阻止这种情况。

If you are comfortable with editing readmore.js yourself, then you can change these sections and replace _this with this to make it work. 如果您熟悉编辑readmore.js自己,那么你可以改变这些部分和替换_thisthis使它工作。 It's row 227 and 231 in the non-minimized version of readmore.js. 在readmore.js的非最小版本中,它是第227231行。

if (! trigger) {
  trigger = $('[aria-controls="' + _this.element.id + '"]')[0];
}

if (! element) {
  element = _this.element;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM