限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

javascript基于SVG创建的复古的摇摆时钟特效代码

所属分类: 网页特效-日期时间    2024-01-13 11:28:11

javascript基于SVG创建的复古的摇摆时钟特效代码 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

javascript基于SVG创建的复古的摇摆时钟特效代码(共3个文件)

    • index.html

使用方法

/**[minimum JS only to set current time and sound the chimes]**/
(function() {
	'use strict';
	let	seconds = document.getElementById('second_time'),
			munutes = document.getElementById('minute_time'),
			hours = document.getElementById('hour_time'),
		 	s, m, h, S, M, H, time;
	
	/*[set the clock to correct time and let CSS handle the rest]*/
	function windup () {
		time = new Date(),
		s = time.getSeconds(),
		m = time.getMinutes(),
		h = time.getHours(),
		S = s * 6,
		M = m * 6 + s / 10,
		H = h * 30 + 0.5 * m;

		seconds.style.transform = 'rotate(' + S + 'deg)';
		munutes.style.transform = 'rotate(' + M + 'deg)';
		hours.style.transform = 'rotate(' + H + 'deg)';
		
		console.log('windup: ' + h + ':' + m + ':' + s);
		tick.volume = chime.volume = 1;
	}
	setTimeout(windup, 0);
	
	/*[main visibility API function]*/
	// use visibility API to check if current tab is active or not
	let vis = (function(){
		 let stateKey, 
			  eventKey, 
			  keys = {
						 hidden: 'visibilitychange',
						 webkitHidden: 'webkitvisibilitychange',
						 mozHidden: 'mozvisibilitychange',
						 msHidden: 'msvisibilitychange'
		 };
		 for (stateKey in keys) {
			  if (stateKey in document) {
					eventKey = keys[stateKey];
					break;
			  }
		 }
		 return function(c) {
			  if (c) document.addEventListener(eventKey, c);
			  return !document[stateKey];
		 }
	})();
	
	/*[HTML5 Visibility API]****************************************/
	// check if current tab is active or not
	vis( function () {
		if (vis()) {	
		setTimeout( function () {
					// tween resume() code goes here
					windup();
					console.log('tab is visible - has focus');
			  }, 300);		
		 } else {
			  // tween pause() code goes here
			  console.log('tab is invisible - has blur');
			 tick.volume = chime.volume = 0.1;
		 }
	});
	
	// check if browser window has focus		
	let notIE = (document.documentMode === undefined),
		 isChromium = window.chrome;
	if (notIE && !isChromium) {
		 // checks for Firefox and other  NON IE Chrome versions
		 $(window).on('focusin', function () { 
			  // tween resume() code goes here
			  setTimeout( function () {  
					windup();
					console.log('focus');
			  }, 300);
		 }).on('focusout', function () {
			  // tween pause() code goes here
			  console.log('blur');
			 tick.volume = chime.volume = 0.1;
		 });
	} else {
		 // checks for IE and Chromium versions
		 if (window.addEventListener) {
			  // bind focus event
			  window.addEventListener('focus', function (event) {
					// tween resume() code goes here
					setTimeout( function () {
						windup();
						console.log('focus');
					},300);
			  }, false);
			  // bind blur event
			  window.addEventListener('blur', function (event) {
					// tween pause() code goes here
					 console.log('blur');
				  tick.volume = chime.volume = 0.1;
			  }, false);
		 } else {
			  // bind focus event
			  window.attachEvent('focus', function (event) {
					// tween resume() code goes here
					setTimeout( function () {
						windup();
						console.log('focus');
					},300);
			  });
			  // bind focus event
			  window.attachEvent('blur', function (event) {
					// tween pause() code goes here
					console.log('blur');
				   tick.volume = chime.volume = 0.1;
			  });
		 }
	}
	/*[end HTML5 Visibility API]************************************/
	
	/*[hourly and quarterly chimes]*/
	const tick = document.getElementById('tick');
	const chime = document.getElementById('chime');
	const sound_dir = 'http://www.gerasimenko.com/sandbox/codepen/sounds/';

	let bell, tock = 'tock.wav';

	tick.src = sound_dir + tock;

	function hourly_chime(n) {
		console.log('plays left: ' + n);
		if (n === 0) {
			return;
		} else {
			chime.pause();
			chime.currentTime = 0;
			chime.play();
			n--;
			setTimeout( function () {
				hourly_chime(n);
			}, 3000);
		}
	}

	setInterval( function () {
		time = new Date(),
		s = time.getSeconds(),
		m = time.getMinutes(),
		h = time.getHours();
		
		console.log('watch: ' + h + ':' + m + ':' + s);
		tick.play();

		if (s === 0 && (m === 15 || m === 30 || m === 45)) {
			bell = 'ding-tone.wav';
			chime.src = sound_dir + bell;
			hourly_chime(m / 15);
		} else if (s === 0 && m === 0) {
			bell = 'bell-japanese.wav';
			chime.src = sound_dir + bell;
			h > 12 ? h = h - 12 : h;
			hourly_chime(h);
		}
	}, 1000);
})();

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 日期时间

jquery基于Bootstrap多功能日期选择器插件

一款兼容移动端的日期选择器代码,带多种展示方式:默认显示、弹出层、侧边栏。
  日期时间
 9416  0

jquery自定义的模拟时钟立体特效代码

一款可自定义的数字时钟插件,可在网页上显示当前当前系统时间。
  日期时间
 1439  0

原生js实现的支持自定义分秒倒计时插件

一个分秒倒计时计时器,可输入自定义时间进行倒计时。提供一些默认的时间作为导航菜单,鼠标点击即可开启倒计时。这是一个很棒的时间管理工具,比如在既定的时间后提醒你休息。有实力的大佬,可以增加倒计时结束时,播放声音提醒功能。
  日期时间
 1378  0

jquery自定义时间选择器插件

qcTimepicker是一个时间选择器插件,它可以自动将文本字段转换为具有自定义时间格式的下拉时间picker。可自定义设置最小时间和最大时间,以及step.
  日期时间
 2311  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论