CSS expression VS Script event

來源:互聯網
上載者:User

國慶來了,手機加油站(http://www.sjjyz.com)的首頁也想帶給訪問客人一點喜悅的感覺,於是美工做了兩個flash分別放在網頁的兩邊空白的地方,同時想讓它們隨頁面滾動而滾動,有浮動的感覺。
在實現滾動的效果時,我開始按習慣用了js的事件body onscroll來做。但做好後發現在滾動時兩個flash有點卡卡的感覺,像抽筋一樣,給人感覺很不好,我就嘗試著用css 的expression來實現效果,發現結果要好得多,抽筋的感覺一點也沒有了。

代碼如下:

        <style> 
            #flashRight {}{ POSITION: absolute; TOP: expression(lockTop());    LEFT:expression(lockLeft(false)); } 
            #flashLeft {}{ POSITION: absolute; TOP: expression(lockTop());    LEFT:expression(lockLeft(true)); } 
        </style> 

 

        <script language="javascript"> 
        function lockTop() 
        { 
            var _body=document.body; 
            return _body.scrollTop; 
        }
        function lockLeft(left)
        {
            if(left)
            {
                return    (screen.availWidth - 777)/2 - 134;
            }
            else
            {
                return    (screen.availWidth - 777)/2 + 770;        
            }
        }
        </script> 

 可以看到代碼也變得很簡單

        <div id="flashRight">
            
         </div>
         <div id="flashLeft">
            
        </div>

具體效果可以到http://www.sjjyz.com上去看,這兩天會把這個改動拿上去。

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.