问题陈述:
我想有一个屏幕空间,在 div 中有一个背景图像,在背景图像上有另一个图像。背景图像上方的图像应该是可拖动和可调整大小的,并且当我添加它时它应该自动调整为背景图像的百分比缩放。此外,背景和其他图像应按比例放大和缩小。
请帮忙!
我的做法:
有两个div。一个 div 有一个图像作为其背景。第二个 div 有另一个可拖动的图像。
我不能做的是同步这两个 div,以便它们可以按比例放大和缩小。
先感谢您 :)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery.iviewer test</title>
<link href="jquery.iviewer.css" rel="stylesheet" type="text/css" /ss>
<script type="text/javascript" src="jquery.js" ></script>
<script type="text/javascript" src="jqueryui.js" ></script>
<script type="text/javascript" src="jquery.mousewheel.min.js" ></script>
<script type="text/javascript" src="jquery.iviewer.js" ></script>
<script type="text/javascript">
var $ = jQuery;
$(document).ready(function(){
var iv1 = $("#viewer").iviewer({
src: "meditation.png",
update_on_resize: true,
zoom_animation: true,
mousewheel: true,
onMouseMove: function(ev, coords) { },
onStartDrag: function(ev, coords) { return false; }, //this image can be dragged
onDrag: function(ev, coords) { }
});
$("#in").click(function(){ iv1.iviewer('zoom_by', 1); });
$("#out").click(function(){ iv1.iviewer('zoom_by', -1); });
$("#fit").click(function(){ iv1.iviewer('fit'); });
$("#orig").click(function(){ iv1.iviewer('set_zoom', 100); });
$("#update").click(function(){ iv1.iviewer('update_container_info'); });
});
</script>
<link rel="stylesheet" type="text/css" href="common/common.css"/>
<script language="JavaScript" type="text/javascript" src="core.js"></script>
<script language="JavaScript" type="text/javascript" src="events.js"></script>
<script language="JavaScript" type="text/javascript" src="css.js"></script>
<script language="JavaScript" type="text/javascript" src="coordinates.js"></script>
<script language="JavaScript" type="text/javascript" src="drag.js"></script>
<script language="JavaScript"><!--
window.onload = function() {
var group
var coordinates = ToolMan.coordinates()
var drag = ToolMan.drag()
var boxDrag = document.getElementById("boxDrag")
drag.createSimpleGroup(boxDrag)
var boxVerticalOnly = document.getElementById("boxVerticalOnly")
group = drag.createSimpleGroup(boxVerticalOnly)
group.verticalOnly()
var boxHorizontalOnly = document.getElementById("boxHorizontalOnly")
group = drag.createSimpleGroup(boxHorizontalOnly)
group.horizontalOnly()
var boxRegionConstraint = document.getElementById("boxRegionConstraint")
group = drag.createSimpleGroup(boxRegionConstraint)
var origin = coordinates.create(0, 0)
group.addTransform(function(coordinate, dragEvent) {
var originalTopLeftOffset =
dragEvent.topLeftOffset.minus(dragEvent.topLeftPosition)
return coordinate.constrainTo(origin, originalTopLeftOffset)
})
var boxThreshold = document.getElementById("boxThreshold")
group = drag.createSimpleGroup(boxThreshold)
group.setThreshold(25)
var boxHandle = document.getElementById("boxHandle")
group = drag.createSimpleGroup(boxHandle, document.getElementById("handle"))
var boxAbsolute = document.getElementById("boxAbsolute")
group = drag.createSimpleGroup(boxAbsolute)
group.verticalOnly()
group.addTransform(function(coordinate, dragEvent) {
var scrollOffset = coordinates.scrollOffset()
if (coordinate.y < scrollOffset.y)
return coordinates.create(coordinate.x, scrollOffset.y)
var clientHeight = coordinates.clientSize().y
var boxHeight = coordinates._size(boxAbsolute).y
if ((coordinate.y + boxHeight) > (scrollOffset.y + clientHeight))
return coordinates.create(coordinate.x,
(scrollOffset.y + clientHeight) - boxHeight)
return coordinate
})
}
</script>
<link rel="stylesheet" href="/jquery.iviewer.css" />
<style>
.viewer
{
width: 75%;
height: 800px;
border: 1px solid black;
position: relative;
overflow:scroll;
}
.wrapper
{
overflow: hidden;
}
div {
margin: 0px;
padding: 0px;
}
.verticalgridline {
padding-top: 27px;
}
.box {
float: left;
padding: 0px;
}
#boxDrag, #boxVerticalOnly, #boxHorizontalOnly, #boxRegionConstraint,
#boxThreshold, #boxAbsolute {
cursor: move;
}
#boxAbsolute {
position: absolute;
bottom: 0px;
right: 0px;
}
</style>
</head>
<body>
<h1>Design Page</h1>
<!-- wrapper div is needed for opera because it shows scroll bars for reason -->
<div class="wrapper">
<div id="viewer" class="viewer" >
<div id="boxDrag" class="box">
<img src="4.png" />
</div>
</div>
</div>
</body>
</html>