如何更改 IE 中图像的不透明度? - jQuery、CSS

发布于 2024-10-07 06:39:47 字数 1866 浏览 0 评论 0原文

以下内容适用于 FF、Chrome 和 Safari:

$('#delete_img').click(function(e) {
            var offset = $(this).offset();
            $(this).parent().parent().fadeTo("slow", 0.30);
            $(this).parents("li").children("img").css({ 'border' : '3px solid #f6f6f7' });
            e.stopPropagation();
});

但不适用于 IE8(我什至没有在 7 及更早版本中进行测试)。

如何在 IE8 中实现此功能?

编辑:根据大众的要求,这里是 HTML:

<div id="slider-code">
        <a class="buttons prev" href="#"></a>
        <div class="viewport">
            <ul class="overview">           
                <li><img src="images/red-stripe.jpg" /></li>
                <li><img src="images/red-stripe-bw.jpg" /></li>
                <li><img src="images/red-stripe-red.jpg" /></li>            
                <li><img src="images/red-stripe-dark.jpg" /></li>
                <li><img src="images/red-stripe.jpg" /></li>
                <li><img src="images/red-stripe-red.jpg" /></li>
                <li><img src="images/red-stripe-dark.jpg" /></li>           
            </ul>       
        </div>
        <a class="buttons next" href="#"></a>
    </div>

    <div style="clear:both"></div>

    <div id="edit-image-nav">
        <div id="add_comment"><img src="images/comment-icon.png" /></div>
        <div id="like"><img src="images/paint-icon.png" /></div>
        <div id="delete_img"><img src="images/delete-icon.png" /></div>
    </div>  

请注意,当您单击“edit-image-nav”div 中的图标之一(覆盖在图像上)时,会发生什么情况?上面的 UL onHover),它具有不同的功能。对于其他图标,它有效。但对于 #delete_img 来说,却没有。

The following works in FF, Chrome and Safari:

$('#delete_img').click(function(e) {
            var offset = $(this).offset();
            $(this).parent().parent().fadeTo("slow", 0.30);
            $(this).parents("li").children("img").css({ 'border' : '3px solid #f6f6f7' });
            e.stopPropagation();
});

But doesn't in IE8 (I am not even testing in 7 and earlier).

How do I achieve this functionality in IE8 ?

Edit: By popular request here is the HTML:

<div id="slider-code">
        <a class="buttons prev" href="#"></a>
        <div class="viewport">
            <ul class="overview">           
                <li><img src="images/red-stripe.jpg" /></li>
                <li><img src="images/red-stripe-bw.jpg" /></li>
                <li><img src="images/red-stripe-red.jpg" /></li>            
                <li><img src="images/red-stripe-dark.jpg" /></li>
                <li><img src="images/red-stripe.jpg" /></li>
                <li><img src="images/red-stripe-red.jpg" /></li>
                <li><img src="images/red-stripe-dark.jpg" /></li>           
            </ul>       
        </div>
        <a class="buttons next" href="#"></a>
    </div>

    <div style="clear:both"></div>

    <div id="edit-image-nav">
        <div id="add_comment"><img src="images/comment-icon.png" /></div>
        <div id="like"><img src="images/paint-icon.png" /></div>
        <div id="delete_img"><img src="images/delete-icon.png" /></div>
    </div>  

Please note that what happens is, when you click on one of the icons in the 'edit-image-nav' div (which are overlayed on the images in the UL above onHover), it has different functionality. For the other icons, it works. For the #delete_img however, it does not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身仙ぐ女味 2024-10-14 06:39:47

您的代码中似乎没有错误,但如果它确实不起作用,请尝试以下操作:


$('#delete_img').click(function(e) {
            var offset = $(this).offset();
            $(this).parent().parent().parent().children("img").fadeTo("slow", 0.30, function() {
                   $(this).css('opacity', 0.3);
            } );
            $(this).parents("li").children("img").css({ 'border' : '3px solid #f6f6f7' });
            e.stopPropagation();
});

It doesn't seems to be an error in your code, but if it really doesn't work try this:


$('#delete_img').click(function(e) {
            var offset = $(this).offset();
            $(this).parent().parent().parent().children("img").fadeTo("slow", 0.30, function() {
                   $(this).css('opacity', 0.3);
            } );
            $(this).parents("li").children("img").css({ 'border' : '3px solid #f6f6f7' });
            e.stopPropagation();
});

带刺的爱情 2024-10-14 06:39:47

图像不能是父级(当然不太可能是),因此您的选择器是错误的。如果没有相关的 HTML 片段,很难说它应该是什么,但您可能想尝试一下(如果您的删除按钮距离要删除的目标低两级,这将起作用):

$(this).parent().parent().find("img").fadeTo("slow", 0.30);

图像上的 fadeTo 方法在 IE8 上工作得很好。如果这不起作用,请发布您的 html。

否则,请确保您的 img 标签指定了高度和宽度,否则 IE 将不会对元素应用不透明度更改,因为它“没有布局” - 有关详细说明,请参阅 http://www.satzansatz.de/cssd/onhavinglayout.html

Image cannot be a parent (well it is very unlikely to be) so your selector is wrong. It is hard to say what it should be without a relevant HTML snippet but you might want to try (this will work if your delete button is two levels down from the target to be deleted):

$(this).parent().parent().find("img").fadeTo("slow", 0.30);

The fadeTo method on image works just fine with IE8. If this doesn't work please post your html.

Otherwise make sure that your img tag has a height and width specified otherwise IE will not apply opacity change to the element as it "has no layout" - for detailed explanation see http://www.satzansatz.de/cssd/onhavinglayout.html.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文