BOM对象--类似页面左右两侧的广告

来源:互联网 发布:freertos源码详解 编辑:程序博客网 时间:2024/05/16 19:04

html代码:

<div id = "div1">

<img src="">

<span>&times;</span>//X号

</div>

style代码://设置div的位置,X号的样式

#div1{    display: none;    float: left;    position: fixed;    margin-top: 200px;    cursor:pointer;}
 #div1 img{    /*display: none;*/    width: 150px;    height:300px;    float: left;    background-color: #0F1F0F;}
span{    width: 12px;    height: 12px;    background-color: #ccc;    cursor: default;}
js代码:

  <script>        window.onload = function(){            var div1 = document.getElementById('div1');            var span1 = document.getElementById('span1');            var div2 = document.getElementById('div2');            var span2 = document.getElementById('span2');            setTimeout(function(){                div1.style.display = 'block';                div2.style.display = 'block';            },2000);            span1.onclick = function(){                div1.style.display = 'none';            }}</script>
主要是用了setTimeout():让广告在2秒后出现。
position:fixed:将广告固定在页面上。

0 0
原创粉丝点击