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

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>

Related

Image rounding on Android but not on iOS

Edit 3: What worked for me
<View
style={{
minHeight: 200
}}
>
<Image
resizeMode="contain"
source={{ uri: props.item.thumbnailURL }}
style={{
flex: 1,
width: 350,
height: 200,
borderBottomLeftRadius: 30,
borderBottomRightRadius: 30,
borderTopLeftRadius: 30,
borderTopRightRadius: 30,
borderColor: "orange",
borderWidth: 1,
overflow: "hidden",
flexDirection: "row",
alignSelf: "center",
}}
/>
</View>
Edit 2: Added full code
Edit: I added
borderWidth: 3, borderColor: "orange"
and noticed that the parent of the image is rounding screenshot ... But why? I didn't want that.
I also tried with
borderRadius: Platform.OS === "ios" ? 30/2 : 30 but it didn't have any effect. What more can I do?
You must specify border radius value for all of the corners for ios
for example:
{
flex: 1,
width: 350,
height: 200,
borderRadius:30,
overflow: "hidden",
borderBottomLeftRadius: 30,
borderBottomRightRadius: 30,
borderTopLeftRadius: 30,
borderTopRightRadius: 30,
}

what is the problem with my left alignment?

I use konva.js and I try to align texts with the align function but I can't do it with the left alignment (right and center works on the other hand)
my code
var text1 = new Konva.Text({
y: 26,
fontSize: 40,
text: 'ligne1',
draggable: true,
width : 550,
align: 'center',
});
layer.add(text1);
layer.draw();
Thank you
The text.align() method sets the alignment. In the snippet below I have drawn a rect around the text shape to give a visualisation of the effect.
let
// Set up a stage
stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight
}),
layer = new Konva.Layer(),
rect = new Konva.Rect({
x: 0,
y: 26,
width: 550,
height: 40,
stroke: 'magenta'
}),
text1 = new Konva.Text({
y: 26,
fontSize: 40,
text: 'ligne1',
draggable: true,
width: 550,
align: 'center',
fill: 'cyan'
});
stage.add(layer);
layer.add(rect, text1);
layer.draw();
$('#left').on('click', function() {
text1.align('left');
layer.draw();
})
$('#center').on('click', function() {
text1.align('center');
layer.draw();
})
$('#right').on('click', function() {
text1.align('right');
layer.draw();
})
body {
margin: 10;
padding: 10;
overflow: hidden;
background-color: #f0f0f0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/konva#^3/konva.min.js"></script>
<p>Click a button to change alignment of the text.</p>
<button id='left'>Left</button>
<button id='center'>Center</button>
<button id='right'>Right</button>
<div id="container"></div>

Is it possible to make custom shaped label w/o use of html in highcharts?

I have animated moving label
plotbandLabel.animate({
y : yAxis.toPixels(y) - labelOffset
}, {
duration : 500,
step : function () {
this.attr({
text : yAxis.toValue(this.y + labelOffset).toFixed(2),
zIndex : 999999999
})
},
complete : function () {
this.attr({
text : y.toFixed(2),
zIndex : 999999999
})
}
});
Here is the full example: http://jsfiddle.net/7yo3nht4/
And I need this label to be shaped like an arrow:
If you omit fill property in renderer.label the label's box won't be created:
plotbandLabel = this.renderer.label(
(...)
)
.css({
(...)
}).attr({
(...)
//fill: 'red' // no fill
})
.add();
Then you can create a custom path and append it to the plotbandLabel SVG group:
this.renderer.path(['m', -10, 15, 'l', 15, -15, 'l', 50, 0, 'l', 0, 30, 'l', -50, 0, 'l', -15, -15, 'z']).attr({
fill: 'rgba(0, 0, 0, 0.75)'
}).add(plotbandLabel);
Live demo: http://jsfiddle.net/kkulig/hqyfpsw4/
API reference: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#path
The label renderer has this form:
label: function (str, x, y, shape, anchorX, anchorY, useHTML, baseline, className)
So if useHTML=true the string could be an HTML string like this:
var txt = '<div class="arrow_box">'+(66).toFixed(2)+'</div>';
and applying a proper CSS:
.arrow_box {
color: #FFFFFF;
position: relative;
background: rgba(0, 0, 0, 0.75);
border: 0px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 5px;
padding-right: 5px;
width: 50px;
}
.arrow_box:after, .arrow_box:before {
right: 100%;
top: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.arrow_box:after {
border-color: rgba(255, 0, 0, 0)
border-right-color: rgba(0, 0, 0, 0.75);
border-width: 20px;
margin-top: -20px;
}
.arrow_box:before {
border-color: rgba(0, 255, 0, 0);
border-right-color: rgba(0, 0, 0, 0.75);
border-width: 20px;
margin-top: -20px;
}
You can obtain an arrow box as a label.
Check the fiddle updated: http://jsfiddle.net/beaver71/eenjkv5c/

iOS 11 browsers image bug

I'm getting the following error in iOS 11 when scrolling through the page.
(In Firefox, Safari and Chrome). In Android devices the error is not happening.
These are background images, I don't know if that could be the reason that's causing the error.
Image 2 shows how the image is intended and shown in Android.
<div
className="shelf-page-lists-icons-background"
style={containerImage}
/>
<div
style={styles.container}
>
<p style={styles.listsTitle}>{list.title}</p>
</div>
CSS
containerImage = {
backgroundImage: url(${list.image}),
backgroundSize: 'cover',
height: 150,
borderRadius: 4,
position: 'absolute',
width: imageWidth,
overflow: 'hidden',
}
container: {
height: 150,
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-end',
marginBottom: 10,
padding: '0px 40px 13px 16px',
},
.shelf-page-lists-icons-background {
opacity: 0.84;
filter: brightness(0.4)
}
The problem seems to be related to the filters: Slow CSS Filters on iPhone?
I added these properties as metioned above and it seems to work:
-webkit-transform: translateZ(0);
-webkit-perspective: 1000;
-webkit-backface-visibility: hidden;

Resize Div on Click and MouseDown

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>

Resources