[英]Having issues with “setInterval/clearInterval” in Javascript
[英]Issues with Javascript setInterval function on Joomla
我添加了這個腳本
<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>
到我模板的index.php。
我想使用腳本為一組圖像創建一個簡單的幻燈片。
循環僅運行一次並停止。
在Joomla外部,它可以完美運行,但在Joomla中,它只運行一次並停止。
Joomla是否與setInterval函數有關?
解決此問題的方法是什么?
這是分別指向Joomla和Joomla 之外的演示的鏈接Joomla演示 Outside Joomla演示
即使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);}
這是控制台上出現的錯誤:
Uncaught TypeError: Cannot call method 'css' of null
jQuery的,請嘗試更換的每個實例$
用jQuery
。
或者,您可以像這樣$
:
(function($){
// your code here
})(jQuery);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.