자바스크립트 고수님께 (+ - 버튼이미지 스왑 관련)
작업하다 곤란하면 제일 먼저 찾는 곳이 여기 뿐이네요...
JS / JQuery 관련 질문인데 도움을 부탁드립니다. ㅠㅠ
Toggle 관련 Jquery를 사용해서 페이지 제작중입니다.
http://jandspace.com/kaplan/toggle_test.html
위 링크에 보시면 + 버튼이 3개 있고 그 중 제일 위에 링크를 누르면
DIV가 슬라이딩되면서 내려오고 + 버튼은 - 버튼으로 바뀝니다.
JS / JQuery 관련 질문인데 도움을 부탁드립니다. ㅠㅠ
Toggle 관련 Jquery를 사용해서 페이지 제작중입니다.
http://jandspace.com/kaplan/toggle_test.html
위 링크에 보시면 + 버튼이 3개 있고 그 중 제일 위에 링크를 누르면
DIV가 슬라이딩되면서 내려오고 + 버튼은 - 버튼으로 바뀝니다.
문제는 똑같은 스크립트를 아래 2개의 버튼에 적용하면 작동을 하지 않습니다.
링크 갯수는 딱 3개만 둘 것은 아니고 여러 개가 추가될 수 있어서요
onclick 이벤트를 입력한 곳에 해당 라인의 + - 버튼에만 이벤트가 발생했으면 하는데요...
(아마도 변수가 필요한 것이 아닌지... 아니면 심플하게 만들 수 있을지...)
JS / JQuery 고수님들 한번 보시구서 도움을 주셨으면 합니다. (초보라서... 잘 알려주시면...^^;;)
미리 감사드립니닷!!
링크 갯수는 딱 3개만 둘 것은 아니고 여러 개가 추가될 수 있어서요
onclick 이벤트를 입력한 곳에 해당 라인의 + - 버튼에만 이벤트가 발생했으면 하는데요...
(아마도 변수가 필요한 것이 아닌지... 아니면 심플하게 만들 수 있을지...)
JS / JQuery 고수님들 한번 보시구서 도움을 주셨으면 합니다. (초보라서... 잘 알려주시면...^^;;)
미리 감사드립니닷!!
댓글 2개
13년 전
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link type="text/css" rel="stylesheet" href="kaplan.css" media="screen" />
<style type="text/css">
.exp_box {
background-color: #FFFFFF;
padding: 10px;
margin: 4px 10px 16px 0;
border: 1px solid #c4c4c4;
text-align: justify;
line-height: 18px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
-moz-box-shadow: inset 0 0 30px #DDDDDD;
-webkit-box-shadow: inset 0 0 30px #DDDDDD;
box-shadow: inset 0 0 30px #DDDDDD;
overflow: hidden;
display: none;
font-family: Tahoma, Geneva, sans-serif;
}
.exp_box p {
margin: 0;
padding: 0;
}
.close_box {
text-align: right;
display: block;
padding: 0 0 0 0;
}
.exp_box h3 {
margin: 0 0 -16px 0;
padding: 0;
color: #415bf5;
font-size: 17px;
}
#box_button {
vertical-align: -3px;
margin: 0 0 0 6px;
}
.show_hide {
cursor: pointer;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function ($) {
$(document).ready(function(){
$('.show_hide').showHide({
speed: 400, // speed you want the toggle to happen
easing: '', // the animation effect you want. Remove this line if you dont want an effect and if you haven't included jQuery UI
changeText: 0, // if you dont want the button text to change, set this to 0
showText: 'View',// the button text to show when a div is closed
hideText: 'Close' // the button text to show when a div is open
});
});
$.fn.showHide = function (options) {
//default vars for the plugin
var defaults = {
speed: 1000,
easing: '',
changeText: 0,
showText: 'Show',
hideText: 'Hide'
};
var options = $.extend(defaults, options);
var flag=0;
$(this).click(function () {
$('.toggleDiv').slideUp(options.speed, options.easing);
// this var stores which button you've clicked
var toggleClick = $(this);
// this reads the rel attribute of the button to determine which div id to toggle
var toggleDiv = $(this).attr('rel');
// here we toggle show/hide the correct div at the right speed and using which easing effect
$(toggleDiv).slideToggle(options.speed, options.easing, function() {
// this only fires once the animation is completed
if(options.changeText==1){
$(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
}
});
var img = $(this).find('img');
var src = img.attr('src');
//image is open
if(src == 'box_open.gif') {
img.attr('src','box_close.gif');
}
//image is close
if(src == 'box_close.gif') {
img.attr('src','box_open.gif');
}
return false;
});
};
})(jQuery);
</script>
</head>
<body>
<div style="width: 600px; font-size: 12px">
<h2><strong>Title</strong></h2>
<ul>
<li>
<a class="show_hide" rel="#slidingDiv1">Intensive English Courses<img name="img1" src="box_open.gif" alt="Box Open" id="box_button" /></a>
<div id="slidingDiv1" class="exp_box">
<p>
<h3>Intensive English Courses</h3><br />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus imperdiet nibh a risus blandit ut fringilla ante adipiscing. Donec non ligula elit. Nulla suscipit dapibus vulputate. Cras purus dolor, scelerisque sed congue sed, aliquet pellentesque nisi. Suspendisse sed odio at mi iaculis elementum vitae a tellus. Nulla ac adipiscing enim. Pellentesque vulputate purus et nisl rhoncus volutpat. Proin dapibus, tortor nec dignissim lobortis, tortor nulla facilisis sapien, vitae rhoncus lorem lorem nec leo. Ut a tellus euismod neque feugiat ultricies fringilla id nisi. Integer eget justo ipsum. Pellentesque metus ipsum, egestas at molestie consequat, semper eget mi. Integer non ante in sem iaculis pretium. Suspendisse nec massa eget leo fringilla iaculis in a nulla. Duis at lobortis odio. Quisque in nunc velit. Sed pulvinar sem non felis dapibus dictum.
</p>
</div>
</li>
<li>Intensive English Academic Year and Semester</a></li>
<li>
<a class="show_hide" rel="#slidingDiv2">OPUS Paid work and study<img src="box_open.gif" alt="Box Open" id="box_button" /></a>
<div id="slidingDiv2" class="exp_box">
<p>
<h3>OPUS Paid work and study</h3><br />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus imperdiet nibh a risus blandit ut fringilla ante adipiscing. Donec non ligula elit. Nulla suscipit dapibus vulputate. Cras purus dolor, scelerisque sed congue sed, aliquet pellentesque nisi. Suspendisse sed odio at mi iaculis elementum vitae a tellus. Nulla ac adipiscing enim. Pellentesque vulputate purus et nisl rhoncus volutpat. Proin dapibus, tortor nec dignissim lobortis, tortor nulla facilisis sapien, vitae rhoncus lorem lorem nec leo. Ut a tellus euismod neque feugiat ultricies fringilla id nisi. Integer eget justo ipsum. Pellentesque metus ipsum, egestas at molestie consequat, semper eget mi. Integer non ante in sem iaculis pretium. Suspendisse nec massa eget leo fringilla iaculis in a nulla. Duis at lobortis odio. Quisque in nunc velit. Sed pulvinar sem non felis dapibus dictum.
</p>
</div>
</li>
<li>
<a class="show_hide" rel="#slidingDiv3">Internship placement service<img src="box_open.gif" alt="Box Open" id="box_button" /></a>
<div id="slidingDiv3" class="exp_box">
<p>
<h3>Internship placement service</h3><br />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus imperdiet nibh a risus blandit ut fringilla ante adipiscing. Donec non ligula elit. Nulla suscipit dapibus vulputate. Cras purus dolor, scelerisque sed congue sed, aliquet pellentesque nisi. Suspendisse sed odio at mi iaculis elementum vitae a tellus. Nulla ac adipiscing enim. Pellentesque vulputate purus et nisl rhoncus volutpat. Proin dapibus, tortor nec dignissim lobortis, tortor nulla facilisis sapien, vitae rhoncus lorem lorem nec leo. Ut a tellus euismod neque feugiat ultricies fringilla id nisi. Integer eget justo ipsum. Pellentesque metus ipsum, egestas at molestie consequat, semper eget mi. Integer non ante in sem iaculis pretium. Suspendisse nec massa eget leo fringilla iaculis in a nulla. Duis at lobortis odio. Quisque in nunc velit. Sed pulvinar sem non felis dapibus dictum.
</p>
</div>
</li>
</ul>
</div>
</body>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link type="text/css" rel="stylesheet" href="kaplan.css" media="screen" />
<style type="text/css">
.exp_box {
background-color: #FFFFFF;
padding: 10px;
margin: 4px 10px 16px 0;
border: 1px solid #c4c4c4;
text-align: justify;
line-height: 18px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
-moz-box-shadow: inset 0 0 30px #DDDDDD;
-webkit-box-shadow: inset 0 0 30px #DDDDDD;
box-shadow: inset 0 0 30px #DDDDDD;
overflow: hidden;
display: none;
font-family: Tahoma, Geneva, sans-serif;
}
.exp_box p {
margin: 0;
padding: 0;
}
.close_box {
text-align: right;
display: block;
padding: 0 0 0 0;
}
.exp_box h3 {
margin: 0 0 -16px 0;
padding: 0;
color: #415bf5;
font-size: 17px;
}
#box_button {
vertical-align: -3px;
margin: 0 0 0 6px;
}
.show_hide {
cursor: pointer;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function ($) {
$(document).ready(function(){
$('.show_hide').showHide({
speed: 400, // speed you want the toggle to happen
easing: '', // the animation effect you want. Remove this line if you dont want an effect and if you haven't included jQuery UI
changeText: 0, // if you dont want the button text to change, set this to 0
showText: 'View',// the button text to show when a div is closed
hideText: 'Close' // the button text to show when a div is open
});
});
$.fn.showHide = function (options) {
//default vars for the plugin
var defaults = {
speed: 1000,
easing: '',
changeText: 0,
showText: 'Show',
hideText: 'Hide'
};
var options = $.extend(defaults, options);
var flag=0;
$(this).click(function () {
$('.toggleDiv').slideUp(options.speed, options.easing);
// this var stores which button you've clicked
var toggleClick = $(this);
// this reads the rel attribute of the button to determine which div id to toggle
var toggleDiv = $(this).attr('rel');
// here we toggle show/hide the correct div at the right speed and using which easing effect
$(toggleDiv).slideToggle(options.speed, options.easing, function() {
// this only fires once the animation is completed
if(options.changeText==1){
$(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
}
});
var img = $(this).find('img');
var src = img.attr('src');
//image is open
if(src == 'box_open.gif') {
img.attr('src','box_close.gif');
}
//image is close
if(src == 'box_close.gif') {
img.attr('src','box_open.gif');
}
return false;
});
};
})(jQuery);
</script>
</head>
<body>
<div style="width: 600px; font-size: 12px">
<h2><strong>Title</strong></h2>
<ul>
<li>
<a class="show_hide" rel="#slidingDiv1">Intensive English Courses<img name="img1" src="box_open.gif" alt="Box Open" id="box_button" /></a>
<div id="slidingDiv1" class="exp_box">
<p>
<h3>Intensive English Courses</h3><br />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus imperdiet nibh a risus blandit ut fringilla ante adipiscing. Donec non ligula elit. Nulla suscipit dapibus vulputate. Cras purus dolor, scelerisque sed congue sed, aliquet pellentesque nisi. Suspendisse sed odio at mi iaculis elementum vitae a tellus. Nulla ac adipiscing enim. Pellentesque vulputate purus et nisl rhoncus volutpat. Proin dapibus, tortor nec dignissim lobortis, tortor nulla facilisis sapien, vitae rhoncus lorem lorem nec leo. Ut a tellus euismod neque feugiat ultricies fringilla id nisi. Integer eget justo ipsum. Pellentesque metus ipsum, egestas at molestie consequat, semper eget mi. Integer non ante in sem iaculis pretium. Suspendisse nec massa eget leo fringilla iaculis in a nulla. Duis at lobortis odio. Quisque in nunc velit. Sed pulvinar sem non felis dapibus dictum.
</p>
</div>
</li>
<li>Intensive English Academic Year and Semester</a></li>
<li>
<a class="show_hide" rel="#slidingDiv2">OPUS Paid work and study<img src="box_open.gif" alt="Box Open" id="box_button" /></a>
<div id="slidingDiv2" class="exp_box">
<p>
<h3>OPUS Paid work and study</h3><br />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus imperdiet nibh a risus blandit ut fringilla ante adipiscing. Donec non ligula elit. Nulla suscipit dapibus vulputate. Cras purus dolor, scelerisque sed congue sed, aliquet pellentesque nisi. Suspendisse sed odio at mi iaculis elementum vitae a tellus. Nulla ac adipiscing enim. Pellentesque vulputate purus et nisl rhoncus volutpat. Proin dapibus, tortor nec dignissim lobortis, tortor nulla facilisis sapien, vitae rhoncus lorem lorem nec leo. Ut a tellus euismod neque feugiat ultricies fringilla id nisi. Integer eget justo ipsum. Pellentesque metus ipsum, egestas at molestie consequat, semper eget mi. Integer non ante in sem iaculis pretium. Suspendisse nec massa eget leo fringilla iaculis in a nulla. Duis at lobortis odio. Quisque in nunc velit. Sed pulvinar sem non felis dapibus dictum.
</p>
</div>
</li>
<li>
<a class="show_hide" rel="#slidingDiv3">Internship placement service<img src="box_open.gif" alt="Box Open" id="box_button" /></a>
<div id="slidingDiv3" class="exp_box">
<p>
<h3>Internship placement service</h3><br />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus imperdiet nibh a risus blandit ut fringilla ante adipiscing. Donec non ligula elit. Nulla suscipit dapibus vulputate. Cras purus dolor, scelerisque sed congue sed, aliquet pellentesque nisi. Suspendisse sed odio at mi iaculis elementum vitae a tellus. Nulla ac adipiscing enim. Pellentesque vulputate purus et nisl rhoncus volutpat. Proin dapibus, tortor nec dignissim lobortis, tortor nulla facilisis sapien, vitae rhoncus lorem lorem nec leo. Ut a tellus euismod neque feugiat ultricies fringilla id nisi. Integer eget justo ipsum. Pellentesque metus ipsum, egestas at molestie consequat, semper eget mi. Integer non ante in sem iaculis pretium. Suspendisse nec massa eget leo fringilla iaculis in a nulla. Duis at lobortis odio. Quisque in nunc velit. Sed pulvinar sem non felis dapibus dictum.
</p>
</div>
</li>
</ul>
</div>
</body>
</body>
</html>
13년 전
저를 살리셨습니다.
무한 감사를 드립니다. (_ _) 정말 잘되네요...(^_^)=b
무한 감사를 드립니다. (_ _) 정말 잘되네요...(^_^)=b
게시글 목록
| 번호 | 제목 |
|---|---|
| 12307 |
JavaScript
테이블 각 row 마우스오버시 색깔바꾸기 입니다.
|
| 12306 |
JavaScript
png 24비트 투명처리하기 입니다.
|
| 12305 |
JavaScript
full-down메뉴 자바스크립트 입니다.
|
| 12304 |
JavaScript
iframe사용시 높이 자동 조정하기 입니다.
|
| 12303 |
JavaScript
계산기
|
| 12302 |
JavaScript
숫자를 한글로 변환하기 입니다.
|
| 12301 |
JavaScript
아이프레임 자동으로 늘어나는 자바 스크립트 입니다.
|
| 12300 |
JavaScript
끊기지 않는 배너 롤링 입니다.
|
| 12299 |
기타
랜섬에 당한 화일 복구
|
| 12298 |
JavaScript
id값 변수명으로 치환 예제 자바스크립트 입니다.
|
| 12297 |
JavaScript
상태바의 링크 주소 감추기 입니다.
|
| 12296 |
JavaScript
가짜 카운터 달기 입니다.
|
| 12295 |
JavaScript
홈에 머문시간을 제목표시줄과 상태바에 실시간으로 알려주기 입니다.
|
| 12294 |
JavaScript
prompt 와 alert 응용 자바스크립트 예제 입니다.
|
| 12293 |
JavaScript
prompt 와 alert 간단한 자바스크립트 예제 입니다.
|
| 12292 |
jQuery
간단한 탭 제이쿼리
|
| 12291 |
jQuery
간단한 셀렉트 드롭다운 제이쿼리
|
| 12290 |
JavaScript
문서내 이미지갯수 출력하기 입니다.
|
| 12289 |
JavaScript
내용 복사해서 붙어넣기 하면 출처 따라오는 자바스크립트입니다.
|
| 12288 |
JavaScript
팝업창 지정한 시간대에 예약 열기 입니다.
|
| 12287 |
JavaScript
접속때마다 음악 다르게 나오기 입니다.
|
| 12286 |
JavaScript
자동 스크롤 메뉴 관련 입니다.
|
| 12285 |
JavaScript
이 브라우저로 몇페이지나 보았나 확인하기 입니다.
|
| 12284 |
JavaScript
사용자 브라우저의 펄러그인 목록 출력하기 입니다.
|
| 12283 |
JavaScript
상태표시줄 제어 + 간단한 복사 제어 하기 입니다.
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기