JavaScript 库相互冲突

发布于 2024-09-07 16:55:14 字数 2595 浏览 2 评论 0原文

我正在为我的女朋友开发一个模特网站,她想要一个大型幻灯片作为网站的背景。为此,我使用了 JonDesign Gallery,它非常适合此目的,而且重量相对较轻。

现在,对于联系表单,我想使用 Lightbox/Slimbox 风格。 Slimbox 与 Mootools 配合使用,京东画廊也使用 Mootools。不幸的是,Slimbox 似乎与京东画廊有冲突,我不明白为什么。我检查了 CSS 是否有冲突,但没有元素 ID 或类两次。我查看了代码,无法立即发现冲突。我确定我错过了什么。我无法弄清楚,因为我没有太多使用 JavaScript 的经验,更不用说 Mootools 或 Slimbox 了。

这是我的(相关)代码。

头部

<link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="css/jd.gallery.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="css/slimbox.css" type="text/css" media="screen" /> 

<script type="text/javascript" src="scripts/mootools.js"></script>
<script src="scripts/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
<script src="scripts/mootools-1.2-more.js" type="text/javascript"></script>
<script src="scripts/jd.gallery.js" type="text/javascript"></script>
<script src="scripts/jd.gallery.transitions.js" type="text/javascript"></script>

<script type="text/javascript" src="scripts/slimbox.js"></script> 

身体

<script type="text/javascript">
function startGallery() {
 var myGallery = new gallery($('myGallery'), {
 timed: true,
 showArrows: false,
 showCarousel: false,
 delay: 6000,
 embedLinks: false,
 showInfopane: false,
});
}
window.addEvent('domready', startGallery);
</script>
<div id="myGalleryBox">
            <a href="contact.php" rel="lightbox" class="menu">Contact her</a>
</p>
</div>
<div class="content" style="z-index:1;">
<div id="myGallery">
<div class="imageElement">
 <h3>Item 2 Title</h3>
 <p>Item 2 Description</p>
 <a href="#" title="open image" class="open"></a>
 <img src="images/pic1.jpg" class="full" />
</div>
</div>
</div>`

据我所知,冲突存在于这些线条之间:

<script type="text/javascript" src="scripts/mootools.js"></script>

以及

<script src="scripts/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
<script src="scripts/mootools-1.2-more.js" type="text/javascript"></script>

头部。

我使用的是 JD GallerySlimBox。任何帮助将不胜感激!

I'm working on a modeling website for my girlfriend and she wants a large slideshow as background on the website. I used the JonDesign Gallery for that, which works nicely for this purpose and is relatively light-weight.

Now, for the contact form I'd like to use something Lightbox/Slimbox style. Slimbox works with Mootools, which is also used by JD Gallery. Unfortunately, Slimbox seems to conflict with JD Gallery and I can't figure out why. I checked the CSS for conflicts, but there are no elements ID'd or class'd twice. I looked at the code and couldn't immediately spot a conflict. I'm sure I missed something. I can't figure it out because I don't have much experience with JavaScript let alone Mootools or Slimbox.

Here's my (relevant) code.

Head

<link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="css/jd.gallery.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="css/slimbox.css" type="text/css" media="screen" /> 

<script type="text/javascript" src="scripts/mootools.js"></script>
<script src="scripts/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
<script src="scripts/mootools-1.2-more.js" type="text/javascript"></script>
<script src="scripts/jd.gallery.js" type="text/javascript"></script>
<script src="scripts/jd.gallery.transitions.js" type="text/javascript"></script>

<script type="text/javascript" src="scripts/slimbox.js"></script> 

Body

<script type="text/javascript">
function startGallery() {
 var myGallery = new gallery($('myGallery'), {
 timed: true,
 showArrows: false,
 showCarousel: false,
 delay: 6000,
 embedLinks: false,
 showInfopane: false,
});
}
window.addEvent('domready', startGallery);
</script>
<div id="myGalleryBox">
            <a href="contact.php" rel="lightbox" class="menu">Contact her</a>
</p>
</div>
<div class="content" style="z-index:1;">
<div id="myGallery">
<div class="imageElement">
 <h3>Item 2 Title</h3>
 <p>Item 2 Description</p>
 <a href="#" title="open image" class="open"></a>
 <img src="images/pic1.jpg" class="full" />
</div>
</div>
</div>`

As far as I can tell, the conflict is between these lines:

<script type="text/javascript" src="scripts/mootools.js"></script>

and

<script src="scripts/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
<script src="scripts/mootools-1.2-more.js" type="text/javascript"></script>

in the head.

I'm using unmodified code from JD Gallery and SlimBox. Any help would be much appreciated!

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

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

发布评论

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

评论(4

無心 2024-09-14 16:55:25

当我不得不在同一页面中使用两个版本的 jquery 时,我遇到了同样的问题。

<script type='text/javascript'>
// This script prevent the conflict between older and newer versions of jquery
var $jq = jQuery.noConflict(true);  
</script> 

然后你可以通过使用类似这样的东西来引用你的不同版本的jquery:

var $noborders = $jq('.noborders');

我希望这样的东西也能解决你的问题。

I faced the same issue when I had to use two versions of jquery in the same page.

<script type='text/javascript'>
// This script prevent the conflict between older and newer versions of jquery
var $jq = jQuery.noConflict(true);  
</script> 

And then you can reference your different version of jquery by using something like this :

var $noborders = $jq('.noborders');

I hope something like this will solve your issue too.

芸娘子的小脾气 2024-09-14 16:55:23

好的,现在可以使用了。事情是这样的:我按照 Matthew Crumley 的建议删除了多余的逗号 (+1)。根据 Anurag 的说法,我检查了 Chrome 的开发者工具(我完全忘记了这一点 - 工作到很晚=不好。)它没有显示任何错误。然后我重新下载了SlimBox文件并尝试了演示,但没有成功。然后我注意到 SlimBox 有两个文件夹,其中包含 SlimBox JS 文件:js 和 src。 js 是具有正确库的正确文件夹,src 无论出于何种原因都不起作用。我更改了网站以使用 js 文件夹中的文件,现在可以正常工作了。

底线:毕竟没有脚本冲突,SlimBox 只是以一种奇怪的方式分发。谢谢大家的帮助!

Alright, it's working now. Here's what's going on: I removed the extra comma as per Matthew Crumley's suggestion (+1). Per Anurag, I checked Chrome's developer tool (I completely forgot about that - working late = bad.) It didn't show any errors. Then I redownloaded the SlimBox files and tried the demo, which didn't work. Then I noticed that SlimBox had two folders with its SlimBox JS files: js and src. js is the correct folder with the correct library, src doesn't work for whatever reason. I changed the website to use the file from the js folder and it's now working.

Bottom line: No script conflict after all, SlimBox was just distributed in a weird way. Thank you everybody for your help!

记忆消瘦 2024-09-14 16:55:22

在 JQuery 中,您可以为 JQuery 函数选择一个新名称,以避免与其他库(例如 Prototype)发生冲突。 Mootools 可能支持类似的东西。

In JQuery you can choose a new name for the JQuery function to avoid conflicts with other libraries, e.g. Prototype. Mootools might support something similar.

§对你不离不弃 2024-09-14 16:55:20

我能看到的唯一问题是图库选项末尾有一个额外的逗号:

var myGallery = new gallery($('myGallery'), {
    ...
    showInfopane: false, <--- Right Here
});

至少 Firefox 和 Chrome 会忽略尾随的逗号,但在 Internet Explorer 中这是一个语法错误。在我解决这个问题后,你的代码在 Chrome、Firefox 和 IE 中运行得很好。

就像 Anurag 在评论中提到的那样,您将 MooTools 包含了两次。它没有对我造成任何问题,但您可以删除 scripts/mootools.js 脚本,它应该仍然可以工作。

The only problem I can see is an extra comma at the end of the gallery options:

var myGallery = new gallery($('myGallery'), {
    ...
    showInfopane: false, <--- Right Here
});

At least Firefox and Chrome ignore the trailing comma, but it's a syntax error in Internet Explorer. After I fixed that, your code worked fine for me in Chrome, Firefox, and IE.

Like Anurag mentioned in the comments, you are including MooTools twice. It didn't cause any problems for me, but you can remove the scripts/mootools.js script, and it should still work.

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