Question

I am using this script for PNG fixes for IE6.

I've noticed that when I clone an element, the cloned PNG's are unfixed even though they have the proper classes attached, and I'm unable to re-apply the fix. I'm using jquery to clone an element, and have to use clone(false,false) for extensive reasons...is there a way I can apply the fix to the new element after appending the clone? Calling DD_belatedPNG.fix(".pngfix") again does not seem to work.

Was it helpful?

Solution

This solution is for img elements

<!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" />
<style>
    body {
        background:#0000FF;
    }
</style>
<script type="text/javascript" language="javascript" src="jquery.min.js"></script>
<script type="text/javascript" language="javascript" src="DD_belatedPNG_0.0.8a.js"></script>
<script>
    $(document).ready(function () {
        function imageClickHandler () {
            var $newA = $("<a></a>")
            var $newImg = $(this).find('img').clone(false,false);
            $newImg.attr("style","");
            $newA.append($newImg);

            $newA.click(imageClickHandler);
            $(this).parent().append($newA);
            DD_belatedPNG.fix('img');
        }

        DD_belatedPNG.fix('img');
        $('a').click(imageClickHandler);

    });
</script>
</head>
<body>
<a><img src="image.png" /></a>
</body>
</html>

EDIT this solution is for bg elements

<!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" />
    <style>
        body {
            background:#0000FF;
        }

        a {
            display:inline-block;
            //display:inline;
            zoom:1;
            width:512px;
            height:512px;
            background:url(image.png) no-repeat center center;
            text-decoration:none;
            outline:none;
        }
    </style>
    <script type="text/javascript" language="javascript" src="jquery.min.js"></script>
    <script type="text/javascript" language="javascript" src="DD_belatedPNG_0.0.8a.js"></script>
    <script>
        $(document).ready(function () {
            function imageClickHandler () {
                var $newA = $(this).clone(false,false);
                $newA.removeAttr("style isImg vmlInitiated vmlBg");
                $newA.click(imageClickHandler);
                $(this).parent().append($newA);
                DD_belatedPNG.fix('a');
            }

            DD_belatedPNG.fix('a');
            $('a').click(imageClickHandler);

        });
    </script>
</head>
<body>
    <a></a>
</body>
</html>

OTHER TIPS

Rather than use a png fix, just use transparent PNGs that are supported by IE (paletted 8-bit with alpha). ImageAlpha will do this for you if you are using a Mac, otherwise you can use pngquant (which ImageAlpha is based on) to do this for you.

Javascript/IE Filter type stuff is not needed to solve this problem, and should be avoided.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top