Postings

You can freely browse the forum and post in the community forum.
However, you need a valid license to write posts for support (own a valid commercial software license or have purchased a support membership).

Posts only show once reviewed. This is mainly preventive to keep spam away. Thank you for your understanding!

setInterval functionality?

More
IP: 76.172.179.58 14 years 1 month ago #1004 by jqueryplease
Hi Everyone,

I downloaded jquery easy to enable jquery on my joomla 2.5 site...It works great for stuff like .animate, but I'm having a problem getting an animation to work that uses setInterval. I assume this is because it's Javascript rather than jQuery...

The relevant jQuery code is below:

var g = 0;
var e = 0;
var b = 0;
var d = 0;

jQuery(document).ready(function($) {

setInterval("animateopener()", 30);

$("#testbutton2").click(function() {

g=0;
e=0;
b=0;
d=0;

}); });

function animateopener () {
/*the function is kind of long, so I'll leave it out*/
}

I didn't include the definition of the function animateopener(), but it basically cycles through the background of a div to create an animation when you click on #testbutton2. It's defined as a function that uses the backgroundPosition property through .css combined with counters for x and y position.

Please help! It might even be a simple coding issue I'm overlooking!
More
IP: 207.229.131.129 14 years 1 month ago - 14 years 1 month ago #1006 by admin
Hello, I would package your code differently, something like (this is an example):
Code:
(function($) { $.fn.animate = function(options) { var defaults = { speed: 1000, pause: 3000 }; var options = $.extend(defaults, options); this.each(function() { var obj = $(this); // possible code here on obj var timer = setInterval(function() { animateopener(); }, options.pause); // Pause the animation on mouse over obj.hover( function () { clearInterval(timer); }, function () { timer = setInterval(function(){ animateopener(); }, options.pause); } ); function animateopener() { // your code here }; }); }; })(jQuery); jQuery(document).ready(function($) { $("some html element here").animate({ speed: 1000, pause: 3000 }); });

Olivier.
Last edit: 14 years 1 month ago by admin.