• 吴裕雄--天生自然PHP-MySQL-JavaScript学习笔记:由JavaScript访问CSS


    function C(i)
    {
      return document.getElementsByClassname(i)
    } 
    function S(i)
    {
      return O(i).style
    }
    function O(i)
    {
      return typeof i == 'object' ? i : document.getElementById(i)
    }
    <!DOCTYPE html>
    <html>
      <head>
        <title>Simple Animation</title>
        <script src='OSC.js'></script>
        <style>
          #box {
            position  :absolute;
            background:orange;
            border    :1px solid red;
          }
        </style>
      </head>
      <body>
         <div id='box'></div>
         
         <script>
           SIZE = LEFT = 0
    
           setInterval(animate, 30)
    
           function animate()
           {
             SIZE += 10
             LEFT += 3
    
             if (SIZE == 200) SIZE = 0
             if (LEFT == 600) LEFT = 0
    
             S('box').width  = SIZE + 'px'
             S('box').height = SIZE + 'px'
             S('box').left   = LEFT + 'px'
           }
         </script>
      </body>
    </html>
    <!DOCTYPE html>
    <html>
      <head>
        <title>Using setInterval</title>
        <script src='OSC.js'></script>
      </head>
      <body>
        The time is: <span id='time'>00:00:00</span><br>
    
        <script>
          setInterval("showtime(O('time'))", 1000)
    
          function showtime(object)
          {
            var date = new Date()
            object.innerHTML = date.toTimeString().substr(0,8)
          }
        </script>
      </body>
    </html>
    <!DOCTYPE html>
    <html>
      <head>
        <title>Adding Elements</title>
        <script src='OSC.js'></script>
      </head>
      <body>
        This is a document with only this text in it.<br><br>
    
        <script>
          alert('Click OK to add an element')
    
          newdiv    = document.createElement('div')
          newdiv.id = 'NewDiv'
          document.body.appendChild(newdiv)
    
          S(newdiv).border = 'solid 1px red'
          S(newdiv).width  = '100px'
          S(newdiv).height = '100px'
          newdiv.innerHTML = "I'm a new object inserted in the DOM"
          tmp              = newdiv.offsetTop
    
          alert('Click OK to remove the element')
          pnode = newdiv.parentNode
          pnode.removeChild(newdiv)
          tmp = pnode.offsetTop
        </script>
      </body>
    </html>
    <!DOCTYPE html>
    <html>
      <head>
        <title>Non-inline JavaScript</title>
        <script src='OSC.js'></script>
      </head>
      <body>
        <img id='object' src='apple.png'>
    
        <script>
          O('object').onmouseover = function() { this.src = 'orange.png' }
          O('object').onmouseout  = function() { this.src = 'apple.png'  }
        </script> 
      </body>
    </html>
    <!DOCTYPE html>
    <html>
      <head>
        <title>Inline JavaScript</title>
      </head>
      <body>
        <img src='apple.png'
          onmouseover="this.src='orange.png'"
          onmouseout="this.src='apple.png'"> 
      </body>
    </html>
    <!DOCTYPE html>
    <html>
      <head>
        <title>Accessing CSS Properties</title>
        <script src='OSC.js'></script>
      </head>
      <body>
        <div id='object'>Div Object</div>
    
        <script>
          S('object').border     = 'solid 1px red'
          S('object').width      = '100px'
          S('object').height     = '100px'
          S('object').background = '#eee'
          S('object').color      = 'blue'
          S('object').fontSize   = '15pt'
          S('object').fontFamily = 'Helvetica'
          S('object').fontStyle  = 'italic'
        </script> 
      </body>
    </html>
    function O(i) { return typeof i == 'object' ? i : document.getElementById(i) }
    function S(i) { return O(i).style                                            }
    function C(i) { return document.getElementsByClassName(i)                    }
    function O(i) { return typeof i == 'object' ? i : document.getElementById(i) }
    function S(i) { return O(i).style                                            }
    function C(i) { return document.getElementsByClassname(i)                    }
  • 相关阅读:
    Android自定义Dialog
    Ubuntu中好用的中文输入法
    Android_去掉EditText控件周围橙色高亮区域
    Android中Bitmap,byte[],Drawable相互转化
    准备期末考试 博客不更了
    NYOJ5 Binary String Matching ——KMP
    hdu1420 Prepared for New Acmer ——快速幂
    点头1010 只包含因子2 3 5的数
    Constructing Roads ——最小生成树
    hdu1257 最少拦截系统 ——DP么?
  • 原文地址:https://www.cnblogs.com/tszr/p/12382944.html
Copyright © 2020-2023  润新知