function autoSizePopup()
{
var winResizeW=0;
var winResizeH=0;
$(document).ready(function() {
//크롬, 사파리일때
if (navigator.userAgent.indexOf('Chrome')>-1 || navigator.userAgent.indexOf('Safari')>-1)
{
if(winResizeW==0 && winResizeH==0)
{
resizeWin();
}
}
//크롬, 사파리말고 모두
else
{
resizeWin();
}
});
function resizeWin()
{
var conW = $("#test").innerWidth(); //컨텐트 사이즈
var conH = $("#test").innerHeight();
var winOuterW = window.outerWidth; //브라우저 전체 사이즈
var winOuterH = window.outerHeight;
var winInnerW = window.innerWidth; //스크롤 포함한 body영역
var winInnerH = window.innerHeight;
var winOffSetW = window.document.body.offsetWidth; //스크롤 제외한 body영역
var winOffSetH = window.document.body.offsetHeight;
var borderW = winOuterW - winInnerW;
var borderH = winOuterH - winInnerH;
//var scrollW = winInnerW - winOffSetW;
//var scrollH = winInnerH - winOffSetH;
winResizeW = conW + borderW;
winResizeH = conH + borderH;
window.resizeTo(winResizeW,winResizeH);
}
}
$(document).ready(function(){
if(document.getElementById('main_img') != null){
$img_h = Number($("#main_img").css("height").replace("px",""));
$img_w = Number($("#main_img").css("width").replace("px",""));
if($img_h > $img_w){
$("#main_img").css("height","100%");
}else if($img_w > $img_h){
$("#main_img").css("width","100%");
$("#main_img").css("height","");
$("#main_img").css("top","50%");
$("#main_img").css("transform","translate(0,-50%);");
}else if($img_w == $img_h){
$("#main_img").css("width","100%");
$("#main_img").css("height","100%");
}
autoSizePopup();
}else{
autoSizePopup();
}
});
<div id="test" style="width: 400px;">
<br>
<div id="img_div" style="position:relative; text-align: center;">
<img id="main_img" src="${select_time_sale_item.time_special_leaflet_img_url}">
</div>
<br>
<hr>
<div style="padding:1% 3% 2% 3%;"> 내용 : ${select_time_sale_item.time_special_cont}</div>
</div>
참고 : http://blog.naver.com/sonix/150178152690
팝업 안에 내용크기에 맞게 resize 시켜준다.
'DEV > JavaScript' 카테고리의 다른 글
자바스크립트 큰 수 팩토리얼 (0) | 2021.08.07 |
---|---|
Custom 드롭다운 (0) | 2018.07.09 |
Safari new Date 형 변환시 NaN (0) | 2017.12.13 |
별 색칠하기 (0) | 2017.11.22 |