工具提示中的JavaScript倒计时。我如何使用它?

时间:2019-04-05 20:35:09

标签: javascript jquery html tooltip countdown

我在工具提示中找到了此javascript(jquery)代码,用于倒数计数器。但是我不知道怎么称呼它。如何集成到HTML或PHP。

这是代码:

	$("a.tooltip").mousemove(function(e){
                xOffset = 10;
		yOffset = 20;
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			

        var date = new Date();
        var started = date.getTime();
	$(".tooltip_countdown").hover(function(e){   
                xOffset = 10;
		yOffset = 20;	
		this.t = this.title;
		this.title = "";
                data = jQuery.parseJSON(this.t);
                div_id1 = "counter_"+data.id1;
                if(data.id2) {
                    div_id2 = "counter_"+data.id2;
                    span2 = "<br><span id='"+div_id2+"'>2</span>";
                }
                else {
                    div_id2 = "";
                    span2 = "";
                }
                $("body").append("<div id='tooltip'><span id='"+div_id1+"'>1</span>"+span2+"</div>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
                now = new Date();
                diff = Math.round((now.getTime() - started) / 1000);
                sec = parseInt(data.time1) - diff;
                now.setSeconds(now.getSeconds() + sec);
                if(sec > 86400) c = "{dn} {dl} {hn} {hl} {mn} {ml}"; else if(sec > 3600) c = "{hn} {hl} {mn} {ml} {sn} {sl}"; else c = "{mn} {ml} {sn} {sl}";
                if(this.id == 'ikon_alvas' || this.id == 'ikon_munka') 
                    ttxt = 'Épp '+data.text1+', ezért nem tudsz tevékenykedni.<br>Hátralévõ idõ: '+c;
                else if(this.id == 'ikon_drog')
                    ttxt = 'Még '+c+'ig állsz a '+data.text1+' hatása alatt';
                else
                    ttxt = 'A következõ '+data.text1+' várnod kell '+c+'et';                
                $("#"+div_id1).countdown({until: now, layout: ttxt});
                if(data.id2) {
                 now = new Date();
                 diff = Math.round((now.getTime() - started) / 1000);
                 sec = parseInt(data.time2) - diff;
                 now.setSeconds(now.getSeconds() + sec);
                 if(sec > 86400) c = "{dn} {dl} {hn} {hl} {mn} {ml}"; else if(sec > 3600) c = "{hn} {hl} {mn} {ml} {sn} {sl}"; else c = "{mn} {ml} {sn} {sl}";
                 $("#"+div_id2).countdown({until: now, layout: 'A következõ '+data.text2+' várnod kell '+c+'et'});
                }

我用这个,但是不起作用:

<img class="tooltip_countdown" src="../img/wait.png" title="{ "id1":"John", "time1":"0" }">
我不了解它是如何工作的,所以请给我帮助以找出如何称呼此功能

0 个答案:

没有答案