【问题标题】:Using Pixastic and .live with a class of images使用 Pixastic 和 .live 处理一类图像
【发布时间】:2011-10-25 05:31:58
【问题描述】:

我在 JavaScript 中使用 Pixastic 插件。我有一张桌子,里面装满了模糊的图像。当我用鼠标越过它们时,我希望它们恢复正常。当鼠标离开图像时,我希望它模糊回来。出于某种原因,我的代码不起作用。代码如下:

之前,我复制了错误的代码部分,对于这就是我要询问的部分,我深表歉意。

<script type="text/javascript">
    $(document).ready(function(){
        $('.photography').live('mouseover mouseout', function(event) {
            if (event.type == 'mouseover') {
                function () {Pixastic.revert('this');};
            }
            else {
                function(){Pixastic.process('this', "blurfast", {amount:0.5});};
            }
        });
    });
</script>

好的,所以我设法找到了实际上可以正常工作的旧代码(当我第一次将鼠标悬停在图像上时它可以工作,但当我第二次尝试时它不会工作)。

$(document).ready(function(){
    var blur = function() {Pixastic.process(this, "blurfast", {amount:0.5});};
    var unblur = function () {Pixastic.revert(this);};
    $('.photography').each(blur);
    $('.photography').hover(unblur,blur);
});

好的,现在我还要为名为@9​​87654323@的函数添加代码:

revert : function(img) {
    if (Pixastic.Client.hasCanvas()) {
        if (img.tagName.toLowerCase() == "canvas" && img.__pixastic_org_image) {
            img.width = img.__pixastic_org_width;
            img.height = img.__pixastic_org_height;
            img.getContext("2d").drawImage(img.__pixastic_org_image, 0, 0);

            if (img.parentNode && img.parentNode.replaceChild) {
                img.parentNode.replaceChild(img.__pixastic_org_image, img);;
            }
            return img;
        }
    }
    else
        if (Pixastic.Client.isIE()) {
            if (typeof img.__pixastic_org_style != "undefined")
                img.style.cssText = img.__pixastic_org_style;
            }
        }

【问题讨论】:

  • 也许你应该传递 this 而不是字符串? ('this')

标签: javascript image jquery pixastic


【解决方案1】:

所以昨天我的朋友发现了如何做到这一点......问题是插件将图像转换为画布无论如何她的代码:

$(document).ready(function(){

    $('.pic').each(function(){
        this.onmouseout = function(){
            var canvas1 = Pixastic.process(this, "blurfast", {amount:0.5});
            canvas1.onmouseover = function(){
                Pixastic.revert(this);

            }
        }

        this.onload = function(){
            var canvas = Pixastic.process(this, "blurfast", {amount:0.5});
            canvas.onmouseover = function(){
                Pixastic.revert(this);

            }
        }
    });
});

【讨论】:

    【解决方案2】:

    尝试这样做

    $('.photography').live('mouseenter', function(event){
        Pixastic.revert(this);
    }).live('mouseleave', function(event){
        Pixastic.process(this, "blurfast", {amount:0.5});
    });
    

    【讨论】:

    • 您遇到了什么错误?你能单步执行代码吗?是不是进入了 mouseenter 函数?
    • 好吧,我没有收到错误,这是我之前在 onhover 上使用了一些代码的问题,它曾经工作过一次(我的意思是,就像我用鼠标浏览图像然后离开它,当我下车时它第二次没有工作)如果我找到那个代码我会发布它......
    • 好的,所以我更新了它,但我认为第一个是正确的(我用 js alert(); 试过了)唯一的问题是我不知道如何访问在 div 旁边单击的图像...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    相关资源
    最近更新 更多