jQuery 和 Mootools 冲突
我知道有很多关于在 mootools 中使用 jQuery 的帖子,但我做错了。
原来的头部MooTools + jQuery:
<head>
<?php css(); ?>
<meta name="viewport" content="width=device-width" />
<meta content="text/html; charset=<?php print $this->getConfig('charset'); ?>" http-equiv="content-type" />
<?php
if(($this->getConfig('log_file') != null && strlen($this->getConfig('log_file')) > 0)
|| ($this->getConfig('thumbnails') != null && $this->getConfig('thumbnails') == true && $this->mobile == false))
{
?>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.livadi.gr/ib/sources/js/mootools.js"></script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
<?php
if($this->logging == true)
{
?>
function logFileClick(path)
{
$.ajax({
async: false,
type: "POST",
data: {log: path},
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
cache: false
});
}
$("a.file").click(function(){
logFileClick("<?php print $this->location->getDir(true, true, false, 0);?>" + $(this).html());
return true;
});
<?php
}
if(EncodeExplorer::getConfig("thumbnails") == true && $this->mobile == false)
{
?>
function positionThumbnail(e) {
xOffset = 30;
yOffset = 10;
$("#thumb").css("left",(e.clientX + xOffset) + "px");
diff = 0;
if(e.clientY + $("#thumb").height() > $(window).height())
diff = e.clientY + $("#thumb").height() - $(window).height();
$("#thumb").css("top",(e.pageY - yOffset - diff) + "px");
}
$("a.thumb").hover(function(e){
$("#thumb").remove();
$("body").append("<div id=\"thumb\"><img src=\"?thumb="+ $(this).attr("href") +"\" alt=\"Preview\" \/><\/div>");
positionThumbnail(e);
$("#thumb").fadeIn("medium");
},
function(){
$("#thumb").remove();
});
$("a.thumb").mousemove(function(e){
positionThumbnail(e);
});
$("a.thumb").click(function(e){$("#thumb").remove(); return true;});
<?php
}
?>
});
//]]>
</script>
<?php
}
?>
<title><?php if(EncodeExplorer::getConfig('main_title') != null) print EncodeExplorer::getConfig('main_title'); ?></title>
</head>
现在我已经放入了jQuery.noConflict();
,并用jQuery
替换了$
。之后,MooTools 就不能通过 jQuery 工作了。
标题有一些变化:
<head>
<?php css(); ?>
<meta name="viewport" content="width=device-width" />
<meta content="text/html; charset=<?php print $this->getConfig('charset'); ?>" http-equiv="content-type" />
<?php
if(($this->getConfig('log_file') != null && strlen($this->getConfig('log_file')) > 0)
|| ($this->getConfig('thumbnails') != null && $this->getConfig('thumbnails') == true && $this->mobile == false))
{
?>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.livadi.gr/ib/sources/js/mootools.js"></script>
<script type="text/javascript">
//<![CDATA[
//no conflict jquery
jQuery.noConflict();
//jquery stuff
jQuery(document).ready(function() {
<?php
if($this->logging == true)
{
?>
function logFileClick(path)
{
jQuery.ajax({
async: false,
type: "POST",
data: {log: path},
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
cache: false
});
}
jQuery("a.file").click(function(){
logFileClick("<?php print $this->location->getDir(true, true, false, 0);?>" + $(this).html());
return true;
});
<?php
}
if(EncodeExplorer::getConfig("thumbnails") == true && $this->mobile == false)
{
?>
function positionThumbnail(e) {
xOffset = 30;
yOffset = 10;
jQuery("#thumb").css("left",(e.clientX + xOffset) + "px");
diff = 0;
if(e.clientY + $("#thumb").height() > $(window).height())
diff = e.clientY + $("#thumb").height() - $(window).height();
jQuery("#thumb").css("top",(e.pageY - yOffset - diff) + "px");
}
jQuery("a.thumb").hover(function(e){
jQuery("#thumb").remove();
jQuery("body").append("<div id=\"thumb\"><img src=\"?thumb="+ $(this).attr("href") +"\" alt=\"Preview\" \/><\/div>");
positionThumbnail(e);
jQuery("#thumb").fadeIn("medium");
},
function(){
jQuery("#thumb").remove();
});
jQuery("a.thumb").mousemove(function(e){
positionThumbnail(e);
});
jQuery("a.thumb").click(function(e){$("#thumb").remove(); return true;});
<?php
}
?>
});
//]]>
</script>
<?php
}
?>
<title><?php if(EncodeExplorer::getConfig('main_title') != null) print EncodeExplorer::getConfig('main_title'); ?></title>
</head>
I know that there are many post about hot to use jQuery with mootools, but I am doing something wrong.
The original head MooTools + jQuery:
<head>
<?php css(); ?>
<meta name="viewport" content="width=device-width" />
<meta content="text/html; charset=<?php print $this->getConfig('charset'); ?>" http-equiv="content-type" />
<?php
if(($this->getConfig('log_file') != null && strlen($this->getConfig('log_file')) > 0)
|| ($this->getConfig('thumbnails') != null && $this->getConfig('thumbnails') == true && $this->mobile == false))
{
?>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.livadi.gr/ib/sources/js/mootools.js"></script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
<?php
if($this->logging == true)
{
?>
function logFileClick(path)
{
$.ajax({
async: false,
type: "POST",
data: {log: path},
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
cache: false
});
}
$("a.file").click(function(){
logFileClick("<?php print $this->location->getDir(true, true, false, 0);?>" + $(this).html());
return true;
});
<?php
}
if(EncodeExplorer::getConfig("thumbnails") == true && $this->mobile == false)
{
?>
function positionThumbnail(e) {
xOffset = 30;
yOffset = 10;
$("#thumb").css("left",(e.clientX + xOffset) + "px");
diff = 0;
if(e.clientY + $("#thumb").height() > $(window).height())
diff = e.clientY + $("#thumb").height() - $(window).height();
$("#thumb").css("top",(e.pageY - yOffset - diff) + "px");
}
$("a.thumb").hover(function(e){
$("#thumb").remove();
$("body").append("<div id=\"thumb\"><img src=\"?thumb="+ $(this).attr("href") +"\" alt=\"Preview\" \/><\/div>");
positionThumbnail(e);
$("#thumb").fadeIn("medium");
},
function(){
$("#thumb").remove();
});
$("a.thumb").mousemove(function(e){
positionThumbnail(e);
});
$("a.thumb").click(function(e){$("#thumb").remove(); return true;});
<?php
}
?>
});
//]]>
</script>
<?php
}
?>
<title><?php if(EncodeExplorer::getConfig('main_title') != null) print EncodeExplorer::getConfig('main_title'); ?></title>
</head>
Now I have put the jQuery.noConflict();
and replaced the $
with the jQuery
. After that, MooTools is working by jQuery isn't.
The header with some changes:
<head>
<?php css(); ?>
<meta name="viewport" content="width=device-width" />
<meta content="text/html; charset=<?php print $this->getConfig('charset'); ?>" http-equiv="content-type" />
<?php
if(($this->getConfig('log_file') != null && strlen($this->getConfig('log_file')) > 0)
|| ($this->getConfig('thumbnails') != null && $this->getConfig('thumbnails') == true && $this->mobile == false))
{
?>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.livadi.gr/ib/sources/js/mootools.js"></script>
<script type="text/javascript">
//<![CDATA[
//no conflict jquery
jQuery.noConflict();
//jquery stuff
jQuery(document).ready(function() {
<?php
if($this->logging == true)
{
?>
function logFileClick(path)
{
jQuery.ajax({
async: false,
type: "POST",
data: {log: path},
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
cache: false
});
}
jQuery("a.file").click(function(){
logFileClick("<?php print $this->location->getDir(true, true, false, 0);?>" + $(this).html());
return true;
});
<?php
}
if(EncodeExplorer::getConfig("thumbnails") == true && $this->mobile == false)
{
?>
function positionThumbnail(e) {
xOffset = 30;
yOffset = 10;
jQuery("#thumb").css("left",(e.clientX + xOffset) + "px");
diff = 0;
if(e.clientY + $("#thumb").height() > $(window).height())
diff = e.clientY + $("#thumb").height() - $(window).height();
jQuery("#thumb").css("top",(e.pageY - yOffset - diff) + "px");
}
jQuery("a.thumb").hover(function(e){
jQuery("#thumb").remove();
jQuery("body").append("<div id=\"thumb\"><img src=\"?thumb="+ $(this).attr("href") +"\" alt=\"Preview\" \/><\/div>");
positionThumbnail(e);
jQuery("#thumb").fadeIn("medium");
},
function(){
jQuery("#thumb").remove();
});
jQuery("a.thumb").mousemove(function(e){
positionThumbnail(e);
});
jQuery("a.thumb").click(function(e){$("#thumb").remove(); return true;});
<?php
}
?>
});
//]]>
</script>
<?php
}
?>
<title><?php if(EncodeExplorer::getConfig('main_title') != null) print EncodeExplorer::getConfig('main_title'); ?></title>
</head>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个...
如果你在 joomla 中使用 mootools 它将与 JQuery 冲突。这样 JQuery 将无法工作。
首先需要安装 SC 系统 JQuery 插件。
并对 JQuery 使用以下代码。
将 $ 符号替换为 (JQuery) 关键字
然后您将使用 jquery.
Try this...
If you use mootools in joomla it will conflict with JQuery. So that the JQuery is wont work.
First Need Install the SC System JQuery plugin.
And use the following code for JQuery.
Replace the $ sign with (JQuery) keyword
Then you will use the jquery.
然后尝试
在您自己的库调用中使用 j 而不是 jQuery。
您还可以封装您自己的所有使用 jQ 的代码,如下所示:
Try
and then use j rather than jQuery in your own calls to the lib.
You can also encapsulate all of your own code that use jQ like this: