javascript - how do you restart setInterval on mouse out -
i have function runs on document load after 5 seconds, on mouseover, want stop setinterval
, on mouseout reset it. have read loads tutorials cant work.
my code follows:
jquery(function () { var timerid = setinterval(function () { var name = "name"; jquery.ajax({ url: "/ajax-includes/index.php", type: 'post', datatype: 'html', data: {name: name}, beforesend: function () { jquery('#progress').html('processing...'); }, success: function (data, textstatus, xhr) { jquery('#bodymain').html(data) }, error: function (jqxhr, exception) { if (jqxhr.status === 0) { alert('not connect.\n verify network.'); } else if (jqxhr.status == 404) { alert('requested page not found. [404]'); } else if (jqxhr.status == 500) { alert('internal server error [500].'); } else if (exception === 'parsererror') { alert('requested json parse failed.'); } else if (exception === 'timeout') { alert('time out error.'); } else if (exception === 'abort') { alert('ajax request aborted.'); } else { alert('uncaught error.\n' + jqxhr.responsetext); } } }); }, 5000); jquery(document).on('mouseover', 'div.video', function (e) { e.stoppropagation(); var videoid = jquery(this).attr("vid"); jquery(this).css('background-color', 'red'); jquery(this).find("iframe").css('width', '0px').css('height', '0px'); jquery(this).find(".livebutton a").css('display', 'block'); clearinterval(timerid); }).mouseout(function () { jquery('div.video').css('background-color', 'white').css('color', 'white'); jquery(this).find("iframe").css('width', '200px').css('height', '200px'); jquery(this).find(".livebutton a").css('display', 'none'); var timerid = setinterval(5000); }); });
any great thanks.
var timerid = setinterval(myinterval, 5000); function myinterval() { var name = "name"; jquery.ajax({ url: "/ajax-includes/index.php", type: 'post', datatype: 'html', data: {name:name}, beforesend: function () { jquery('#progress').html('processing...'); }, success: function(data, textstatus, xhr) { jquery('#bodymain').html(data) }, error: function(jqxhr, exception) { if (jqxhr.status === 0) { alert('not connect.\n verify network.'); } else if (jqxhr.status == 404) { alert('requested page not found. [404]'); } else if (jqxhr.status == 500) { alert('internal server error [500].'); } else if (exception === 'parsererror') { alert('requested json parse failed.'); } else if (exception === 'timeout') { alert('time out error.'); } else if (exception === 'abort') { alert('ajax request aborted.'); } else { alert('uncaught error.\n' + jqxhr.responsetext); } } } jquery(document).on('mouseover','div.video',function(e){ e.stoppropagation(); var videoid = jquery(this).attr("vid"); jquery(this).css('background-color','red'); jquery(this).find("iframe").css('width','0px').css('height','0px'); jquery(this).find(".livebutton a").css('display','block'); clearinterval(timerid); }).mouseout(function(){ jquery('div.video').css('background-color','white').css('color','white'); jquery(this).find("iframe").css('width','200px').css('height','200px'); jquery(this).find(".livebutton a").css('display','none'); clearinterval(timerid); timerid = setinterval(myinterval, 5000); });
Comments
Post a Comment