Note that there are some explanatory texts on larger screens.

plurals
  1. POTransfer inline hard-coded jQuery function to variables
    primarykey
    data
    text
    <p>I have the following code:</p> <pre><code> &lt;!-- work item 1 --&gt; &lt;li id="portfolio-1" class="col-12 col-sm-6 col-md-6 col-lg-4"&gt; &lt;figure class="box box--sm text-center"&gt; &lt;h4 class="brand--font-standard"&gt;Project Title&lt;/h4&gt; &lt;div class="row"&gt; &lt;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"&gt; &lt;img src="img/globe.jpg" class="img-responsive" alt="globe"&gt; &lt;/div&gt; &lt;/div&gt; &lt;figcaption&gt; &lt;p&gt;Project comment&lt;/p&gt; &lt;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;"&gt;View&lt;/a&gt; &lt;/figcaption&gt; &lt;/figure&gt; &lt;/li&gt;&lt;!-- /work item 1 --&gt; </code></pre> <p>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).</p> <p>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.</p> <p>The corresponding hidden content would also need to work from variables as oppose to being hard-coded. An example of this is:</p> <pre><code>&lt;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;"&gt;close&lt;/a&gt; </code></pre> <p>Which I currently have the following function for (to get the window width): </p> <pre><code>var _getInnerWidth = function () { return typeof window.innerWidth !== 'undefined' ? window.innerWidth : document.documentElement.clientWidth; </code></pre> <p>Any help is appreciated!</p> <p><a href="http://www.nerdswithhair.com/themes/uno" rel="nofollow">Demo is here</a></p> <p>PS - I can deal with the second part (adding the offset values based on the window width etc)</p> <p>PPS - I'm a novice with js, so please be gentle :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload