字符串反转/定时器弹框/定时器的基本用法/定时器动画

                                         字符串反转

1、split字符串转成数

2、reverse数组反转

3、join数组转成字符串

........................................................................................................................................................

<script type="text/javascript">

var sTr = "123asdf79888asdfe21";

//1、split字符串转成数组

//2、reverse数组反转

//3、join数组转成字符串

var sTr2 = sTr.split('').reverse().join('');

alert(sTr2);//12efdsa88897fdsa321

</script>

........................................................................................................................................

                                      定时器弹框

setTimeout 只执行一次的定时器

clearTimeout 关闭只执行一次的定时器

setInterval 反复执行的定时器

clearInterval 关闭反复执行的定时器

........................................................................................................................................

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>定时器弹框</title>

<style type="text/css">

.pop{

width: 400px;

height: 300px;

background-color: #fff;

border: 1px solid #000;

/*固定定位*/

position: fixed;

/*左上角位于页面中心*/

left: 50%;

top: 50%;

/*让div向左偏移半个宽度、向上偏移半个高度,使div位于页面中心*/

margin-left: -200px;

margin-top: -150px;

/*弹窗在最上面*/

z-index: 9999;

}

/*遮罩样式*/

.mask{

position: fixed;

width: 100%;

height: 100%;

background-color: #000;

left: 0;

top: 0;

/*设置透明度30%*/

opacity: 0.3;

filter: alpha(opacity=30);/*兼容IE6、7、8*/

/*遮罩在弹窗的下面,在网页所有内容的上面*/

z-index: 9990;

}

.pop_con{

display: none;/*默认不显示,用定时器显示*/

}

</style>

<script type="text/javascript">


window.onload = function(){

var oPop = document.getElementById('pop');

var oShut = document.getElementById('shutOff');

/*setTimeout(showPop, 3000);//开启定时器,3秒后调用函数showPop()弹框

function showPop(){

oPop.style.display = 'block';//显示弹框和遮罩

}*/

//开启定时器的简写方式:调用匿名函数

setTimeout(function(){

oPop.style.display = 'block';

}, 3000);

oShut.onclick = function(){

oPop.style.display = 'none';//关闭弹框和遮罩

}

}

</script>

</head>

<body>

<h1>首页标题</h1>

<p>页面内容</p>

<a href="http://www.baidu.com">百度网</a>

<div class="pop_con" id="pop">

<div class="pop">

<h3>提示信息!</h3>

<a href="#" id="shutOff">关闭</a>

</div>

<div class="mask"></div>

</div>

</body>

</html>

..........................................................................................................................................................................

                                                定时器的基本用法

<script type="text/javascript">

//单次定时器

var timer = setTimeout(function(){

alert('hello!');

}, 3000);

//清除单次定时器

clearTimeout(timer);

//反复循环定时器

var timer2 = setInterval(function(){

alert('hi~~~');

}, 2000);

//清除反复循环定时器

clearInterval(timer2);

</script>

..........................................................................................................................................................................

                                                定时器动画

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>定时器动画</title>

<style type="text/css">

.box{

width: 100px;

height: 100px;

background-color: gold;

position: fixed;

left: 20px;

top: 20px;

}

</style>

<script type="text/javascript">

window.onload = function(){

var oBox = document.getElementById('box');

var left = 20;

//反复循环定时器,每30毫秒修改一次盒子的left值

var timer = setInterval(function(){

left += 2;

oBox.style.left = left + 'px';

//当left值大于700时停止动画(清除定时器)

if(left > 700){

clearInterval(timer);

}

},30);

}

</script>

</head>

<body>

<div class="box" id="box"></div>

</body>

</html>

..........................................................................................................................................................................

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 简述JavaScript起源起源于美国的Netscape公司,原名为LiveScript,后改为JavaScrip...
    3ab670b99521阅读 3,108评论 0 0
  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 2,068评论 0 2
  • 工厂模式类似于现实生活中的工厂可以产生大量相似的商品,去做同样的事情,实现同样的效果;这时候需要使用工厂模式。简单...
    舟渔行舟阅读 7,963评论 2 17
  • 第一章 1.什么是DOM DOM: Document Object Model(文档对象模型) 是JavaScri...
    fastwe阅读 847评论 0 0
  • 单例模式 适用场景:可能会在场景中使用到对象,但只有一个实例,加载时并不主动创建,需要时才创建 最常见的单例模式,...
    Obeing阅读 2,142评论 1 10