Alerting after resizing an element - javascript

How do I put an alert message just after am done re-sizing an element? That is, after the element has been re-sized.
resizeend() method not working.

check below link with
$( $clone ).resizable({
stop:function(){
hello();
},
});
check below link for more , which uses jquery ui for resizing and invoking javascrip after resize occurs
Fiddle
html content
<div class = "resizethis">
resize this widget
two js libraries
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
one css
<link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
javascript content
$('.resizethis').resizable({
stop: resizestopped
});
function resizestopped(){
alert('resize stopped');
}
css
.resizethis{
width: 100px;
height: 100px;
border: 2px solid red;
}

Related

JSPlumb v1.4.1 draggable/resizable example not working anymore with v2.0.7

I need to connect draggable and resizable <div> elements with JSPlumb.
I was looking at this tutorial it uses v1.4.1 of JSPlumb. I have a very simmilar code as the example in the tutorial:
<!DOCTYPE html>
<html ng-app="">
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<style>
#diagramContainer {
padding: 20px;
width:80%; height: 400px;
border: 1px solid gray;
}
.item {
position: absolute;
height:80px; width: 80px;
border: 1px solid blue;
}
</style>
</head>
<body>
<div id="diagramContainer">
<div id="item_left" class="item"></div>
<div id="item_right" class="item" style="left:150px;"></div>
</div>
<p>Visit the full jsPlumb-Tutorial to learn it and see many more interesting examples.</p>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jsPlumb/1.4.1/jquery.jsPlumb-1.4.1-all-min.js"></script>
<script>
$(".item").resizable({
resize : function(event, ui) {
jsPlumb.repaint(ui.helper);
}
});
jsPlumb.ready(function() {
jsPlumb.connect({
source:"item_left",
target:"item_right",
endpoint:"Rectangle"
});
jsPlumb.draggable("item_left");
jsPlumb.draggable("item_right");
});
</script>
</body>
</html>
( Here is a jsFiddle like demonstration: http://www.freedevelopertutorials.com/jsplumb-tutorial/examples/jsplumb-resizable-divs-example/ of the code)
If I switch the JSPlumb version in the sample code above from v1.4.1 to v2.0.7 resizingan element also starts draggingit.
I found the following stackoverflow question jsPlumb issue using drag and resize but I could not understand the answer.
I tried the following:
not using jsPlumb.draggable("item_left"); and instead just
$(".item").draggable({
drag: function (event, ui) {
jsPlumb.repaint(ui.helper);
}
});
Then the line gets drawn but does not follow the resize/drag
movement of the items.
Can anybody tell me how to get the example to work with the new version?
Thanks a lot
For the newer versions of JsPlumb the bug persists. In this case, just use the filter option in the drag options.
jsPlumb.draggable((element), {
filter: ".ui-resizable-handle"
});
https://github.com/jsplumb/katavorio/wiki#filtering

I can't seem to apply Jquery to my Microsoft Visual Studio

Can anyone suggest me a solution please? I've been trying half an hour to get jQuery ready and working for my Visual Studio but it does not work. I can't really be specific because i also don't know why.
<script>
$(document).ready(function () {
$("button").click(function () {
$("#square").animate({ left: '500px' }, slow);
});
});
</script>
<style>
#square{
border: solid; border-color: aqua; border-width: 1px; background-color: skyblue; width: 125px; height: 125px; text-align:center;
}
</style>
<body>
<div id="square">Focus on me!</div>
<div> <button>Click me</button> </div>
You have to add jquery to your page. You can add jQuery in two ways :
Download the jQuery library from jQuery.com
Include jQuery from a CDN, like Google
The jQuery library is a single JavaScript file, and you reference it with the HTML tag :
<head>
<script src="jquery-1.11.3.min.js"></script>
</head>
And for CDN :
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
then write your code :
$(document).ready(function(){
alert("Hello there!")
});
Add this piece of code above the closing body tag.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
Now you have successfully added jQuery!

jQuery resizable issue if applied to child element of a resizable

Here is my complete code, which is derived from jQuery Resizable Example -
In my example I have two div elements, with id parent and child, where child element is inside parent element. My Problem is I am not able to resize parent element, even I have made it resizable. Has anyone faced the similar issue?
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Resizable - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<style>
#parent {
padding: 40px;
width:400px;
height:400px;
}
#child {
width: 150px;
height: 150px;
}
</style>
<script>
$(function() {
$( "#child" ).resizable();
$( "#parent" ).resizable();
});
</script>
</head>
<body>
<div id="parent" class="ui-widget-content">
<h3>Parent</h3>
<div id="child" class="ui-widget-content">
<h3>Child</h3>
</div>
</div>
</body>
</html>
NOTE
Playing with the code, I just found out, this problem only occur is I make child element reseizable before parent element. As in code -
$(function() {
$( "#child" ).resizable();
$( "#parent" ).resizable();
});
If I change the order to -
$(function() {
$( "#parent" ).resizable();
$( "#child" ).resizable();
});
it will work smoothly. I am not sure why it is happening.
I will try looking into jQuery resizable code but if someone already have faced and solve this issue it will be very helpful.
-Thanks
A ticket has been opened about this on jQuery bugtracker (ticket #7711), but as you can see, it was considered has "not a bug", specifying the work-around you found by yourself as a solution:
As a work-around, initialize the outer/parent resizable first and both are resizable

Can't drag a textbox properly using jquery

I am new to jquery. I am trying to drag and resize a textbox using jquery. But i am facing some problems. I could drag and re-size the text box. But.. just look at the below screenshot.
To drag the text box, first i have to drag and move that "Edge" (showed in arrow mark), out of the box.
In all mean, it is not a good idea. So can somebody help me to simply drag the textbox?
below is my code
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Draggable - Constrain movement</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<style>
#containment-wrapper { width: 300px; height:300px; border:2px solid #ccc; padding: 10px; }
#custombox { width: 160px; height: 30px; padding: 0.5em; float: left; }
</style>
<script>
$(function()
{
$("#custombox").draggable({ containment: "#containment-wrapper", scroll: false }).resizable();
});
</script>
<body>
<div id="containment-wrapper">
<div id="custombox" >
<textarea></textarea> </p>
</div>
</div>
</body>
</html>
When i tried the code in jsfiddle.net, the textbox is non-dragable. Only resize is possible. But i copied the code to notepad and run it on chrome. Then the problem in the screenshot appeared.
After drag the edge outside the textbox, the box can be dragged to anywhere in the containment.
Check this
$(function()
{
$("#custombox").draggable({ scroll: false }).resizable();
});
Fiddle

Error in using contextmenu in jquery?

I want to create a contextmenu of a div tag to append some contents into it.
But when i right click many times continuously,my div tag contains more contents than i want.Here is my code.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<style type="text/css">
#container{
width: 500px;
height: 500px;
border: 1px solid red;
position: relative;
}
#MyMenu{
position: absolute;
border: 1px solid blue;
}
</style>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#container').bind('contextmenu',function(e){
e.preventDefault();
var x=e.pageX;
var y=e.pageY;
$('#MyMenu').css({'top': y+'px','left': x+'px'}).show();
$('#add').click(function(e){
var ContentToAppend='<p>My Content</p>';
$('#container').append(ContentToAppend);
});
});
});
</script>
</head>
<body>
<div id="container">
</div>
<ul id="MyMenu">
<li>Add</li>
<li>Delete</li>
</ul>
</body>
</html>
For example,if i right click 5 times continuously,in my div will contain 5 lines "My Content" although i only want 1 line.Can anyone explain why and solution for me?Thank a lot!
Try (See DEMO):
$(document).ready(function(){
$('#container').bind('contextmenu',function(e){
e.preventDefault();
var x=e.pageX;
var y=e.pageY;
$('#MyMenu').css({'top': y+'px','left': x+'px'}).show();
});
$('#add').click(function(e){
var ContentToAppend='<p>My Content</p>';
$('#container').append(ContentToAppend);
});
});​
The deal is that in your version you bind to #add element click event hendler each time user open context menu. So after 5 times it heppens there will be 5 click event hendlers, so if you then click on #add element you add '<p>My Content</p>' string to #container element 5 times.

Categories