繁体   English   中英

Javascript在Joomla中不起作用

[英]Javascript not working in Joomla article

我正在尝试将这个(dannyvankooten点com / jquery-plugins / mapz /)图片平移脚本实现到Joomla文章中。 我在Joomla( http://tylypahka.tk/karttatesting/ )外部进行了测试,并且运行良好。 但是,当我在Joomla文章中尝试过时,平移不起作用( http://tylypahka.tk/kartta )。

我在测试版中输入了与Joomla模板相同的代码:

<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js" type="text/javascript"></script>
<script src="https://jquery-ui.googlecode.com/svn-history/r2596/branches/dev/spinner/external/mousewheel/jquery.mousewheel.min.js" type="text/javascript" ></script>
<script src="http://tylypahka.tk/js/jquery.mapz.js" type="text/javascript"></script>
<script type="text/javascript" src="http://tylypahka.tk/js/jquery.maphilight.js"></script>
<script type="text/javascript">
$(document).ready(function() {
  $("#map").mapz({
    zoom : true,
    createmaps : true,
    mousewheel : true
  });
});
</script>
<script type="text/javascript">$(function() {
        $('.map').maphilight();
        $('#squidheadlink').mouseover(function(e) {
            $('#squidhead').mouseover();
        }).mouseout(function(e) {
            $('#squidhead').mouseout();
        }).click(function(e) { e.preventDefault(); });
    });</script>
<style>
.map-viewport{ position:relative; width:860px; height:883px; overflow:hidden; background-color:black;}
.level{ position:absolute; left:0; top:0; z-index:10;}
.current-level{ z-index:20; }
#map{ width:1297px; height:883px; position:absolute; left:0; top:0; cursor:move;}
</style>

和文章相同的代码:

<div class="map-viewport">
  <div id="map">
    <img src="http://img42.imageshack.us/img42/8954/tylypahkanportit.png" width="1297" height="883" usemap="#html-map" class="current-level level map" />
  </div>
  <map name="html-map">
    <area id="squidhead" shape="rect" coords="311,494,434,634" href="http://www.image-maps.com/" alt="" title=""/>
  </map>
</div>

jQuery自动在Joomla网站中加载,因此这不应该成为问题。 有任何想法我在这里做错了吗?

所有建议和帮助将不胜感激!

您正在使用$,这是jQuery的简写代码,但Joomla也加载了mootools,它被分配了相同的选择器:因此,只需将所有$()更改为jquery()即可,它应该可以工作。 您只需要在外部执行此操作,然后将$作为参数传递即可:

jQuery(function($){
  // inside this handler you can use the $ since you passed it as a parameter to the function:
  // btw, this is nicer than jQuery(document).ready...
  $('#someid').show();
}); 

最好使用Joomla编码标准将代码包含在您的头脑中,并且还要检查它是否尚未导入,因为这将导致冲突。

因此,首先,下载Sourcerer ,它将允许您将代码添加到文章中。

然后,使用Sourcerer添加以下内容:

$document = JFactory::getDocument();
if(!JFactory::getApplication()->get('jqueryui')){
     JFactory::getApplication()->set('jqueryui',true);
     $document->addScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js");
}
$document->addScript("https://jquery-ui.googlecode.com/svn-history/r2596/branches/dev/spinner/external/mousewheel/jquery.mousewheel.min.js");
$document->addScript("http://tylypahka.tk/js/jquery.mapz.js");
$document->addScript("http://tylypahka.tk/js/jquery.maphilight.js");
$document->addScriptDeclaration('
$(document).ready(function() {
  $("#map").mapz({
    zoom : true,
    createmaps : true,
    mousewheel : true
  });
});
');
$document->addScriptDeclaration('
$(function() {
        $('.map').maphilight();
        $('#squidheadlink').mouseover(function(e) {
            $('#squidhead').mouseover();
        }).mouseout(function(e) {
            $('#squidhead').mouseout();
        }).click(function(e) { e.preventDefault(); });
    });
');

$document->addStyleDeclaration(.map-viewport { position:relative; width:860px; height:883px; overflow:hidden; background-color:black;}
.level{ position:absolute; left:0; top:0; z-index:10;}
.current-level{ z-index:20; }
#map{ width:1297px; height:883px; position:absolute; left:0; top:0; cursor:move;});

希望这能有所帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM