CSS: content scaling in parent div - html

I'm using famo.us for rendering surfaces contaning HTML. I want the HTML content to scale with transformations on the surface. For example a "polaroid" rendering with picture and name:
HTML:
<div id="contentdiv" style="width:164px; height:199px; background-color: aqua; border: dashed">
<div class="polaroid">
<img class="img-responsive" src='https://dl.dropboxusercontent.com/u/7197720/www/Serge.jpg'>
<p>Serge</p>
</div>
</div>
CSS:
.polaroid {
position: relative;
width: 100%; /* width 144px, both sides 10px border */
}
.polaroid img {
max-width: 100%;
border: 10px solid #fff;
border-bottom: 2.4vw solid #fff;
-webkit-box-shadow: 3px 3px 3px #777;
-moz-box-shadow: 3px 3px 3px #777;
box-shadow: 3px 3px 3px #777;
}
.polaroid p {
position: absolute;
text-align: center;
width: 100%;
bottom: 0px;
font: 400 1vw 'Kaushan Script', cursive;
color: #888;
}
I just don't get the CSS in a shape that when I enlarge or minimize the div, the content scales with it. To test scaling within a div I created a simple test harness with the example I try to implement. See http://codepen.io/svdoever/pen/raGjrZ. Problem is the scaling/positiong of fonts and that borders should scale on resize, so smaller border on smaller size.
My first question is: is it possible to write html/css that scales correctly with the parent container? Should work for images, fonts, margins etc. Is there a solution for my example?
My second question is: is it possible to make the html/css responsive, so show less/more content based on the size of the container element.
My third question is: what are the best practices for writing this type of html/css.
EDIT: I found blogpost http://blog.sathomas.me/post/zooming-html-content-with-css-scale-transform, but don't really understand the approach yet...

There is a solution for what you have done in your codepin using Famo.us. I have created an example, but will not include all the features of your codepen, but it will give you a start for dynamic css in Famo.us
Answer to first question:
It is possible to write css that will scale proportionately in your event handlers.
Example jsBin of code below
var mainContext = Engine.createContext();
mainContext.setPerspective(1000);
var splash = new Surface({ content: 'Famo.us Application'});
mainContext.add(splash);
var proportion = 1;
var orig = 144;
var min = 100;
var max = 1440;
var widthLabel = new Surface({
content: 'Width',
size: [true, true]
});
var widthSlider = new InputSurface({
type: 'range',
value: orig,
attributes: {
min: min,
max: max
}
});
var heightLabel = new Surface({
content: 'Height',
size: [true, true]
});
var heightSlider = new InputSurface({
type: 'range',
value: orig,
attributes: {
min: min,
max: max
}
});
function _changeProportions() {
var value = widthSlider.getValue();
polaroidMod.setSize([value,value]);
proportion = value/orig ;
polaroidText.setOptions({properties: {fontSize: Math.round(proportion) + 'em'}});
image.setOptions({
properties: {
border: Math.round(proportion*10) + 'px solid #fff',
borderBottom: Math.round(proportion * 1.5) + 'em solid #fff',
boxShadow: Math.round(proportion*3) + 'px ' + Math.round(proportion*3) + 'px ' + Math.round(proportion*3) + 'px #777'
}
});
polaroidText.mod.setTransform(Transform.translate(0,-Math.round(proportion*15), 0.002));
}
widthSlider.on('input', function(e){
var slider = e.target;
heightSlider.setValue(slider.value);
_changeProportions(slider.value);
});
heightSlider.on('input', function(e){
var slider = e.target;
widthSlider.setValue(slider.value);
_changeProportions();
});
var widthNode = mainContext.add(new Modifier({
size: [200, 40],
transform: Transform.translate(0,20, 0.001)
}));
var heightNode = mainContext.add(new Modifier({
size: [200, 40],
transform: Transform.translate(210,20, 0.001)
}));
widthNode.add(widthLabel);
widthNode.add(widthSlider);
heightNode.add(heightLabel);
heightNode.add(heightSlider);
var polaroidMod = new Modifier({
size: [orig, orig],
transform: Transform.translate(10,70, 0.001),
proportions: [1, 1]
});
var polaroidNode = mainContext.add(polaroidMod);
var polaroid = new ContainerSurface({
size:[undefined, undefined]
});
var image = new ImageSurface({
size:[undefined, true],
content: 'https://dl.dropboxusercontent.com/u/7197720/www/Serge.jpg',
properties: {
maxWidth: '100%',
border: Math.round(proportion*10) + 'px solid #fff',
borderBottom: Math.round(proportion) + 'em solid #fff',
boxShadow: '3px 3px 3px #777'
}
});
polaroidNode.add(polaroid);
polaroid.add(image);
polaroidText = new Surface({
size: [true, true],
content: 'Serge',
properties: {
font: "400 "+ Math.round(proportion) +"em 'Kaushan Script', cursive",
color: '#888',
fontSize: Math.round(proportion) + 'em'
}
});
polaroidText.mod = new Modifier({
origin: [0.5, 0],
align: [0.5, 1],
transform: Transform.translate(0,-15, 0.002)
});
var textNode = polaroidNode.add(polaroidText.mod);
textNode.add(polaroidText);
Answer to second question:
Yes, you could make it responsive within your transition event handlers as in the example.
Answer to third question:
Best practice in my opinion is based on use case, but you can see that styling can be dynamic during transitions without using a style sheet file.

Related

Correctly Increasing The Size Of A Video Camera Without Ruining The Aspect Ratio

I have a web page that displays a video where the user can see them self with the computer's camera.
The issue is the camera is too small and when I make the height and width 400px, the aspect ratio is ruined.
Not only this, but the top camera output fill the entire border.
The following is an image showing this happening:
top-camera
The following is the facial-login.html file:
<!DOCTYPE html>
<html>
<head>
<style>
#video {
border: 1px solid black;
width: 320px;
height: 240px;
}
#photo {
border: 1px solid black;
width: 320px;
height: 240px;
}
#canvas {
display: none;
}
.camera {
width: 320px;
display: inline-block;
}
.output {
width: 320px;
display: inline-block;
}
#startbutton {
display: block;
position: relative;
margin-left: auto;
margin-right: auto;
bottom: 36px;
padding: 5px;
background-color: #6a67ce;
border: 1px solid rgba(255, 255, 255, 0.7);
font-size: 14px;
color: rgba(255, 255, 255, 1.0);
cursor: pointer;
}
.contentarea {
font-size: 16px;
font-family: Arial;
text-align: center;
}
/* .sendButton {
background-color: #4CAF50;
border: none;
color: white;
padding: 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 12px;
} */
.sendButton {
position: absolute;
top: 327px;
text-align: center;
}
</style>
<!--The title of the HTML document.-->
<title>Facial Image Recognition</title>
</head>
<body>
<div class="contentarea">
<h1 align="center">Facial Image Recognition</h1>
<div class="camera">
<video id="video">Video stream not available.</video>
</div>
<!--An id on a <button> tag assigns an identifier to the button.
The id allows JavaScript to easily access the <button> element
and manipulate it.-->
<button id="startbutton">Capture Image</button>
<!--The following button will trigger the JavaScript function.-->
<!-- <button class="sendButton">Submit Facial Image</button> -->
<button class="sendButton">Submit Facial Image</button>
<!--The HTML canvas tag is where the image frames are stored
before they are converted into an image of proper format
to be shown using the <img> tag.-->
<canvas id="canvas"></canvas>
<div class="output">
<img id="photo" alt="The image captured will appear in this box.">
</div>
</div>
<script>
var data;
(function() {
// We will scale the photo width to this.
var width = 400;
// The height will be computed based on the input stream.
var height = 0;
var streaming = false;
var video = null;
var canvas = null;
var photo = null;
var startbutton = null;
function startup() {
video = document.getElementById('video');
canvas = document.getElementById('canvas');
photo = document.getElementById('photo');
/*The following line is executed when a user clicks on the
"Capture Image" button.
document.getElementById returns the element whose 'id'
is 'startbutton'.*/
startbutton = document.getElementById('startbutton');
// Access the video stream from the webcam.
navigator.mediaDevices.getUserMedia({
video: true,
audio: false
})
// Upon success, stream video in a video tag.
.then(function(stream) {
video.srcObject = stream;
video.play();
})
.catch(function(err) {
console.log("An error occurred: " + err);
});
video.addEventListener('canplay', function(ev) {
if (!streaming) {
height = video.videoHeight / (video.videoWidth / width);
if (isNaN(height)) {
height = width / (4 / 3);
}
video.setAttribute('width', width);
video.setAttribute('height', height);
canvas.setAttribute('width', width);
canvas.setAttribute('height', height);
streaming = true;
}
}, false);
startbutton.addEventListener('click', function(ev) {
takepicture();
ev.preventDefault();
}, false);
clearphoto();
}
/*Collect the frames of the photo from the canvas and then
convert it into a PNG format, so that it can be shown in
the HTML page.*/
function clearphoto() {
var context = canvas.getContext('2d');
context.fillStyle = "#AAA";
context.fillRect(0, 0, canvas.width, canvas.height);
var data = canvas.toDataURL('image/png');
photo.setAttribute('src', data);
}
/*Capture a frame from the video stream.*/
function takepicture() {
var context = canvas.getContext('2d');
if (width && height) {
canvas.width = width;
canvas.height = height;
/*The canvas takes a snapshot of the video.*/
context.drawImage(video, 0, 0, width, height);
/*toDataURL('image/png') returns a data URL containing a
representation of the image in PNG format.
'data' will hold the URL link of each image that is
captured from the camera.*/
data = canvas.toDataURL('image/png');
/*'src' is the name of the attribute whose value is to be set.
'data' is a string containing the value to assign to the attribute.
The data is fed as a source of the image element.*/
photo.setAttribute('src', data);
let facialImageURL = '<img src="'+data+'"/>';
// document.write('<img src="'+data+'"/>');
}else {
clearphoto();
}
}
/*The following code will call the startup() function when
the HTML page is loaded.*/
window.addEventListener('load', startup, false);
})();
var URL = "{% url 'facial-login-result' %}";
/*POST the data (the facial image) to the server via AJAX.*/
function SendFacialImage(){
var facialImage = {'data': data};
$.post(URL, facialImage, function(response){
if(response === 'success')
{
alert('Facial Image Successfully Sent!');
}
else{
alert('Error Sending Facial Image!');
}
});
}
$(document).ready(function(){
$('#sendButton').click(function(){
SendFacialImage();
});
});
</script>
</body>
</html>

Dragging shapes from a palette onto a Konvajs stage

On the Konvajs chat stream someone recently asked for an example of drag-and-drop from a palette onto an HTML5 canvas fronted by the Konvajs library. There were no ready examples and I was curious about how to achieve it.
I answered the question in a codepen but decided to post here for (my own) future reference. See my answer below.
Here is my solution using jquery UI draggable & droppables. Konvajs requires jquery so the use of jquery UI is only a small step further. The palette is a set of small canvas elements with one shape drawn per draggable item. The palette can be housed on any html element and does not need to be attached to the main stage in any way.
// Set up the canvas to catch the dragged shapes
var s1 = new Konva.Stage({container: 'container1', width: 500, height: 200});
// add a layer to host the 'dropped' shapes.
var layer1 = new Konva.Layer({draggable: false});
s1.add(layer1);
// set up the palette of draggable shapes - 5 sample shapes.
var palletteEle = $('#pallette');
var d, ps, l, c;
for (var i = 0; i<5; i = i + 1){
// make a div to hold the shape
d = $('<div id="shape' + i + '" class="draggable">Shape</div>')
palletteEle.append(d)
// make a mini stage to hold the shape
ps = new Konva.Stage({container: 'shape' + i, width: 50, height: 50});
// make a layer to hold the shape
l = new Konva.Layer();
// add layer to palette
ps.add(l);
// make a shape - red circles for example
c = new Konva.Circle({x: 24, y: 24, radius: 22, fill: 'red', stroke: 'black'})
l.add(c);
ps.draw();
}
// make a crosshair to give some idea of the drop location
var cross = new Konva.Line({points: [10, 0, 10, 20, 10, 10, 0, 10, 20, 10],
stroke: 'gold',
strokeWidth: 1,
lineCap: 'round',
lineJoin: 'round'})
layer1.add(cross);
//s1.draw();
// make the main stage a drop target
$('#container1').addClass('droppable');
// function to move the cross hairs
function moveCross(x, y){
cross.x(x);
y = y - $('#container1').offset().top;
cross.y(y < 0 ? 0 : y);
s1.draw();
}
// draggable setup. Movecross used to move the crosshairs. More work needed but shows the way.
$( ".draggable" ).draggable({
zIndex: 100,
helper: "clone",
opacity: 0.35,
drag: function( event, ui ) {moveCross(ui.offset.left , ui.offset.top + $(this).offset().top)}
});
// set up the droppable
$( ".droppable" ).droppable({
drop: function( event, ui ) {
dropShape(ui.position.left, ui.position.top)
}
});
// Function to create a new shape when we drop something dragged from the palette
function dropShape() {
var c1 = new Konva.Circle({x: cross.x(), y: cross.y(), radius: 22, fill: 'red', stroke: 'black'});
layer1.add(c1);
cross.x(0); cross.y(0);
cross.moveToTop(); // move the cross to the top to stop going bahind previously dropped shapes.
s1.draw();
}
p
{
padding: 4px;
}
#container1
{
display: inline-block;
width: 500px;
height: 200px;
background-color: silver;
overflow: hidden;
}
#pallette
{
height: 52px; width: 500px;
border: 1px solid #666;
margin-bottom: 10px;
z-index: 10;
}
.draggable
{
width:50px;
height: 50px;
display: inline-block;
border: 1px solid #666;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdn.rawgit.com/konvajs/konva/1.6.5/konva.min.js"></script>
<p>Drag a red circle from the pallette and drop it on the grey canvas.
</p>
<div id='pallette'></div>
<div id='container1'></div>
I tried Vanquished Wombat's solution, it was a great example. But ultimately I wanted my palette to be separate from Konva. So I modified that original snippet to work with Html5 drag & drop, without any jQuery. See the snippet below. You can drag stars & circles from the palette into the Konva canvas. Currently you have to drop onto another shape, but you can modify it easily to drop anywhere on the canvas. I'm using text for the palette items and a custom image for the drag object just for fun. But you can just use an img instead of using the setDragImage code.
const CUSTOM_DATA_TYPE = 'text/x-node-type';
// Set up the canvas to catch the dragged shapes
var s1 = new Konva.Stage({
container: 'container1',
width: 500,
height: 200
});
// add a layer to host the 'dropped' shapes.
var layer1 = new Konva.Layer({
draggable: false
});
s1.add(layer1);
for (let t = 0; t < 10; t++) {
let rect = document.getElementById('container1').getBoundingClientRect();
let x = Math.floor(Math.random() * rect.width);
let y = Math.floor(Math.random() * rect.height);
let type = Math.floor(Math.random() * 100) % 2 == 0 ? 'circle' : 'star';
dropShape(x, y, type);
}
// Function to create a new shape when we drop something dragged from the palette
function dropShape(x, y, type) {
var shape;
if (type == 'circle') {
shape = new Konva.Circle({
x: x,
y: y,
radius: 22,
fill: 'blue',
stroke: 'black'
});
} else {
shape = new Konva.Star({
x: x,
y: y,
numPoints: 5,
innerRadius: 10,
outerRadius: 20,
fill: 'purple',
stroke: 'black'
});
}
layer1.add(shape);
s1.draw();
}
function cursorToCanvasPos(e) {
let clientRect = document.getElementById('container1').getBoundingClientRect();
let pointerPosition = {
x: e.clientX - clientRect.x,
y: e.clientY - clientRect.y,
};
return pointerPosition;
}
function getHoveredShape(e) {
let pointerPosition = cursorToCanvasPos(e);
return s1.getIntersection(pointerPosition);
}
function onDragStart(e, type) {
// Do this or other things can mess with your drag
e.stopPropagation();
e.dataTransfer.setData(CUSTOM_DATA_TYPE, type);
e.dataTransfer.effectAllowed = "all";
var dragIcon = document.createElement('img');
dragIcon.src = 'https://placehold.it/100x100';
dragIcon.width = 100;
e.dataTransfer.setDragImage(dragIcon, 150, 150);
}
function onDragOver(e) {
// Might break if you don't have this
e.stopPropagation();
// Breaks for sure if you don't have this
e.preventDefault();
let thing = getHoveredShape(e);
if (thing) {
e.dataTransfer.dropEffect = "move";
// Just fire off a custom even if you want to, this does nothing in this example.
thing.fire('htmlDragOver');
} else {
e.dataTransfer.dropEffect = "none";
}
}
function onDrop(e) {
e.stopPropagation();
let type = e.dataTransfer.getData(CUSTOM_DATA_TYPE);
let pos = cursorToCanvasPos(e);
dropShape(pos.x, pos.y, type);
}
p {
padding: 4px;
}
#container1 {
display: inline-block;
width: 500px;
height: 200px;
background-color: silver;
overflow: hidden;
}
#palette {
height: 52px;
width: 500px;
border: 1px solid #666;
margin-bottom: 10px;
z-index: 10;
}
#palette span {
width: 50px;
height: 25px;
display: inline-block;
border: 1px solid #666;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdn.rawgit.com/konvajs/konva/1.6.5/konva.min.js"></script>
<p>Drag circle/star from the palette onto an existing shape on the canvas below.
</p>
<div id='palette'>
<!-- Pre-load this image so it'll be used for our drag -->
<img src="https://placehold.it/100x100" style="display: none">
<span draggable="true" ondragstart="onDragStart(event, 'circle')">circle</span>
<span draggable="true" ondragstart="onDragStart(event, 'star')">star</span>
</div>
<div id='container1' ondragover="onDragOver(event)" ondrop="onDrop(event)"></div>

Image outside of div in infobubble

I am working on Google Map and showing an InfoWindow using the InfoBubble library. My problem is that when I show image for outside div with CSS properties it's showing half image that is within div.
Here is my CSS code:
#wider-header{
overflow: hidden;
display:inline-block;
width: 100px;
height: 300px;
}
#wide-header img {
position:relative;
top:-70px;
float:right;
border-radius: 50% 50% 50% 50%;
border: 2px solid #d81f27;
}
and the JavaScript:
infoBubble2 = new InfoBubble({
map: map,
content: "<div id='wide-header'><img id='jdImg' src='http://i.telegraph.co.uk/multimedia/archive/02474/cat-eyebrows-1_2474686k.jpg' width='100' height='100' alt='userImage'></div>",
position: new google.maps.LatLng(-35, 151),
padding: 10,
backgroundColor: '#fff',
borderRadius: 4,
arrowSize: 10,
borderWidth: 1,
borderColor: '#2c2c2c',
disableAutoPan: false,
hideCloseButton: true,
arrowPosition: 50,
arrowStyle: 3
});
infoBubble2.open();
The code above results in this:
How can I fix this?
i found my solution by changed these lines in infobubble.js library
// Content area
var contentContainer = this.contentContainer_ = document.createElement('DIV');
contentContainer.style['overflowX'] = 'auto';
contentContainer.style['overflowY'] = 'auto';
into
// Content area
var contentContainer = this.contentContainer_ = document.createElement('DIV');
contentContainer.style['overflowX'] = 'visible';
contentContainer.style['overflowY'] = 'visible';
Here is the required solution

Make text appear somewhere else on hover

I have an image, and when I hover over the image, I want to make text appear somewhere else on the screen. I've found lots of solutions making text appear on the image, but not somewhere else on the page. Any ideas?
Here's what I'm trying:
HTML:
<div class="dan-profile-picture"></div>
blah blah blah
<div class="dan-profile">lots of text</div>
CSS:
div.dan-profile-picture {
width: 150px;
height: 150px;
border-radius: 75px;
-webkit-border-radius: 75px;
-moz-border-radius: 75px;
background: url(./images/dan.jpg) no-repeat;
border:3px solid black;
}
div.dan-profile {
display:none;
}
div.dan-profile-picture:hover {
opacity:0.5;
}
div.dan-profile-picture:hover + div.dan-profile {
display:block;
}
if you prefer jQuery :
$('.dan-profile-picture').hover(function () {
var posx = Math.floor(Math.random() * $("body").width());
var posy = Math.floor(Math.random() * $("body").height());
$('.dan-profile').css({
'position': 'absolute',
'left': posx + 'px',
'top': posy + 'px',
'display': 'block'
});
});
Fiddle Demo
update
to hide the div, you can use either a call back function in existing jQuery - as mentioned in comments by user3008011
$('.dan-profile-picture').hover(function () {
var posx = Math.floor(Math.random() * $("body").width());
var posy = Math.floor(Math.random() * $("body").height());
$('.dan-profile').css({
'position': 'absolute',
'left': posx + 'px',
'top': posy + 'px',
'display': 'block'
});
},function(){ //this is call back function
console.log('out'); //will be triggered when main
$('.dan-profile').hide(); //function completes
});
demo
second way - since you are new to jQuery - you can trigger hide even on mouseout
$('.dan-profile-picture').mouseout(function () {
$('.dan-profile').css({
'display': 'none'
});
});
demo
make dan-profile a child of dan-profile-picture
.dan-profile-picture{
position:relative;
}
.dan-profile{
position:absolute;
right: -30px /* whichever value you desire */
top: -30px /*whichever value you desire */
display:none;
}
.dan-profile-picture:hover .dan-profile{
display:block;
}
hope this helps
This should do the trick.
div.dan-profile-picture {
width: 150px;
height: 150px;
border-radius: 75px;
-webkit-border-radius: 75px;
-moz-border-radius: 75px;
background: url(./images/dan.jpg) no-repeat;
border:3px solid black;
}
.dan-profile-picture:hover {
opacity:0.5;
}
.dan-profile{display:none;}
.dan-profile-picture:hover + .dan-profile{display:block;}
Fiddle
Remember that with the + selector, the element must be the directly next element. If there are elements in between, this selector won't work and you'll have to resort to javascript.
See this page for more info on css selectors
Number 7. of that list is the one I used for your user case
"This is referred to as an adjacent selector. It will select only the element that is immediately preceded by the former element."

Setting limit for mootools makeResizable dynamically?

I'm trying to set the upper limit values of a resizable image to keep it within the containing div. I'm using mootools to make the image both moveable and resizable (implementing Drag.Move and makeResizable to do so.)
My temporary solution is to use overflow:hidden; so the resized image does not overtake the rest of the page when it is sized beyond the container, but I'd like to be able to have a way so the image can not be resized outside of its container.
I know that since limit is set on 'domready', if I try to set it to a variable that changes value as the image is resized (ie: onDrag), the limit parameter won't be updated on the fly. I'm wondering if anyone has any insight into how I can achieve a similar effect to the Drag.Move container parameter, as makeResizable doesn't seem to have the same parameter.
HTML:
<div id="pImageArea">
<div id="pLogo" class="displayNone">
<div id="moveHandleName">
<img src="uploadedlogo.jpg" id="imgName" />
</div>
<div id="resizeHandleName"></div>
</div>
</div>
CSS:
#imageArea {
float: left;
width: 630px;
height: 400px;
border: 1px solid #333;
position: relative;
overflow: hidden;
}
#imgContainer {
width: 50px;
height: 50px;
border: 1px dashed #333;
position: absolute;
}
#imgName {
width: 100%;
}
#moveHandleName {
width: 100%;
height: 100%;
}
#resizeHandleName {
width: 8px;
height: 8px;
border: 1px solid #000;
position: absolute;
left: 100%;
top: 100%;
margin: -5px 0 0 -5px;
background-color: #fff;
z-index: 100;
}
JS:
window.addEvent('domready', function(){
var xLim = 50;
var yLim = 50;
// Make image moveable
new Drag.Move($('imgContainer'), {
container: $('imageArea'),
handle: $('imgHandleName')
});
// Make image resizable
$('imgContainer').makeResizable({
handle:$('handleName'),
limit: {x: [50, xLim], y: [50, yLim]},
onDrag: function(el) {
// Set imgContainer height
el.setStyle('height', $('imgName').getSize().y + 'px');
// Set upper limits
xLim = $('imageArea').getSize().x - el.getSize().x;
yLim = $('imageArea').getSize().y - el.getSize().y;
},
});
});
Thanks in advance,
Matt
I 'solved' it like this in my own code (modified to use your element and values):
$('imgContainer').retrieve('resizer').setOptions({
limit: {
x: [50, xLim],
y: [50, yLim]
}
});
The move limit should be properly enforced once you specify the 'container' option and your container has a set width and height. When you resize, my draggable does not need to have limits (re)set. (Using Moo 1.4 by the way.)
However, resizing does cause problems in conjunction with move and limits. The key is that the 'limit' option is only set when initializing makeResizable(). The only way to update it is by setting it with the code shown above. But you have to update it right after you dropped the draggable, because that's the only event that affects the limit. So:
// Make image moveable
new Drag.Move($('imgContainer'), {
container: $('imageArea'),
handle: $('imgHandleName'),
onDrop: function() {
$('imgContainer').retrieve('resizer').setOptions({
limit: {
x: [50, $('imageArea').getSize().x - parseInt($('imageArea]).getStyle('left'))],
y: [50, $('imageArea').getSize().y - parseInt($('imageArea]).getStyle('top'))]
}
});
});
As you can see, I've also used getStyle() instead of getPosition() because getPosition() returns a value relative to the window, while Moo sets the draggable top and left relative to the droparea.