javascript 實現FLASH浮動表徵圖廣告代碼

來源:互聯網
上載者:User

  使用 Javascript 代碼,實現一個可移動的表徵圖在網頁上飄動,滑鼠放在上面的時候,表徵圖不動,移開後,表徵圖又開始移動.

javascript 代碼如下:

<script language='javascript'> 

var xPos = 0;
var yPos = 0; 
var step = 1;
var delay = 10;
var height = 0; 
var Hoffset = 0;
var Woffset = 0; 
var yon = 0;
var xon = 0; 
var xon = 0; 
var interval; 

var img = document.getElementById('img'); 
img.style.top = 0; 

function changePos()
...{ 
    width = document.body.clientWidth; 
    height = document.body.clientHeight; 
    Hoffset = img.offsetHeight; 
    Woffset = img.offsetWidth; 
    img.style.left = xPos + document.body.scrollLeft; 
    img.style.top = yPos + document.body.scrollTop; 
    
    if (yon) ...{ 
        yPos = yPos + step; 

    }else ...{ 
        yPos = yPos - step; 
    } 
    if (yPos < 0) ...{ 
        yon = 1; 
        yPos = 0; 
    } 
    if (yPos >= (height - Hoffset)) ...{ 
        yon = 0; 
        yPos = (height - Hoffset); 
    } 
    if (xon) ...{ 
        xPos = xPos + step; 
    } 
    else ...{ 
        xPos = xPos - step; 
    } 
    if (xPos < 0) ...{ 
        xon = 1; 
        xPos = 0; 
    } 
    if (xPos >= (width - Woffset)) ...{ 
        xon = 0; 
        xPos = (width - Woffset); 
    } 


function start() ...{ 
    img.visibility = 'visible'; 
    interval = setInterval('changePos()', delay); 


function mystop() 
...{ 
    clearInterval(interval) 


start() 
</script>

頁面中,代碼如下:

<!-- FLASH浮動表徵圖廣代碼-->
<span id='img' style='position: absolute;' onmouseover='mystop()' onmouseout='start()'>
    <object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0'
        width='140' height='160'>
        <param name='movie' value='http://www.myhome.com.cn/swf/sample.swf'>
        <param name='quality' value='high'>
        <param name="wmode" value="transparent">
        <!--這裡代碼可使Flash背景透明 -->
        <embed src='http://www.myhome.com.cn/swf/sample.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'
            type='application/x-shockwave-flash' width='306' height='141'> </embed>
    </object>
</span>

  原理:就是調用Macromedia的Flash組件,在Span中運行指定的SWF檔案(<param name='movie' value='http://www.myhome.com.cn/swf/sample.swf'>),Javascript指令碼用於控制Span的運動.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.