Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I hope this little solution will help you out. You can see it action here: <a href="http://jsfiddle.net/neopreneur/ZQqbQ/" rel="nofollow">http://jsfiddle.net/neopreneur/ZQqbQ/</a></p> <p>In the second example, scroll the image and click the button to see the indicator re-center.</p> <p>-css-</p> <pre><code>.fancy-img{ display:inline-block; position: relative; max-height:400px; max-width: 300px; overflow: auto; } .indicator{ width: 50px; height: 50px; border: 2px solid green; position: absolute; } </code></pre> <p>-html-</p> <pre><code>&lt;div class="fancy-img"&gt; &lt;img id="img1" src="http://upload.wikimedia.org/wikipedia/en/7/72/Example-serious.jpg" alt="" /&gt; &lt;/div&gt; &lt;div class="fancy-img"&gt; &lt;img id="img2" src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Example.svg/600px-Example.svg.png" alt="" /&gt; &lt;/div&gt; </code></pre> <p>-js-</p> <pre><code>$(document).ready(function(){ // add indicator functionality for each img $('.fancy-img').each(function(){ // button to toggle indicator $(this).after('&lt;button class="indicator-btn" data-imageid="' + $(this).find('img').attr('id') + '" type="button"&gt;Adjust Indicator&lt;/button&gt;'); }); // handle button click $('button.indicator-btn').click(function(){ var imgId = $(this).data('imageid'); // insert indicator $('#' + imgId).before('&lt;div class="indicator" /&gt;'); // center indicator (also adjust for offset) var containerWidth = $('#' + imgId).parents('.fancy-img:first').width(); var containerHeight = $('#' + imgId).parents('.fancy-img:first').height(); var indicatorWidth = $('.indicator:first').width(); var indicatorHeight = $('.indicator:first').height(); var newIndicator = $('#' + imgId).parents('.fancy-img:first').find('.indicator'); $(newIndicator).css({ left: containerWidth/2 - indicatorWidth /2 + $('#' + imgId).parents('.fancy-img:first').scrollLeft(), top: containerHeight/2 - indicatorHeight/2 + $('#' + imgId).parents('.fancy-img:first').scrollTop() }); }); }); </code></pre> <p>Let me know if this has helped. Cheers!</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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