블로그 이미지

카테고리

데꾸벅 (194)
Publisher (39)
Scripter (97)
Programmer (1)
Designer (30)
Integrator (18)
Pattern Searcher (4)
News (2)
강좌 및 번역 (3)

최근에 올라온 글

최근에 달린 댓글

'setPNG24'에 해당되는 글 1건

  1. 2008.08.13 PNG(setPNG)를 이용시 이미지 토글 이벤트 먹는 경우 2

보통 IE5,5와 IE6에서의 투명 PNG이미지 처리시 CSS와 스크립트로 다음과 같이 처리하는데
.png24 {
    tmp:expression(setPNG24(this));
}


/* png24 이미지 파일을 웹에서 투명하게 변경하는 스크립트 */
function setPNG24(obj) {
    obj.width=obj.height=1;
    obj.className=obj.className.replace(/\bPNG24\b/i,'');
    obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
    obj.src='';
    return '';
}

보통 위와 같이 처리하면 onmouseover='this.src=this.src.replace(".gif","_over.gif")'와 같이 처리하는데..

이미지 토글처리를 하다가 setPNG로 filter:progid:DXImageTransform 필터가 적용되면 mouseover 이벤트로 이미지 변경이 되지 않았다.
IE7, IE6에서 필터가 적용되면  onclick, onmouseover이던지 이벤트는 모두 먹어버리고 심지어 <a>태그도 먹질 않는다. 다른 브라우저에서는 아예 filter 속성이 먹질 않아서 정상적으로 작동한다.

실제 이미지의 소스를 filter속에서 정의하기 때문에 그렇다.

이럴경우 다음과 같이 처리한다. [레퍼런스 : http://homepage.ntlworld.com/bobosola/png_mouseover.htm]
<!--[if lt IE 7]>
<script type="text/javascript">
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 and 6.
{
   if ((version >= 5.5) && (document.body.filters))
   {
       for(var i=0; i<document.images.length; i++)
       {
          var img = document.images[i]
          var imgName = img.src.toUpperCase()
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
          {
             var imgID = (img.id) ? "id='" + img.id + "' " : ""
             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
             var imgStyle = "display:inline-block;" + img.style.cssText
             var imgAttribs = img.attributes;
             for (var j=0; j<imgAttribs.length; j++)
             {
                var imgAttrib = imgAttribs[j];
                if (imgAttrib.nodeName == "align")
                {
                   if (imgAttrib.nodeValue == "left") imgStyle = "float:left;" + imgStyle
                   if (imgAttrib.nodeValue == "right") imgStyle = "float:right;" + imgStyle
                   break
                }
             }
             var strNewHTML = "<span " + imgID + imgClass + imgTitle
             strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             strNewHTML += "(src='" + img.src + "', sizingMethod='scale');\""
             strNewHTML += " onmouseover=\"PNGswap('" + img.id + "');\" onmouseout=\"PNGswap('" + img.id +"');\""
             strNewHTML += "></span>"
             img.outerHTML = strNewHTML
             i = i-1
          }
       }
   }
}
window.attachEvent("onload", correctPNG);
function PNGswap(myID)
{
   var strOver  = "_on"
   var strOff = "_off"
   var oSpan = document.getElementById(myID)
   var currentAlphaImg = oSpan.filters(0).src
   if (currentAlphaImg.indexOf(strOver) != -1)
      oSpan.filters(0).src = currentAlphaImg.replace(strOver,strOff)
   else
      oSpan.filters(0).src = currentAlphaImg.replace(strOff,strOver)
}

</script>
<![endif]-->

<script language="JavaScript" type="text/javascript">
<!--
function imgSwap(oImg)
{
   var strOver  = "_on"    // image to be used with mouse over
   var strOff = "_off"     // normal image
   var strImg = oImg.src
   if (strImg.indexOf(strOver) != -1)
      oImg.src = strImg.replace(strOver,strOff)
   else
      oImg.src = strImg.replace(strOff,strOver)
}
//-->
</script>

</head>
<body>

<div class="plainbackground">
<img id="img100" src="logo_off.png" width="100" height="100" alt="a PNG logo"
onmouseover="imgSwap(this)" onmouseout="imgSwap(this)"/>
</div>

<div class="plainbackground">
<img id="img200" src="logo2_off.png" width="100" height="100" alt="another PNG logo"
onmouseover="imgSwap(this)" onmouseout="imgSwap(this)"/>

</div>


결국 필터의 src 소스를 변경시켜야 하다는 얘기닷.. ㅡ.,ㅡ;
다들 건승하길... 저 같으면 그냥 gif 깨끗하게 쓰겠어요.. ㅠ.,ㅠ;



Post by 넥스트리소프트 데꾸벅(techbug)
, |