사용자의 화면 중앙에 심장 이미지를 배치하고 싶습니다. 그리고 그것을 클릭 할 때마다 크기를 조정하고 키워야합니다.이미지 가운데 맞추기 및 가운데에서 이미지 크기 조정. 여백 없음
주된 문제는 여백없이 그걸하고 싶다는 것입니다. 제발 도와 주실 수 있습니까?
편집 1 - 이 지금까지 내 코드이지만, 정말 지저분하고
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<style>
#container {
width: 100px;
height: 100px;
position:absolute;
left: 50%;
top: 50%;
margin-left: -50px;
margin-top: -50px;
}
#Msg1 {
width: 200px;
height: 100px;
display:none;
position:absolute;
margin-right:55%;
margin-top: 45%;
}
body {
overflow:hidden;
background-color:#ffd6d6;
}
</style>
<script>
var size=100;
var i=0;
var heartImage = document.getElementById('container');
$(document).ready(function(){
$(function() {
$("#Msg1").fadeIn("slow");
});
$(function() {
$("#container")
.mouseover(function() {
if(i==0){
var src = $(this).attr("src").match(/[^\.]+/) + "over.png";
$(this).animation
$(this).attr("src", src);}
})
.mouseout(function() {
var src = $(this).attr("src").replace("over.png", ".png");
$(this).attr("src", src);
});
});
$("#container").click(function(){
i++;
if(i==1)
{
$("#Msg1").fadeOut("fast");
}
if(i==6)
{
$("body").css("background-color","#9d1b1b");
$("#container").hide();
}
size=size*2;
$("#container").animate({
height:size,
width:size,
margin:-size/2,
});
});
});
</script>
</head>
<body dir="rtl">
<img id="container" src="heart.png" alt="null"/>
<div id="Msg1">
</div>
</body>
Here가 JSFiddle의 코드이다 마진을 사용합니다.
지금까지 코드가 있습니까? 그렇다면 질문에 추가하십시오. –
jsfiddle 또는이 작업을 수행하려는 시도가 있습니까? 그냥 CSS/js로 중심에 배치하고 너비와 높이를 늘릴 수는 없습니까? – Sanchit
콘텐츠의 높이를 이전에 알고 있습니까? –