I am currently working on creating a portfolio gallery and have put together the following HTML structure:
<article class="work-gallery">
<ul>
<li id="project-1"><img src="http://placehold.it/50x00"></li>
<li id="project-2"><img src="http://placehold.it/50x50"></li>
<li id="project-3"><img src="http://placehold.it/50x50"></li>
</ul>
</article>
<div class="projects">
<div id="detail-1" class="project-content project-1">Test</div>
<div id="detail-2" class="project-content project-2">Test</div>
<div id="detail-3" class="project-content project-3">Test</div>
</div><!-- end .projects -->
My goal is to automatically match the x/y coordinates of #project-1 to #detail-1, #project-2 to #detail-2, and so on when the page loads.
Here's the JavaScript code I have written for this purpose:
$(document).ready(function () {
var thumb = $('.work-gallery li'),
thumbId = thumb.attr('id'),
thumbIdNumber = thumbId.substring(thumbId.indexOf('-') + 1, thumbId.length),
thumbProject = $('#detail-' + thumbIdNumber);
thumbProject.css({'top': thumb.position.top});
});
However, I'm facing an issue in specifying the ID of the thumb variable in the last statement. If anyone has alternative suggestions or solutions on how to achieve this effect, I would greatly appreciate it.