OctoberCMS - How to make collapsible list default to active only on non-mobile

- 1 answer

Ad

I have an OctoberCMS site and I am trying to hide a sidebar in a collapsible list so that when viewed on mobile the list item will be collapsed. When not on mobile I'm looking for it to be expanded as in the example below:

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

The code is below:

<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>

Does anyone know how I can edit the above example to produce the desired outcome?

Ad

Answer

Ad

Here is the code that work as per your requirement. Here i have define $( document ).width() as 420. You can change it as per your requirement.

if($( document ).width() < 420){
  $('.collapsible-body').hide();
  $('.active').removeClass('active');
  }
<link rel="stylesheet" target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" 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>

Hope this will work for you.

Enjoy !!!! Thanks

Ad
source: stackoverflow.com
Ad