I am working in javaScript an jquery-ui an want to ask a question about resizing.Is it possible to resize only diagonally i.e Suppose I have a rectangle having width 200 and height 100 and I want to resize it by grabbing it one corner only in such a way that both height and width will increase together keeping the width/height ratio same and I am not allowed to increase only height or only width.
I have tried it using the handle option of resizable
$("#resizable").resizable({
handles: 'se'
});
JSFiddle example is here Resizing only diagonally
But still I am able to increase only height or only width changing my width/height ratio.
I am sorry if I am not clear.
Thanks Any help will be appreciated.
user like
<script>
$(function() {
$( "#resizable" ).resizable({
aspectRatio: 16 / 9 //(in your case it should be 2/1)
});
});
</script>
http://jqueryui.com/demos/resizable/aspect-ratio.html
updated demo
http://jsfiddle.net/bx2mk/765/
Related
I have a problem with Jquery UI Resizable feature.
I am using Jquery resizable to resize a div to different width and height.
it is working good, but when i try to reduce the height to a very low number, it is not reducing less than a certain aspect ratio
`
$( 'divname' ).resizable({
minHeight: 1
});
`
In the above code eventhough i try to give 1 pixel as the minHeight, I am not able to resize the div less than 10px. Please help with the above?
you can set minHeight upto 10 not below that.
Go throught this https://api.jqueryui.com/resizable/#option-minHeight
$( ".selector" ).resizable({
minHeight: 150
});
I have a slider that is finished, but I have 1 issue.
I need to re-size the container to the windows size.
As you can see here
jQuery(document).ready(function(){
$(".toggle_window").click(function(){
$("#content").slideToggle("slow");
});
});
the slider disappear and I dont have any change to press the button so collapse the container again.
The problem I think is here #left and the high of this (height: 880px;), but I need to expand this guy at 95% of the webpage.
Which will be the best way to re-size the container?
I will appreciate your help.
Thnx in advance!
Cheers.
element #left height is set wrongly in your fiddle. Try setting the element height on document ready as
$("#left").height($( window ).height() - $("footer").position().left + 10);
If you want exactly 95% try like this,
$("#left").height($(window).height() /100 * 95 - $("footer").position().left);
I'm working on a template showcasing soccer players stats.
On the left there is the .picture of the player. It's fixed and the height is 100% of the window. Its width increases or decreases when you reduce the height of the window.
On the right, you should find the players stats and biography. It all fit in the div .block-left. The width should be 100% minus the player .picture width.
For now, the only way to showcase it is to increase the value of margin-left with the same value as the .picture width.
Here lies the problem, .picture width is always changing depending on your screen resolution, so should the margin-left of .block-content.
I can't find a practical way to do this. Maybe jQuery?
The template is available here : http://bettercheckthekids.com/pirlo/index.html
It's not a popular design but yes you can do it with jQuery using window resize event.
$(window).resize(function () {
var imgWidth = $(".picture img").width();
$(".block-left").css("margin-left", imgWidth);
});
I'm using some script I found on Git that generates a snow effect. Somewhere in the code I have to set the width and the height of the canvas in which the snow is generated. I'm setting the canvas to the window full width / height :
canvas.width = $(window).width();
canvas.height = $(window).height();
But when rendered in the browser there are on both height and width some extra pixels adding scrollbars to the window. You can see the behavior here : Canvas ; I'm not quite sure why the width / height is calculated wrong or if there's something else interfering with those calculations that it makes it bigger than the actual window width / height. Maybe someone has a different view of the behavior or encountered it before ?
The canvas element is displayed inline by default, you can read here about similar problem.
The solution is quite simple :) Add following css code to the canvas element:
display: block;
and scrollbars should disappear.
old answer:
$(window).width() works properly but i don't know why $(window).height() returns too large value. It cause also showing vertical scrollbar because earlier computed width don't include the size of horizontal scrollbar.
I'm trying to optimise my website for different resolutions. In the center of the website I have a DIV that currently has a fixed size. I'm trying to make its size (and contents) change according to the size of the browser window. How do I do that?
This is my website if you want to take a look at its code:
http://www.briefeditions.com
If you resize the page the div will resize with it and on load of the page.
$(window).on('load resize', function(){
$('#div').width($(this).width());
});
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
$(document).ready(function(){
var windowHeight = $(window).height();
$('#divID').css('min-height',windowHeight+'px');
});
UPDATE
If you want that site will resize based on browser resize then use % instead of px
CSS:
html {height:100%; overflow:hidden}
body {height: 100%;}
I guess you need screen width and height for client(users) machine.
at onload of page get screen width & height and set those values to divs using jquery/javascript
var userscreen_width,userscreen_height;
userscreen_width = screen.width;
userscreen_height = screen.height;
check this for more info
Keep in mind that in your example iframe also has fixed size. You should also resize it to the parents width. In your example this would work:
$(window).on('load resize', function(){
$('#content, #content > iframe').width($(this).width());
});
Keep in mind that you must remove all margins, as well as absolute positioning like: top, left, position:absolute from you element styles.
I checked the code from the provided link in question.
Change width to 80% in #content style.
And in .wrapper change width to 100%.
You have used mainly 920px for width, so whenever you will resize window the control will not re-size. Use equivalent % instead of 920px;
You can do like this
var width = $(window).width();
$("#divId").width(width);