내가이 작은 솔루션은 당신을 도움이되기를 바랍니다 검색 할 수 있습니다.
http://jsfiddle.net/neopreneur/ZQqbQ/
두 번째 예에서는 이미지를 스크롤하고 표시기를 다시 보려면 버튼을 클릭하십시오.
<div class="fancy-img">
<img id="img1" src="http://upload.wikimedia.org/wikipedia/en/7/72/Example-serious.jpg" alt="" />
</div>
<div class="fancy-img">
<img id="img2" src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Example.svg/600px-Example.svg.png" alt="" />
</div>
-js-
$(document).ready(function(){
// add indicator functionality for each img
$('.fancy-img').each(function(){
// button to toggle indicator
$(this).after('<button class="indicator-btn" data-imageid="' + $(this).find('img').attr('id') + '" type="button">Adjust Indicator</button>');
});
// handle button click
$('button.indicator-btn').click(function(){
var imgId = $(this).data('imageid');
// insert indicator
$('#' + imgId).before('<div class="indicator" />');
// 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()
});
});
});
이 도움이되었는지 알려주세요
-html-
-css-
.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;
}
. 건배!
그 것이 아름답게 작동합니다! 정말 고마워! –