Reputation: 1792
$("#clickMe").click(
function(){
if (i == 1) {
i = i+1
$("#div p").css("left", "-" + width * i + "px");
}
});
As you can see -margin changes when somebody clicks a button. What if I want it to happen just on site load every 10 seconds?
Thanks.
Upvotes: 6
Views: 11830
Reputation: 14967
var cancel_margin_change = false;
$(function() {
var i = 1, width = 10, xtime = 10000,
margin_change = function() {
if (i == 1)
$("#div p").css("left", "-" + (width * (++i)) + "px");
if (!cancel_margin_change)
setTimeout(margin_change, xtime);
};
margin_change();
});
Upvotes: 0
Reputation: 70701
Use setInterval
to set up a timed event:
setInterval(
function(){
if (i == 1) {
i = i+1
$("#div p").css("left", "-" + width * i + "px");
}
},
10000 /* 10000 ms = 10 sec */
);
Upvotes: 12