I have the following code:
<!-- work item 1 -->
<li id="portfolio-1" class="col-12 col-sm-6 col-md-6 col-lg-4">
<figure class="box box--sm text-center">
<h4 class="brand--font-standard">Project Title</h4>
<div class="row">
<div class="col-xs-offset-2 col-xs-8 col-sm-offset-1 col-sm-10 col-md-offset-2 col-md-8 col-lg-offset-3 col-lg-6">
<img src="img/globe.jpg" class="img-responsive" alt="globe">
</div>
</div>
<figcaption>
<p>Project comment</p>
<a href="#" class="pull-right brand--font" onclick="$('.work--detail').addClass('work--detail_show'); $('#work-2, #work-3, #work-4, #work-5, #work-6').hide(); $('#work-1').slideDown(); $('html, body').animate({scrollTop: $('.hidden-content-top').offset().top - 110 }, 1000); return false;">View</a>
</figcaption>
</figure>
</li><!-- /work item 1 -->
I'm wanting to rewrite the js on the anchor tag so that it is not hard-coded, instead having variables for the items that need to open/have .hide added to them. There are currently 6 li's with ID's of #portfolio-(number) with corresponding hidden content for each with ID's of #work-(number).
The reason i'm wanting to do this is firstly to tidy the code up and make it a little more reusable. But also, as the site is responsive I need to adjust the offset value based on the window width.
The corresponding hidden content would also need to work from variables as oppose to being hard-coded. An example of this is:
<a href="#" class="btn btn--small btn--grey brand--font" onclick="$('#work-1').slideUp(); $('html, body').animate({scrollTop: $('#portfolio-1').offset().top - 140 }, 1000); $('.work--detail').removeClass('work--detail_show'); return false;">close</a>
Which I currently have the following function for (to get the window width):
var _getInnerWidth = function () {
return typeof window.innerWidth !== 'undefined' ? window.innerWidth : document.documentElement.clientWidth;
Any help is appreciated!
PS - I can deal with the second part (adding the offset values based on the window width etc)
PPS - I'm a novice with js, so please be gentle :)