简体   繁体   English

Joomla上的Javascript setInterval函数的问题

[英]Issues with Javascript setInterval function on Joomla

I added this script 我添加了这个脚本

<script type="text/javascript">
    var x = 2;
//console.log('Not broken');
$('.email_image li:gt(0)').css({opacity:0});

setInterval(function() { // function slideshow() { var m = $('.email_image li').size(); x += 1; console.log('Not broken'); if (x > m) { x = 1; } $(".email_image ul li:visible").animate({ opacity: 0 }); $(".email_image ul li:nth-child(" + (x) + ")").animate({ opacity: 1 }); // } }, 5000); </script>

to the index.php of my template. 到我模板的index.php。 I want to use the script to create a simple slideshow for some set of images. 我想使用脚本为一组图像创建一个简单的幻灯片。 The loop just runs once and stops. 循环仅运行一次并停止。 Outside Joomla, it works perfectly but in Joomla, it just runs once and stops. 在Joomla外部,它可以完美运行,但在Joomla中,它只运行一次并停止。 Does Joomla have issues with the setInterval function. Joomla是否与setInterval函数有关? What is way around this issue? 解决此问题的方法是什么?

Here are the links to the demos in Joomla and out of Joomla respectively Joomla demo Outside Joomla demo 这是分别指向Joomla和Joomla 之外的演示的链接Joomla演示 Outside Joomla演示

Even though jQuery path is correct and included fine but $ returns something other than jQuery (seems like a conflict): 即使jQuery路径正确且包含正确,但$返回jQuery以外的值(似乎有冲突):

function $(el){if(!el)return null;if(el.htmlElement)return Garbage.collect(el);if([window,document].contains(el))return el;var type=$type(el);if(type=='string'){el=document.getElementById(el);type=(el)?'element':false;}
if(type!='element')return null;if(el.htmlElement)return Garbage.collect(el);if(['object','embed'].contains(el.tagName.toLowerCase()))return el;$extend(el,Element.prototype);el.htmlElement=function(){};return Garbage.collect(el);}

Here is the error coming on console: 这是控制台上出现的错误:

Uncaught TypeError: Cannot call method 'css' of null

For jQuery, try replacing each instance of $ with jQuery . jQuery的,请尝试更换的每个实例$jQuery

Or you can $ like this: 或者,您可以像这样$

(function($){
   // your code here
})(jQuery);

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

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