크기를 조정하고 이미지를 드래그 할 수있는 배너를 만들려고합니다. 크기 조정을 제외한 모든 작업이 정상적으로 작동합니다.jQuery 이미지 크기 조정 - 너비가 맞지 않습니다.
이미지 아래의 슬라이더로 이미지의 크기를 조정할 때. 이미지가 커집니다. 이미지의 크기를 조정 한 후에는 오른쪽과 아래쪽으로 이미지를 성공적으로 드래그 할 수 있습니다. 이미지를 오른쪽으로 끌면 이미지를 다시 작게 만들기로 결정했습니다. 이미지 아래의 슬라이더를 사용할 수 있습니다. 그러나 이제는 문제가 온다. 이미지의 오른쪽에 있고 이미지의 크기를 다시 조정하려는 경우 이미지가 div에 맞지 않습니다. 검은 색 배경이 보입니다. http://jsfiddle.net/DennisBetman/tnaGA/
HTML :
<div id="box">
<img src="http://www.digindigin.com/blog/wp-content/uploads/2012/05/Diablo_3___Wizard_Wallpaper_by_Lythus.jpg" id="img" width="371" height="auto" style="top:-0px; left:-0px;" />
</div>
<!-- style="top:-262px; left:-425px;" -->
<div id="zoom"></div>
<input type="hidden" id="amount-width" style="border: 0; color: #f6931f; font-weight: bold;" />
<input type="hidden" id="amount-height" style="border: 0; color: #f6931f; font-weight: bold;" />
<div class="text"></div>
<p>
Position x:
<input type="text" id="val-x" style="border:0; color:#f6931f; font-weight:bold;" />
</p>
<p>
Position y:
<input type="text" id="val-y" style="border:0; color:#f6931f; font-weight:bold;" />
</p>
jQuery를 :
jQuery("#zoom").slider({
max: 650,
slide: function(){
var sliderValue = jQuery("#zoom").slider("value");
jQuery("#img").width(370 + sliderValue);
$("#amount-width").val(jQuery("#img").css("width"));
$("#amount-height").val(jQuery("#img").css("height"));
var width = $("#img").width();
var widthZoom = width + sliderValue;
var widthVerschil = widthZoom - sliderValue;
var totalWidth = widthVerschil - '373';
var stageWidth = $("#box").width();
var height = $("#img").height();
var totalHeight = height - '207';
$("#img").draggable({
containment: [-totalWidth, -totalHeight, 0, 0],
scroll: false,
iframeFix: true,
});
$('.text').html('<br/>The file size = ' + height + ' x ' + widthVerschil);
}
});
var height = $("#img").height();
var totalHeight = height - '207';
$("#img").draggable
({
containment: [0, -totalHeight, 0, 0],
snap: false,
drag: function(event, ui)
{
$("#val-x").val(ui.position.left);
$("#val-y").val(ui.position.top);
}
});
$("#img").offset({left: $(this).attr('position')});
CSS :
여기 은 예입니다div {
width:370px;
height:204px;
position:relative;
overflow:hidden;
border-top-left-radius: 7px;
border-top-right-radius: 7px;
}
#box{
background:black;
}
#img{
}
누군가가 나를 도울 수 있기를 바랍니다.
인사말, 데니스.
작동 해 주셔서 감사합니다. 이것은 내가 필요한 것입니다. 그리고 네, 저에게 영감을 불어 넣었습니다! :) 감사!! –
멋진 점은 jsfiddle에서만 작동합니다. 그것은 JS BIN 또는 내 웹 사이트에서 작동하지 않습니다. 다른 것을 아십니까? –
NVM이 다시 작동합니다;) –