The width and and height of my google map is very small. I need 400px width and height. But I am getting 256px. The map_canvas div have 400px width and height.How can I change the width and height of Google map. Please help me.
<form id="overlay_form" style="display:none" style="width:500px;height:500px;">
<img src="<?php echo base_url();?>img/x.png" id="close"/>
<div id="map_canvas" style="width:100%; height:100%;"></div>
</form>
<script type="text/javascript">
$(document).ready(function(){
$(".popup").click(function(){
$("#overlay_form").fadeIn(1000);
positionPopup();
});
$("#close").click(function(){
$("#overlay_form").fadeOut(1000);
});
});
function positionPopup(){
if(!$("#overlay_form").is(':visible')){
return;
}
$("#overlay_form").css({
left: ($(window).width() - $('#overlay_form').width()) / 2,
top: ($(window).width() - $('#overlay_form').width()) / 7,
position:'absolute'
});
}
$(window).bind('resize',positionPopup);
</script>
AFAIK google's map_canvas div doesn't supports height and width in %, you'l need to explicitely specify in pixels only. So change your code as follows:
<form id="overlay_form" style="width:500px;height:500px;">
<img src="<?php echo base_url();?>img/x.png" id="close"/>
<div id="map_canvas" style="width:500px; height:500px;"></div>
</form>
I've also removed style="display:none" from <form ..>. So that it will show map on screen.
See this, to understand issue of height/width in % for google map.
Here is documentation
Related
Imagine that you have an image
<img id="imgid" height="15" width="149" src="image.png" alt="[]" />
and you want to change its dimensions to height="30" and width to proportional size. The first part is easy:
document.getElementById('imgid').height=30px;
However, wat about the second part? Is it possible to do something similar to
document.getElementById('imgid').width='auto';
Thanks for the answers.
Just change the css properties instead (included both jQuery and plain JS solutions):
$(document).ready(function() {
$("#resize").click(function() {
$("#test").css("width", "100px");
$("#test").css("height", "auto");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<script>
function resizeImg() {
var el = document.getElementById("test")
el.style.width = "200px"
el.style.height = "auto"
}
</script>
<img id="test" src="https://media.licdn.com/media/p/8/000/1e9/0e5/26e178f.png" width="323" height="110">
<br>
Resize jQuery
Resize plain JS
</body>
As per documentation
width
The intrinsic width of the image in pixels. In HTML 4, either a
percentage or pixels were acceptable values. In HTML5, however, only
pixels are acceptable.
Use style properties instead
document.getElementById('imgid').style.height="30px";
document.getElementById('imgid').style.width='auto';
It should be style.height and style.width. Check below snippet for reference.
document.getElementById('imgid').style.height = '90px';
document.getElementById('imgid').style.width = 'auto';
<img id="imgid" height="180" width="240" src="https://www.joomlack.fr/images/demos/demo2.jpg" alt="" />
This will solve your problem if I understand correct your problem:
img {
max-height: 30px;
width: auto;
}
Right now i want to make a simple jQuery function so when this function is called the iframe height is changing.
Here is my code:
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
function ChangeHeightF1()
{
$("#inneriframe").css({"height":"350px;"});
alert('The height was changed!');
}
</script>
<div id="outerdiv">
<iframe src="http://beta.sportsdirect.bg/checkout/onepage/" id="inneriframe" scrolling="no" target="_parent"></iframe>
</div>
Here is the code of the button which is in the content of the iframe:
<button type="button" onclick="parent.ChangeHeightF1();">Click me to change Height!</button>
So my questions is how it's possible to change the iframe height on button click inside the content which is holding the iframe.
Also what CSS i have to place on "outerdiv" div element so when the iframe height is changing it will change the height of the div holding the iframe as well ?
Thanks in advance!
You can use window.parent.document as a context in jQuery selector, and then manipulate CSS values.
$(":button").click(function(){
$('#inneriframe, #outerdiv', window.parent.document).css({"height":"350px"});
})
This should work. If you want to re size back to previous height, let me know.
http://jsfiddle.net/ko3pyy8c
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$('#more').click(function(){
$('#inneriframe').animate({height:'500px'}, 500);
$('#more').text('Go Back');
});
});
</script>
<style type = "text/css"/>
#inneriframe {
height: 350px;
overflow: hidden;
}
</style>
<div id="outerdiv">
<iframe src="http://beta.sportsdirect.bg/checkout/onepage/" id="inneriframe" scrolling="no" target="_parent"></iframe>
</div>
<br/>
Change Height
it can help you
<a href='#'>click me</a>
<div id="outerdiv">
<iframe src="http://beta.sportsdirect.bg/checkout/onepage/" id="inneriframe" scrolling="no" target="_parent"></iframe>
by using jquery
$('a').click(function(){
$('iframe').css('height','600px');
});
how is it possible to center a div's scrollbar?
This is what I have:
<div id="mydiv" style="width:1000px;overflow:auto;">
<img src="..." style="width:100%;height:250px;" />
</div>
$(window).on('resize', function () {
$('#mydiv').scrollLeft(
$( "#mydiv" ).width() - $( "#mydiv" ).width()/2
);
});
But this doesn't work. It is not exactly centering. Too bad I can't set percent 50%. The scrollLeft(() function requires an integer.
Thanks!
here is your solution i have checked it with every possible width which was less than the image width. Even measured both left and right side space of scroll bar with plastic ruler ..LOL. :) to check if both sides are equal
http://jsfiddle.net/HSJft/5/
var outer=document.getElementById('mydiv').offsetWidth
var inner=document.getElementById('im').offsetWidth;
console.log(inner);
$('#mydiv').scrollLeft((inner-outer)/2)
<div id="mydiv" style="overflow:auto; overflow-y:hidden;width:300px">
<img id="im" src="http://eofdreams.com/data_images/dreams/image/image-15.jpg" />
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Easy solution:
https://jsfiddle.net/HSJft/21/
Vertical Scroll:
$(scrollWrapper).scrollTop(($(content).height() - $(scrollWrapper).height())/2);
Horizontal Scroll:
$(scrollWrapper).scrollLeft(($(content).width() - $(scrollWrapper).width())/2);
I have one background image(City image) with scroll, on that image I am placing some small images(Just like bomb images on the city image). I have canvas width and height depending on these variables I am placing the bomb image on the city image. When I place the bomb image at can.width/2 and can.height/2 in 430*300 devices, image will be on the center but when I try testing on bigger screen mobile, bomb image position is changing. I need to place bomb image in the same location for all devices. When I zoom in also position is changing. Anybody please help me to solve this scenario.
Here is my code
function smallBombImg(){
document.getElementById('carImg1').style.top = can.width/2 +"px";
document.getElementById('carImg1').style.left = can.height/2 +"px";
//document.getElementById('carImg1').style.background-attachment = "fixed";
document.getElementById('carImg1').style.display = "block";
document.getElementById('carImg1').src = 'img/bomb1.png';
}
HTML code is here
<body>
<div id="container">
<canvas id="can"></canvas>
</div>
<div id="btn">
<input type="image" id="zoomIn" src="img/up.png" onclick="zoomIn()" />
<input type="image" id="zoomOut" src="img/down.png"
onclick="zoomOut()" />
</div>
<div id="score">
<p id="scoreCount">
<b></b>
</p>
</div>
<div>
<img alt="simple1" id="carImg1" style="position: absolute; display: none;" />
</div>
</body>
I have to be brief, I am very sorry but I am running late.
Using jQuery:
var windowEventTimeoutEnded;
$(window).resize(function() {
clearTimeout(windowEventTimeoutEnded);
$(window).height(); // gets the height of the window
$(window).width(); // gets the width of the window
// This ensures the below does not trigger until the resize event is finished
windowEventTimeoutEnded = setTimeout(function() {
// Perform your resizing math and logic here, such
canvas.css({
width: 1234,
height: 235,
position: 'absolute' // etc, etc, etc
})
}, 500 );
});
Sorry for the brevity, hope this helps. I will return later and check if this helped and add to it if necessary, good luck!
$(window).resize is not working, what am I missing?
So I have this page with a single vertical menu of 350px width, centered horizontally. The links open iframe's that show different content. The iframe that shows an external site gets his width through: $("#iframeweb").width($(document).width() - $('#menu').width()) so that it fills up the screen, pushing the menu to the side.
That part works, but it also needs to change the width on resize of the window, but it does nothing...
the code:
<div id="wrapper">
<div id="outer">
<div id="inner">
<iframe name="iframeweb" id="iframeweb"></iframe>
<div id="menu">
</div>
<iframe name="iframeA4" id="iframeA4"></iframe>
</div>
</div>
</div>
<script type="text/javascript">
$(window).resize(function() {
$("#iframeweb").width($(document).width() - $('#menu').width());
};
</script>
<script type="text/javascript">
$("#linkA4").click(function(){
$("#iframeA4")
.hide('fast')
.animate({"width": "0px"}, 'fast')
.animate({"width": "210mm"}, 'fast')
.show('fast');
$("#iframeweb").hide('fast');
});
$("#linkweb").click(function(){
$("#iframeA4")
.animate({"width": "0px"}, 'fast')
.hide('fast');
$("#iframeweb")
.hide('fast')
.width($(document).width() - $('#menu').width())
.show('fast');
});
</script>
You have a simple syntax error, closing the parenthesis
$(window).resize(function() {
$("#iframeweb").width($(document).width() - $('#menu').width());
}); // <--