차근차근/JAVA Script
섬네일 이미지 클릭시 큰 이미지로 보여주기
예쁜꽃이피었으면
2014. 9. 15. 15:33
http://www.dweb.co.kr/bbs/board.php?bo_table=javascript&wr_id=6&page=
html
<ul class = "thumbImg">
<li><img src="/img/Image01.jpg" onclick="doShow(this.src)"/></li>
<li><img src="/img/Image02.jpg" onclick="doShow(this.src)"/></li>
<li><img src="/img/Image03.jpg" onclick="doShow(this.src)"/></li>
<li><img src="/img/Image04.jpg" onclick="doShow(this.src)"/></li>
</ul>
<div class="bigImgBox">
<img src="/img/Image01/jsp" id="bigImg">
</div>
자바스크립트
<script>
funcion doShow(imgSrc){
document.getElementById("bigImg").src = imgSrc;
}
</script>
나의 경우
function doShow(imgSrc){
document.getElementById("bigimage").src = imgSrc;
}
<!--content-->
<div id="content">
<div id="item_images">
<div id = "imgcenter">
<div><img id="bigimage" src="${plant.bimg_file_name}" width="320px" height="225px"></div>
</div>
<div id="thum_image">
<div id = "imgcenter">
<c:forEach items="${plantimage}" var="plantimage">
<a href="#"><img src="${plantimage.file_name}" width="64px" height="91px" onclick="doShow(this.src)"></a>
</c:forEach>
</div>
</div>
http://rocabilly.tistory.com/?page=2
작은 이미지들 클릭하면 특정 공간에 큰 이미지 노출
1. 환경
- 쇼핑몰 사이트의 상품소개등에 사용
- 여러 썸네일 이미지를 클릭 => 큰 이미지 변경
- 큰 이미지 클릭 => 새창으로 이미지 보여줌

2. 소스
- jQuery
- <script language="javascript" type="text/javascript">
- <!--
- jQuery.noConflict();
-
- jQuery(document).ready(function () {
- var imgPath = '';
-
- jQuery('#big_pic').click(function () {
- imgPath = jQuery("#big_pic").attr("src");
- window.open(imgPath, "_blank");
- });
- jQuery('#small_pic1').click(function () {
- imgPath = jQuery("#small_pic1").attr("src");
- if ( imgPath != "http://domain/image/photo_noimg.gif")
- {
- jQuery('#big_pic').attr("src",imgPath);
- }
- });
- jQuery('#small_pic2').click(function () {
- imgPath = jQuery("#small_pic2").attr("src");
- if ( imgPath != "http://domain/image/photo_noimg.gif")
- {
- jQuery('#big_pic').attr("src",imgPath);
- }
- });
- jQuery('#small_pic3').click(function () {
- imgPath = jQuery("#small_pic3").attr("src");
- if ( imgPath != "http://domain/image/photo_noimg.gif")
- {
- jQuery('#big_pic').attr("src",imgPath);
- }
- });
- jQuery('#small_pic4').click(function () {
- imgPath = jQuery("#small_pic4").attr("src");
- if ( imgPath != "http://domain/image/photo_noimg.gif")
- {
- jQuery('#big_pic').attr("src",imgPath);
- }
- });
- });
-
-
-
- </script>
- html or aspx
- <table border="0" cellspacing="0" cellpadding="0">
-
- <tr>
- <td style="background:#f6f6f6;">
-
- <div style="background:#FFF; width:892px; height:190px; padding:20px 0 20px 20px;">
- <!--포토사진보기-->
- <div class="bbs_view02">
- <div style="border:0px solid blue; height:150px; padding:3 3 0 3;"><!--큰사진 -->
- <%
- if ( attach_file1 != "" )
- imgName="http://domain/image/" + attach_file1;
- else if ( attach_file2 != "" )
- imgName="http://domain/image/" + attach_file2;
- else if ( attach_file3 != "" )
- imgName="http://domain/image/" + attach_file3;
- else if ( attach_file4 != "" )
- imgName="http://domain/image/" + attach_file4;
- else
- imgName="http://domain/image/photo_noimg01.gif";
- %>
- <img src="<%=imgName%>" style="max-width:270px;max-height:145px;cursor:pointer;align:top;" width="270" height="145" id="big_pic">
- </div>
- <!--작은사진 -->
- <div style="border:0px solid #000;height:40px;padding:3 3 0 3;">
-
- <%
- if ( attach_file1 != "" ) imgName="http://domain/image/" + attach_file1;
- else imgName="http://domain/image/photo_noimg.gif";
- %>
- <img src="<%=imgName%>" style="max-width:65px;max-height:47px;cursor:pointer;" width="65" height="47" id="small_pic1" >
-
- <%
- if ( attach_file2 != "" ) imgName="http://domain/image/" + attach_file2;
- else imgName="http://domain/image/photo_noimg.gif";
- %>
- <img src="<%=imgName%>" style="max-width:65px;max-height:47px;cursor:pointer;" width="65" height="47" id="small_pic2" >
-
- <%
- if ( attach_file3 != "" ) imgName="http://domain/image/" + attach_file3;
- else imgName="http://domain/image/photo_noimg.gif";
- %>
- <img src="<%=imgName%>" style="max-width:65px;max-height:47px;cursor:pointer;" width="65" height="47" id="small_pic3" >
-
- <%
- if ( attach_file4 != "" ) imgName="http://domain/image/" + attach_file4;
- else imgName="http://domain/image/photo_noimg.gif";
- %>
- <img src="<%=imgName%>" style="max-width:65px;max-height:47px;cursor:pointer;" width="65" height="47" id="small_pic4" >
-
- </div>
- </div><!--bbs_view02---->
- </td>
- </tr>
- </table>