Resize Div on Click and MouseDown - jquery-ui

I'm using jQuery UI. #scene1 is currently being resized and works perfectly when I drag the edge. But, #scene1 needs to be resized when the users mouse is down on #LeftArrow.
I don't understand resize start() or stop() and how to use mouse events. Can someone please help me out?
$('#scene1').resizable({
maxWidth: 300,
maxHeight: 600,
minHeight: 600,
minWidth: 0,
handles: 'e',
});
#LeftArrow {
position: absolute;
background-image: url('../graphics/LeftArrow.jpg');
width: 51px;
height: 71px;
bottom: 156px;
right: 0px;
}
<div id = "codeSection"></div>
<div id = "scene1">
<div id = "LeftArrow"></div>
</div>
<div id = "scene2">
<div id = "S1_Image"><img src = "graphics/S2_Image.jpg"></div>
<div id = "CTAs">
<div id="CTA1" class="transButton">Learn more</div>
<div id="CTA2" class="transButton">Explore</div>
</div>
</div>

You need a link that calls a JS function that sets your width and height.
<style>
#LeftArrow {
position: absolute;
background-image: url('../graphics/LeftArrow.jpg');
width: 51px;
height: 71px;
bottom: 156px;
right: 0px;
}
</style>
<script>
$('#scene1').resizable({
maxWidth: 300,
maxHeight: 600,
minHeight: 600,
minWidth: 0,
handles: 'e',
});
function resizeLeftArrow(){
$('#LeftArrow').width(555);
$('#LeftArrow').height(555);
}
</script>
<div id = "codeSection"></div>
<div id="scene1">
<div id="LeftArrow">click me to grow bigger</div>
</div>

Related

Highcharts doesn't resize properly once expanded

For some reason once you expand the window the chart doesn't resize down properly. You should still be able to see the red spacer.
I made an example here: https://jsfiddle.net/bryaan/pjyzxbdu/10/
<div class="table-row">
<div class="table-cell">
<div id="container"></div>
</div>
<div class="table-cell">
<div class="spacer"></div>
</div>
</div>
.table-row {
display: flex;
margin 10px;
}
.table-cell {
width: 100%;
height: 100%;
min-height: 100px;
}
.spacer {
width: 100%;
height: 100px;
background-color: red;
}
If you want to achieve two equal boxes sets display:flex to parent and add children width: 50%.
.flex {
display: flex;
}
#container {
width: 50%;
}
.spacer {
width: 50%;
height: 500px;
background-color: red;
}
Demo: https://jsfiddle.net/BlackLabel/46o7venk/

How to detect when draggable hits top or bottom of containment in jQuery UI

I am working on the below demo. How can I detect when .draggable hits top and bottom of its containment?
$(function(){
var draggableRight;
var draggableWidth = $('.draggable').height();
var parentWidth = $('#parent').height();
$('.draggable').draggable({
containment: 'parent',
axis: "y",
drag: function(e, ui){
// ==> if .draggable hits top of parent change it's background red
// $(document).trigger("mouseup");
// $('.draggable').css({ background: 'red' });
// ==> if .draggable hits bottom of parent change it's background blue
// $(document).trigger("mouseup");
// $('.draggable').css({ background: 'blue' });
}
});
});
#parent {
background: khaki;
width: 400px;
height: 200px;
position: relative;
margin:20px;
padding:0px;
}
.draggable {
background: #fff;
width: 400px;
height: 50px;
margin:0px;
background: red;
}
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id="parent">
<div class="draggable"></div>
</div>
You will want to use the position or offset from the UI object.
Consider the following:
$(function() {
var draggableRight;
var draggableWidth = $('.draggable').height();
var parentWidth = $('#parent').height();
$('.draggable').draggable({
containment: 'parent',
axis: "y",
drag: function(e, ui) {
var p = {
top: ui.offset.top - $("#parent").offset().top,
bottom: (ui.offset.top - $("#parent").offset().top) + $(this).height()
};
$("#log").html(p.top + ", " + p.bottom);
if (p.top == 0) {
console.log("Hit Top");
}
if (p.bottom == $("#parent").height()) {
console.log("Hit Bottom");
}
}
});
});
#parent {
background: khaki;
width: 400px;
height: 200px;
position: relative;
margin: 20px;
padding: 0px;
}
.draggable {
background: #fff;
width: 400px;
height: 50px;
margin: 0px;
background: red;
}
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id="parent">
<div class="draggable"></div>
</div>
<div id="log"></div>

Set different max/min- height, width on multiple elements with jqueryUI resizable

I am using jQuery-UI resizable on three elements, like this:
$("#element1, #element2, #element3").resizable();
All good and well.. BUT I need to set max/min- height, width. I can't see way in the documentation nor in the example to give the elements different (as in unique for each element selected) values on these:
maxHeight:
maxWidth:
minHeight:
minWidth:
That means that I will have to call the .resizable() one time for each element.... That doesn't feel optimal. Like this:
$("#element1").resizable({
maxHeight:
maxWidth:
minHeight:
minWidth:
});
$("#element2").resizable({
maxHeight:
maxWidth:
minHeight:
minWidth:
});
$("#element3").resizable({
maxHeight:
maxWidth:
minHeight:
minWidth:
});
What I would have liked is something like this:
$("#element1, #element2, #element3").resizable({
[
maxHeight: 111, //#element1
maxWidth: 111,
minHeight: 111,
minWidth: 111,
],
[
maxHeight: 222, //#element2
maxWidth: 222,
minHeight: 222,
minWidth: 222,
],
[
maxHeight: 333, //#element3
maxWidth: 333,
minHeight: 333,
minWidth: 333,
],
});
Is this somehow doable?
I believe you can achieve it this way inside of the resizable start event.
Give all of your resizable elements a common class.
You can use a switch statement, still quite a lot to write.
$('.widget').resizable({
start: function(event,ui) {
var hasId = ui.element.attr('id');
switch(hasId ){
case '#element1':
ui.element.resizable('option','maxHeight', 111);
ui.element.resizable('option','maxWidth', 111);
break;
case '#element2':
ui.element.resizable('option','maxHeight', 222);
ui.element.resizable('option','maxWidth', 222);
break;
case '#element3':
ui.element.resizable('option','maxHeight', 333);
ui.element.resizable('option','maxWidth', 333);
break;
}
}
});
Or, you could use data attributes to set the maxHeight and maxWidth like so:
$(function() {
$('.widget').resizable({
start: function(event,ui) {
var minH = $(this).attr('data-minH');
var maxH = $(this).attr('data-maxH');
var minW = $(this).attr('data-minW');
var maxW = $(this).attr('data-maxW');
$(this).resizable('option', 'minHeight', minH);
$(this).resizable('option', 'maxHeight', maxH);
$(this).resizable('option', 'minWidth', minW);
$(this).resizable('option', 'maxWidth', maxW);
}
});
});
.widget {
width: 100px;
height: 100px;
background: #333;
border: 1px solid #555;
position: relative;
display: inline-block;
}
.ui-resizable-se {
width: 20px;
height: 20px;
background: #555;
position: absolute;
bottom: 0;
right: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div id="element1" class="widget" data-minH="100" data-maxH="100" data-minW="100" data-maxW="100"></div>
<div id="element2" class="widget" data-minH="100" data-maxH="200" data-minW="100" data-maxW="200"></div>
<div id="element3" class="widget" data-minH="100" data-maxH="300" data-minW="100" data-maxW="300"></div>

jQuery click function returning undefined from 2nd time onwards

Hi i'm working with loading video in jqueryui Dialog. When i click first time its working fine. But when i click on the same element again its throwing an empty dialog.
Below is the code snippet for my work.
$(function() {
$(document).on('click', '.wmBox', function(ev) {
ev.preventDefault();
//console.log($(this).children());
var data = $(this).children('div').attr('id');
var title = $(this).children('div').attr('title');
//console.log(data + '----' + title);
$('#' + data).show();
$('#' + data).appendTo('#dialogDiv').removeClass('hide');
ht = $(document).height() / 2;
wd = $(document).width() / 2;
$('video').height(ht);
$('video').width(wd);
$('#dialogDiv').dialog('open');
$('#dialogDiv').dialog({
title: title,
height: 'auto',
width: 'auto'
});
});
$("#dialogDiv").dialog({
autoOpen: false,
modal: true,
minWidth: 500,
minHeight: 300,
open: function() {
$('.ui-widget-overlay').bind('click', function() {
$('#dialogDiv').html('');
$('#dialogDiv').dialog('close');
});
}
});
setInterval(function() {
$('a[href] div').each(function() {
var dure = $(this).find('video').get(0).duration;
var minutes = parseInt(dure / 60, 10);
var seconds = Math.round(dure % 60, 2);
//console.log(minutes+':'+seconds+' min');
$(this).parent().children('span').html(minutes + ':' + seconds + ' min');
});
}, 500);
});
a.wmBox {
width: 150px;
height: 150px;
float: left;
margin: 5px;
position: relative;
}
a.wmBox img {
width: 150px;
height: 150px;
}
.hide {
display: none;
}
img {
width: 250px;
height: 250px;
}
.size {
position: absolute;
top: 0px;
right: 0px;
width: auto;
background: rgba(0, 0, 0, 0.6);
color: #fff;
font-weight: bold;
}
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="dialogDiv"></div>
<a class="wmBox" id="dm" href="#">
<img src='http://media.w3.org/2010/05/sintel/poster.png' />
<span class="size"></span>
<div id="dia_mes" title="Ninja" class='hide'>
<video preload='metadata' class='vidBox' controls>
<source src='http://media.w3.org/2010/05/sintel/trailer.mp4'>
</video>
</div>
</a>
<a class="wmBox" id="dm1" href="#">
<img src='http://media.w3.org/2010/05/bunny/poster.png' />
<span class="size"></span>
<div id="dia_mes1" title="Bunny" class='hide'>
<video preload='metadata' class='vidBox' controls>
<source src='http://media.w3.org/2010/05/bunny/trailer.mp4
'></source>
</video>
</div>
</a>
Calling .dialog({}) reinitialises the widget:
$('#dialogDiv').dialog({
title: title,
height: 'auto',
width: 'auto'
});
Use the option method instead, https://api.jqueryui.com/dialog/#method-option :
$('#dialogDiv').dialog('option', {
title: title,
height: 'auto',
width: 'auto'
});
$(function() {
$(document).on('click', '.wmBox', function(ev) {
ev.preventDefault();
//console.log($(this).children());
var data = $(this).children('div').attr('id');
var title = $(this).children('div').attr('title');
//console.log(data + '----' + title);
$('#' + data).show();
$('#' + data).appendTo('#dialogDiv').removeClass('hide');
ht = $(document).height() / 2;
wd = $(document).width() / 2;
$('video').height(ht);
$('video').width(wd);
$('#dialogDiv').dialog('open');
$('#dialogDiv').dialog('option', {
title: title,
height: 'auto',
width: 'auto'
});
});
$("#dialogDiv").dialog({
autoOpen: false,
modal: true,
minWidth: 500,
minHeight: 300,
open: function() {
$('.ui-widget-overlay').bind('click', function() {
$('#dialogDiv').html('');
$('#dialogDiv').dialog('close');
});
}
});
setInterval(function() {
$('a[href] div').each(function() {
var dure = $(this).find('video').get(0).duration;
var minutes = parseInt(dure / 60, 10);
var seconds = Math.round(dure % 60, 2);
//console.log(minutes+':'+seconds+' min');
$(this).parent().children('span').html(minutes + ':' + seconds + ' min');
});
}, 500);
});
a.wmBox {
width: 150px;
height: 150px;
float: left;
margin: 5px;
position: relative;
}
a.wmBox img {
width: 150px;
height: 150px;
}
.hide {
display: none;
}
img {
width: 250px;
height: 250px;
}
.size {
position: absolute;
top: 0px;
right: 0px;
width: auto;
background: rgba(0, 0, 0, 0.6);
color: #fff;
font-weight: bold;
}
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="dialogDiv"></div>
<a class="wmBox" id="dm" href="#">
<img src='http://media.w3.org/2010/05/sintel/poster.png' />
<span class="size"></span>
<div id="dia_mes" title="Ninja" class='hide'>
<video preload='metadata' class='vidBox' controls>
<source src='http://media.w3.org/2010/05/sintel/trailer.mp4'>
</video>
</div>
</a>
<a class="wmBox" id="dm1" href="#">
<img src='http://media.w3.org/2010/05/bunny/poster.png' />
<span class="size"></span>
<div id="dia_mes1" title="Bunny" class='hide'>
<video preload='metadata' class='vidBox' controls>
<source src='http://media.w3.org/2010/05/bunny/trailer.mp4
'></source>
</video>
</div>
</a>
Finally i was able to solve the issue by doing some debugging and research.
jQuery(document).ready(function() {
jQuery(document).on('click','a[href]',function(ev){
ev.preventDefault();
var data = jQuery(this).children('div').attr('id');
var title = jQuery(this).children('div').attr('title');
jQuery('#' + data).appendTo('#dialogDiv').removeClass('hide');
ht = $(document).height()/2;
wd = $(document).width()/2;
vidht = (ht*3)/4;
vidwd = (wd*3)/4;
$('video').height(vidht);
$('video').width(vidwd);
jQuery('#dialogDiv').data('link', $(this).attr('id')).dialog('open');
jQuery('#dialogDiv').dialog('option',{
title: title,
height: ht,
width: wd
});
});
jQuery("#dialogDiv").dialog({
autoOpen: false,
modal: true,
minWidth: 500,
minHeight: 300,
open: function(){
var id = $(this).data('link');
jQuery('.ui-widget-overlay').data('aid', id).bind('click',function(){
var id = $(this).data('aid');
var ret_data = $(this).parent().find('#dialogDiv').html();
var ret_id = $(ret_data).attr('id');
var title= $(ret_data).attr('title');
jQuery('.wmBox#'+id).append('<div id="'+ret_id+'" title="'+title+'">'+$("#"+ret_id).html()+'</div>');
if(jQuery('.wmBox#'+id).children('div').find(ret_id))
{
jQuery('#'+ret_id).addClass("hide");
}
jQuery('#dialogDiv').html('');
jQuery('#dialogDiv').dialog('close');
});
}
});
setInterval(function(){
jQuery('a[href] div').each(function(){
var dure= jQuery(this).find('video').get(0).duration;
var minutes = parseInt(dure / 60, 10);
var seconds = Math.round(dure % 60, 2);
jQuery(this).parent().children('span').html(minutes+':'+seconds+' min');
});
},500);
});
a.wmBox {width: 250px; height: 250px;float: left; margin: 5px; position: relative;}
a.wmBox img {width: 250px; height: 250px;}
.hide {
display: none;
}
img {width: 250px; height: 250px;}
.size{ position: absolute; top: 0px; right: 0px; width: auto;
background: rgba(0,0,0,0.6);
color: #fff; font-weight: bold;
}
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="dialogDiv"></div>
<a class="wmBox" id="dm" href="#" data-popup="vendor_reg.mp4">
<img src='http://media.w3.org/2010/05/sintel/poster.png' />
<span class="size"></span>
<div id="dia_mes" title="Ninja" class='hide'>
<video preload='metadata' class='vidBox' controls>
<source src='http://media.w3.org/2010/05/sintel/trailer.mp4'>
</video>
</div>
</a>
<a class="wmBox" id="dm1" href="#">
<img src='http://media.w3.org/2010/05/bunny/poster.png' />
<span class="size"></span>
<div id="dia_mes1" title="Bunny" class='hide'>
<video preload='metadata' class='vidBox' controls>
<source src='http://media.w3.org/2010/05/bunny/trailer.mp4
'></source>
</video>
</div>
</a>

OpenLayers 2.12+ and JQueryUI draggable panel

I have a problem with Openlayers 2.12+ and JQueryUI draggable panel that contains OL tools. The panel locks drag.
CSS:
herramientas {
position: absolute; top: 15px; left: 45px; width: 250px; height: 35px; z-index:99999; cursor: move;
background: #000000; }
#herramientas div {
float: left;
margin: 5px; }
HTML:
<body>
<div id="mapcontainer" style="width: 650px; height: 500px; position: relative">
<div id="map" style="width:100%; height:100%"></div>
<div id="herramientas"></div>
</div>
</body>
JavaScript:
var map, layer;
$(document).ready(function () {
$("#herramientas").draggable({containment: "#mapcontainer"});
map = new OpenLayers.Map( 'map' );
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{layers: 'basic'} );
map.addLayer(layer);
map.zoomToMaxExtent();
nav = new OpenLayers.Control.NavigationHistory();
map.addControl(nav);
panel = new OpenLayers.Control.Panel(
{div: document.getElementById("herramientas")}
);
panel.addControls([nav.next, nav.previous]);
map.addControl(panel);
});
The code demo can see in http://jsfiddle.net/leal33/49bP9/
The same example with OpenLayers 2.11 working perfectly --> http://jsfiddle.net/leal33/49bP9/1
It's a bug of OpenLayers? Any solution?
Thanks

Resources