두 div (클래스 이름 ca1 및 ca2 포함)가 있으며 jquery를 사용하여 두 div의 중앙에 이미지 (veer.jpg)를 배치하고 싶습니다.이 작업에 성공했지만 한 번에 하나의 사진 만 배치 할 수 있습니다. 중앙에서, 예를 들어 ca1에 jquery 함수를 사용하면 제대로 작동하지만 동시에 ca2에 jquery 함수를 사용하면 작동하지 않습니다. 이제 ca1에 대한 함수를 삭제하고 이제 ca2에 jquery 함수를 사용하면 이것은 잘 작동합니다. 한 번에 두 div에 대해 jquery 함수를 사용할 수 없습니다. 누구든지 제발 도와 줄 수 있습니까?
내 html 페이지는 다음과 같습니다.
<!DOCTYPE html>
<html>
<head><link rel="stylesheet" href="css/hwcb.css">
</head>
<body>
<div class="ca1"style="height:600px; width:600px; top:100px; left:400px; position:absolute; background:pink;">
<img class="c1" src="veer.jpg" style="height:200px; position:absolute;" />
</div>
<div class="ca2"style="height:600px; width:400px; top:800px; left:400px;position:absolute; background:grey;">
<img class="c2" src="veer.jpg" style="height:200px; position:absolute;" />
</div>
<script src="js/jquery.js"></script>
<script src="js/main.js"></script>
</body>
</html>
내 main.js 페이지는 다음과 같습니다.
$(document).ready(function(){function move_div(){window_width=$('.ca1').width();window_height=$('.ca1').height();obj_width=$('.c1').width();obj_height=$('.c1').height();$('.c1').css('top',(window_height/2)-(obj_height/2)).css('left', (window_width/2)-(obj_width/2));}move_div();$(div).resize(function(){move_div();});});
$(document).ready(function(){function move_div(){window_width=$('.ca2').width();window_height=$('.ca2').height();obj_width=$('.c2').width();obj_height=$('.c2').height();$('.c2').css('top',(window_height/2)-(obj_height/2)).css('left', (window_width/2)-(obj_width/2));}move_div();$(div).resize(function(){move_div();});});
대신에
$(div).resize(function(){move_div();});})
시험
$('.ca1').resize(move_div)
이제 모든 div에 대한 핸들러를 추가하고 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다