找回密码
 注册
首页 ≡≡网络技术≡≡ PHP语言 Discuz! discuz X3 关闭帖子图片动态放大效果和新窗口弹出原图效 ...

discuz X3 关闭帖子图片动态放大效果和新窗口弹出原图效果?

灰儿 2021-2-15 21:55:54
discuz X3 教你同时关闭帖子图片动态放大效果和新窗口弹出原图效果?

虽然discuz很牛×的开发了图片弹出和放大的功能,但是,这个功能并不是人人都喜欢的,对于小站长来说,一些图片往往会有推广链接加上,如果再加上一个本身的放大弹出时间,那无疑对链接推广大打折扣,因此,都希望能够同时关闭帖子图片动态放大效果和新窗口弹出原图效果?。

网上也有很多人提出了这个问题,都是相同的意思,我也尝试过几次,一直没有解决,昨天,终于狠下决心,根据源码跟踪解决了这个问题。


使用浏览器跟踪我们可以看到图片的源码类似如下:
<img id="aimg_KZeLZ" class="zoom"zoom(this, this.src, ..." src="图片地址" alt="" width="380" height="480">

那么我们只要让事件失效就可以解决这个问题了

解决办法如下:

\source\function\function_attachment.php

171~178行,原代码为:

function attachwidth($width) {

    global $_G;

    if($_G['setting']['imagemaxwidth'] && $width) {

        return 'class="zoom" width="'.($width > $_G['setting']['imagemaxwidth'] ? $_G['setting']['imagemaxwidth'] : $width).'"';

    } else {

        return 'thumbImg="1"';

    }

}



删除原174行中的代码:

onclick="zoom(this, this.src, 0, 0, '.($_G['setting']['showexif'] ? 1 : 0).')"



现在的代码变为:

function attachwidth($width) {

    global $_G;

    if($_G['setting']['imagemaxwidth'] && $width) {

        return 'class="zoom" width="'.($width > $_G['setting']['imagemaxwidth'] ? $_G['setting']['imagemaxwidth'] : $width).'"';

    } else {

        return 'thumbImg="1"';

    }

}



找到模版页\template\default\forum\discuzcode.htm

将原258行的onclick事件删除,为了减少没必要的资源浪费,顺便将style="cursor:pointer"样式与zoomfile属性也一起也删除,即将原代码:

<img{if $attach['price'] && $_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']} class="attprice"{/if} style="cursor:pointer" id="aimg_$attach[aid]" aid="$attach[aid]" src="{STATICURL}image/common/none.gif" zoomfile="{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes&nothumb=yes{else}{$attach[url]}$attach[attachment]{/if}" file="{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode{else}{$attach[url]}$attachthumb{/if}" inpost="1"{if $_GET['from'] != 'preview'}{/if} />

改为:

<img{if $attach['price'] && $_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']} class="attprice"{/if} id="aimg_$attach[aid]" aid="$attach[aid]" src="{STATICURL}image/common/none.gif" file="{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode{else}{$attach[url]}$attachthumb{/if}" inpost="1"{if $_GET['from'] != 'preview'}{/if} />



为了减少没必要的资源浪费,将原260行的zoomfile属性也删除,即将原代码:

<img{if $attach['price'] && $_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']} class="attprice"{/if} id="aimg_$attach[aid]" aid="$attach[aid]" src="{STATICURL}image/common/none.gif" zoomfile="{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes&nothumb=yes{else}{$attach[url]}$attach[attachment]{/if}" file="{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes{else}{$attach[url]}$attach[attachment]{/if}" $widthcode id="aimg_$attach[aid]" inpost="1"{if $_GET['from'] != 'preview'}{/if} />     

改为:

<img{if $attach['price'] && $_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']} class="attprice"{/if} id="aimg_$attach[aid]" aid="$attach[aid]" src="{STATICURL}image/common/none.gif" file="{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes{else}{$attach[url]}$attach[attachment]{/if}" $widthcode id="aimg_$attach[aid]" inpost="1"{if $_GET['from'] != 'preview'}{/if} />



删除外链图片弹出窗口



打开source\function\function_discuzcode.php



修改前备份





262行跟263行,都删除

onload=\"thumbImg(this)\"



686行

把这句

$extra = 'onmouseover="img_onmouseoverfunc(this)" style="cursor:pointer"';



修改为

$extra = '';



706行

把这句

$img = '<img id="aimg_'.$rimg_id.'" class="zoom"'.($width >



修改为

$img = '<img id="aimg_'.$rimg_id.'" class="zoom"'.($width >



注意这里如果外链图片没有设置宽度跟高度,图片还是会弹出窗口打开,



260行

"parseimg(0, 0, '\\1', ".intval($lazyload).", ".intval($pid).", 'onmouseover=\"img_onmouseoverfunc(this)\" ".($lazyload ? "lazyloadthumb=\"1\"" : "onload=\"thumbImg(this)\"")."')",



修改为这样,图片就显示默认宽度,不受后台设置的宽度控制,好处就是不会在新窗口打开了。

"parseimg(0, 0, '\\1', ".intval($lazyload).", ".intval($pid).", '".($lazyload ? "": "onload=\"thumbImg(this)\"")."')",



外链图片没有设置宽度跟高度,图片还是会弹出窗口打开解决方法



260行

"parseimg(0, 0, '\\1', ".intval($lazyload).", ".intval($pid).", 'onmouseover=\"img_onmouseoverfunc(this)\" ".($lazyload ? "lazyloadthumb=\"1\"" : "onload=\"thumbImg(this)\"")."')",



修改成

"parseimg(0, 0, '\\1', ".intval($lazyload).", ".intval($pid).", '".($lazyload ? "XinChuanKouDaKai=\"1\"" : "onload=\"\"")."')"





706行

$img = '<img id="aimg_'.$rimg_id.'" class="zoom"'.($width > 0 ? ' width="'.$width.'"' : '').($height > 0 ? ' height="'.$height.'"' : '').' '.$attrsrc.'="{url}" '.($extra ? $extra.' ' : '').'border="0" alt="" />';



修改成

$img = '<img id="aimg_'.$rimg_id.'" class="zoom"'.($width > 0 ? ' width="'.$width.'"' : '').($height > 0 ? ' height="'.$height.'"' : '').' '.$attrsrc.'="{url}" '.($extra ? $extra.' ' : '').'border="0" width="440px" rel="nofollow" alt="" />';



注意:440px是我设置的默认宽度,因为去掉了一些js,图片未设置宽度,它就是以图片自身的宽带显示,如果图片是1920宽带,那网页就完全乱码了,440你可以随意修改。




如还是问题未解决,请在下面回复。。。

您需要登录后才可以回帖 登录 | 注册
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。