Turns Out jQuery and Discuz! Actually Conflict
Original Chinese title: 原来jquery和discuz还是有冲突的
While working on a Discuz! template, I needed a banner effect and remembered I had downloaded nivo-slider earlier. Everything worked fine when embedded inside a module, but when using DIY mode, the JS failed to load properly. At first I suspected a conflict with some core functions, then I realized the widget used jQuery 1.9.0.
After googling it, I found out that jQuery’s $() clashes with common.js, making it unusable. Here’s a workaround I grabbed:
1、打开discuz中共用的header.hrm文件,在<script type="text/javascript" src="{$jspath}common.js?{VERHASH}"></script>下面加载jQuery<script type="text/javascript" src="{$jspath}jquery.js?{VERHASH}"></script>。
2、这里两种情况,一种是直接在文档中写js代码
<script language="javascript" type="text/javascript">
<!--
var jq = jQuery.noConflict();
jq(document).ready(function(){
jq("select").sSelect();
})
-->
</script>
这里我自定义的函数名就是jq,还有一种情况是外链一个js文件,情况是一样的,只要在这个js文件开头加上var jq = jQuery.noConflict();,然后下面用到$的地方都替换为自定义函数名jq就可以了。
Would you believe I eventually gave in and just used runslideshow(); from common.js to make a big slideshow instead?
runslideshow();
<div class="slidebox"><!--幻灯片开始-->
<div class="slideshow"> </div><!--图片展示-->
<div class="slidebar"> </div><!--幻灯片控制展示-->
</div><!--幻灯片结束-->
A very simple slideshow
[loop]
[Archived image unavailable in 2013–2019 mirror: {pic}]
[/loop]
[loop1]{currentorder}[/loop1]
<script type="text/javascript">
runslideshow();
</script>
Slideshow speed
在<div class="slidebox" >增加参数 如下代码 其中 timestep="3000" 为毫秒
Multiple images
<div class="slidebox" slidenum="3" slidestep="1">
其中 slidenum="3" 表示显示数量 , slidestep="1" 表示每点击一次左右按扭 移动的次数 在作discuz的一个template 的时候需要做一个banner的效果,想到之前下过一个nivo-slider。嵌套到模块里面一切正常。但是使用diy的时候就无法正常加载js。刚开始怀疑是和一些基础的方法冲突了。后来发现这个控件用到了jq1.9.0。
google了下发现jq定义的$()和common.js一样,就无法使用。截取了一个方法
1、打开discuz中共用的header.hrm文件,在<script type="text/javascript" src="{$jspath}common.js?{VERHASH}"></script>下面加载jQuery<script type="text/javascript" src="{$jspath}jquery.js?{VERHASH}"></script>。
2、这里两种情况,一种是直接在文档中写js代码
<script language="javascript" type="text/javascript">
<!--
var jq = jQuery.noConflict();
jq(document).ready(function(){
jq("select").sSelect();
})
-->
</script>
这里我自定义的函数名就是jq,还有一种情况是外链一个js文件,情况是一样的,只要在这个js文件开头加上var jq = jQuery.noConflict();,然后下面用到$的地方都替换为自定义函数名jq就可以了。
我会告诉你最后我妥协了使用了common中的runslideshow();作了一个大幻灯么。
runslideshow();
<div class="slidebox"><!--幻灯片开始-->
<div class="slideshow"> </div><!--图片展示-->
<div class="slidebar"> </div><!--幻灯片控制展示-->
</div><!--幻灯片结束-->
##很简单的幻灯
[loop]
[Archived image unavailable in 2013–2019 mirror: {pic}]
[/loop]
[loop1]{currentorder}[/loop1]
<script type="text/javascript">
runslideshow();
</script>
幻灯的速度
在<div class="slidebox" >增加参数 如下代码 其中 timestep="3000" 为毫秒
多个图片
<div class="slidebox" slidenum="3" slidestep="1">
其中 slidenum="3" 表示显示数量 , slidestep="1" 表示每点击一次左右按扭 移动的次数