我在 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);
});
好的,所以现在我还要为函数添加代码revert
:
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;
}
}