OctoberCMS - 如何使可折叠列表默认仅在非移动设备上处于活动状态

Posted

技术标签:

【中文标题】OctoberCMS - 如何使可折叠列表默认仅在非移动设备上处于活动状态【英文标题】:OctoberCMS - How to make collapsible list default to active only on non-mobile 【发布时间】:2016-03-29 06:24:12 【问题描述】:

我有一个 OctoberCMS 网站,我试图在可折叠列表中隐藏一个侧边栏,以便在移动设备上查看时列表项将被折叠。当不在移动设备上时,我希望将其扩展,如下例所示:

http://codepen.io/anon/pen/GoqPJj

代码如下:

<div class="container">
    <div class="row">
        <div class="col s12 m6">
            <ul class="collapsible" data-collapsible="accordion">
                <li>
                    <div class="collapsible-header active"><i class="material-icons">filter_drama</i>First</div>
                    <div class="collapsible-body">
                        <p>Lorem ipsum dolor sit amet.</p>
                    </div>
                </li>
            </ul>
        </div>
        <div class="col s12 m6">
            This is the main page content. Here is some more content, and here is some even more content. It never seems to end as I add random text. Just one more sentence to make it a bit more complete.
        </div>
    </div>
</div>

有谁知道我可以如何编辑上面的示例以产生预期的结果?

【问题讨论】:

【参考方案1】:

这是根据您的要求工作的代码。这里我将$( document ).width() 定义为420。您可以根据需要更改它。

if($( document ).width() < 420)
  $('.collapsible-body').hide();
  $('.active').removeClass('active');
  
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.2/css/materialize.min.css">
    
    
    <link rel='stylesheet prefetch' href='https://fonts.googleapis.com/icon?family=Material+Icons'>
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.2/js/materialize.min.js'></script>

<div class="container">
	<div class="row">
		<div class="col s12 m6">
			<ul class="collapsible" data-collapsible="accordion">
				<li>
					<div class="collapsible-header active"><i class="material-icons">filter_drama</i>First</div>
					<div class="collapsible-body">
						<p>Lorem ipsum dolor sit amet.</p>
					</div>
				</li>
			</ul>
		</div>
		<div class="col s12 m6">
			This is the main page content. Here is some more content, and here is some even more content. It never seems to end as I add random text. Just one more sentence to make it a bit more complete.
		</div>
	</div>
</div>

希望这对你有用。

享受吧!!!! 谢谢

【讨论】:

以上是关于OctoberCMS - 如何使可折叠列表默认仅在非移动设备上处于活动状态的主要内容,如果未能解决你的问题,请参考以下文章

如何使可扩展列表视图的项目选中/不可选中

可折叠的 div,但仅在移动设备上

如何使用获取页面树在 OctoberCMS 中获取静态页面下拉列表?

如何在 OctoberCMS 中使用控制器的默认主题和变量呈现 cms 页面?

如何在 OctoberCMS 中获取基本网址?

请问vue如何实现可折叠列表?