테스트 사이트 - 개발 중인 베타 버전입니다

이미지 alt 부분 캡션으로 활용하기

· 14년 전 · 701
$(document).ready(function()
{
$(".content img").each(function(i) 
{
var captiontext = $(this).attr('alt');
if(captiontext == '') {
$(this).wrap("<div class='imgpost'></div>");
$(this).parent().append("<div class='nonecaption'></div>");
} else {
$(this).wrap("<div class='imgpost'></div>");
$(this).parent().append("<div class='thecaption'>▲" + captiontext + "</div>");}
});
});

이미지 alt 부분을 캡선으로 사용합니다.

그냥했다가는 전체 이미지를 체크하기때문에 일정영역(content)을 class로 묶고 그안에서만 체크하도록 하였습니다.

imgpost / thecaption 부분은 style로 따로 만드시면 취향따라 만드실수 있겠네요.

alt 여부 체크하는 if문도 넣었습니다.

저는 아래와같이 구현하였습니다.


[이 게시물은 관리자님에 의해 2011-10-31 16:55:28 jQuery에서 이동 됨]

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

게시글 목록

번호 제목
12333
12332
12331
12329
12328
12327
12326
12325
12324
12323
12322
12321
12320
12319
12318
12317
12316
12315
12314
12313
12312
12311
12310
12309
12308