materialize+jquery实现秒表计数器报警效果代码
代码语言:html
所属分类:布局界面
代码描述:materialize+jquery实现秒表计数器报警效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" class="stopwatch-mode"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1"> <meta name="mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes" /> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/materialize.css"> <style> *{ margin:0; padding:0; box-sizing: border-box; } html{ text-align: center; background-color:#EFEFEF; -webkit-touch-callout: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; } .wrapper{ width: 100vw; min-height: 100vh; overflow-x: hidden; } .app { width: 300vw; transition: 0.4s; } /*----------------------- Modes -----------------------*/ .switch-clocks{ transition:background-color 0.4s; cursor:default; } html.alarm-mode .switch-clocks{ background-color: #E91E63; } html.alarm-mode header .alarm, html.stopwatch-mode header .stopwatch, html.timer-mode header .timer{ background-color:rgba(255,255,255,0.2); pointer-events:none; } html.stopwatch-mode .switch-clocks{ background-color: #607D8B; } html.timer-mode .switch-clocks{ background-color: #00ACC1; } .switch-clocks a{ color:#fff; padding:30px 40px; } html.alarm-mode .app{ transform: translate(0); -webkit-transform: translate(0); } html.stopwatch-mode .app{ transform: translate(-100vw); -webkit-transform: translate(-100vw); } html.timer-mode .app{ transform: translate(-200vw); -webkit-transform: translate(-200vw); } /*----------------------- Clocks General -----------------------*/ .container { position: relative; float: left; width: 100vw; max-width: none; /* canceling auto styles from materialize.css */ } form{ width: 100%; height: 85px; padding: 10px; margin: 50px auto; color: #0277BD; border-radius: 2px; } form a{ margin: 0 5px; } .control{ display: inline-block; width: 130px; vertical-align: middle; } .input-field{ display: inline-block; padding-right: 20px; } .checkbox{ padding-left: 20px; } .clock { position: relative; height: 300px; max-width: 700px; width: 100%; display: block; margin: 50px auto; font-size: 150px; color: #0277BD; text-align: center; line-height: 300px; background-color: #fff; border-radius: 2px; transition: all 0.4s ease-in, box-shadow 0.2s; } .clock.inactive { color: #9e9e9e; } .clock .overlay{ position: absolute; top:0; left:0; width: 100%; height: 100%; } .switch label .lever:after{ background-color:#fff; } /*----------------------- Alarm -----------------------*/ #alarm-input { font-size: 26px; text-align: center; } .switch{ display: inline-block; } /*----------------------- Stopwatch -----------------------*/ .stopwatch form { padding: 0; line-height: 85px; } .stopwatch form a{ color: #0059bc; margin-bottom: 0; } .stopwatch .clock{ max-width: 800px; } /*----------------------- Timer -----------------------*/ #timer-input { font-size: 32px; text-align: center; } .timer-btn{ font-size: 32px; cursor: pointer; } /*----------------------- Modals -----------------------*/ .modal{ width: 40%; } .dismiss-alarm-sounds{ float:none !important; } /*----------------------- Responsiveness -----------------------*/ @media (max-width: 800px){ .switch-clocks a{ padding: 20px; } form{ height: auto; padding: 10px; margin: 10px auto; } .checkbox{ padding-left: 0; display: none; } .clock{ font-size: 60px; height: 180px; line-height: 180px; margin-top:20px; } .stopwatch form a{ padding: 0 1rem; } .modal{ width: 80%; } } </style> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/jquery.timepicker.css"> </head> <body> <div class="wrapper"> <header class="switch-clocks z-depth-1"> <a class="alarm waves-effect">报警</a> <a class="stopwatch waves-effect">秒表</a> <a class="timer waves-effect">计时器</a> </header> <div class="app"> <div class="container alarm hidden"> <form> <div class="control input-field"> <input id="alarm-input" type="text" class="validate"> <label for="alarm-input">设置时间</label> </div> <div class="control switch"> <label> 关闭 <input type="checkbox" disabled id="alarm-btn"> <span class="lever"></span> 开启 </label> </div> <div class="control checkbox"> <input type="checkbox" id="alarm-sounds" /> <label for="alarm-sounds">声音</label> </div> </form> <div class="clock z-depth-1 inactive"> <span>取消设置</span> <div class="overlay waves-effect"></div> </div> </div> <div class="container stopwatch"> <form> <a id="stopwatch-btn-start" class="waves-effect waves-teal btn-flat">开始</a> <a id="stopwatch-btn-pause" class="waves-effect waves-teal btn-flat">暂停</a> <a id="stopwatch-btn-reset" class="waves-effect waves-teal btn-flat">重置</a> </form> <div class="clock inactive z-depth-1"> <span>0:00:00.0</span> <div class="overlay waves-effect"></div> </div> </div> <div class="container timer hidden"> <form> <div class="control input-field"> <input id="timer-input" type="number"> <label for="timer-input">分钟</label> </div> <a class="timer-btn start waves-effect"><i class="mdi-av-play-arrow"></i></a> <a class="timer-btn pause waves-effect"><i class="mdi-av-pause"></i></a> <a class="timer-btn reset waves-effect"><i class="mdi-av-replay"></i></a> <div class="control checkbox"> <input type="checkbox" id="timer-sounds" /> <label for="timer-sounds">声音</label> </div> </form> <div class="clock inactive z-depth-1 waves-effect">0:00</div> </div> </div> <div id="times-up-modal" class="modal"> <div class="modal-content"> <h3>时间到了!</h3> </div> <div class="modal-footer"> <a href="#!" class="dismiss-alarm-sounds modal-action waves-effect waves-red btn-flat">关闭闹钟</a> </div> </div> </div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-1.8.3.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/materialize.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery.timepicker.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/hammer.min.js"></script> <script > // Frontend navigation $(function () { var modeButtons = $('.switch-clocks a'), html = $('html'); // Changing the different clock modes using the buttons. modeButtons.on('click', function (e) { var that = $(e.target); // Making the according button accented. modeButtons.removeClass('accent-4'); that.addClass('accent-4'); // By adding classes to the html we manipulate which clock is shown through CSS. if(that.hasClass('alarm')){ html.removeClass(); html.addClass('alarm-mode'); } if(that.hasClass('stopwatch')){ html.removeClass(); html.addClass('stopwatch-mode'); } if(that.hasClass('timer')){ html.removeClass(); html.addClass('timer-mode'); } }); // Touch events // Change modes by swiping left and right with the help of Hammer.js. var myElement = document.querySelector(".wrapper"); var mc = new Hammer(myElement); mc.on("panright", function() { if(html.hasClass('stopwatch-mode')){ html.removeClass(); html.addClass('alarm-mode'); modeButtons.removeClass('accent-4'); modeButtons.filter('.alarm').addClass('accent-4'); mc.stop(); } else if(html.hasClass('timer-mode')){ html.removeClass(); html.addClass('stopwatch-mode'); modeButtons.removeClass('accent-4'); modeButtons.filter('.stopwatch').addClass('accent-4'); mc.stop(); } }); mc.on("panleft", function() { if(html.hasClass('stopwatch-mode')){ html.removeClass(); html.addClass('timer-mode'); modeButtons.removeClass('accent-4'); modeButtons.filter('.timer').addClass('accent-4'); mc.stop(); } else if(html.hasClass('alarm-mode')){ html.removeClass(); html.addClass('stopwatch-mode'); modeButtons.removeClass('accent-4'); modeButtons.filter('.stopwatch').addClass('accent-4'); mc.stop(); } }); // A hover effect on the clocks. var clock = $('.clock'); clock.on('mouseenter', function (e) { $(this).addClass('z-depth-3'); }); clock.on('mouseleave', function (e) { $(this).removeClass('z-depth-3'); }); // Prevent page refresh on enter press in the input fields. $('input').keydown(function(event){ if(event.keyCode == 13) { event.preventDefault(); return false; } }); }); </script> <script > // Alarm sound var alarmSound = new Audio('assets/06_Urban_Beat.mp3'); alarmSound.volume = 0.3; var alarmInterval = 0, // Our setInterval variable for controlling the loop. alarmTime = 0; // The time the alarm is set to. var alarmClock = $('.container.alarm').find('.clock'), alarmInput = $('#alarm-input.........完整代码请登录后点击上方下载按钮下载查看
网友评论0