第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

正在回答

1 回答

<!DOCTYPE html>

<html>


<head>

? ? <meta charset="UTF-8">

? ? <title>Document</title>

? ? <style type="text/css">

? ? ? ? * {

? ? ? ? ? ? margin: 0;

? ? ? ? ? ? padding: 0;

? ? ? ? ? ? font-size: 12px;

? ? ? ? }

? ? ? ??

? ? ? ? div {

? ? ? ? ? ? width: 200px;

? ? ? ? ? ? height: 200px;

? ? ? ? ? ? background: green;

? ? ? ? ? ? position: relative;

? ? ? ? ? ? left: -200px;

? ? ? ? }

? ? ? ??

? ? ? ? span {

? ? ? ? ? ? width: 30px;

? ? ? ? ? ? height: 30px;

? ? ? ? ? ? line-height: 30px;

? ? ? ? ? ? background: red;

? ? ? ? ? ? position: absolute;

? ? ? ? ? ? left: 200px;

? ? ? ? ? ? top: 85px;

? ? ? ? ? ? text-align: center;

? ? ? ? ? ? cursor: pointer;

? ? ? ? }

? ? </style>

</head>


<body>

? ? <div id="div">

? ? ? ? <span id="show">show</span>

? ? </div>


? ? <script>

? ? ? ? function $(id) {

? ? ? ? ? ? return typeof id === "string" ? document.getElementById(id) : id;

? ? ? ? }


? ? ? ? window.onload = function() {


? ? ? ? ? ? //定義變量

? ? ? ? ? ? var pto = $("div");

? ? ? ? ? ? var btn = $("show");

? ? ? ? ? ? var timer = null;

? ? ? ? ? ? var speed = 0;


? ? ? ? ? ? //鼠標(biāo)移動(dòng)綁定事件(一個(gè)無(wú)名函數(shù))

? ? ? ? ? ? btn.onmouseenter = function() {

? ? ? ? ? ? ? ? //調(diào)用自定義函數(shù),傳入?yún)?shù)0為pto.offsetLeft需要達(dá)到的距離

? ? ? ? ? ? ? ? showPto(0);

? ? ? ? ? ? }

? ? ? ? ? ? //同理

? ? ? ? ? ? btn.onmouseleave = function() {

? ? ? ? ? ? ? ? //同理

? ? ? ? ? ? ? ? showPto(-200);

? ? ? ? ? ? }


? ? ? ? ? ? //自定義函數(shù),one為自定義參數(shù)

? ? ? ? ? ? function showPto(one) {

? ? ? ? ? ? ? ? //當(dāng)前只需要一個(gè)定時(shí)器,所以需要在每次開始前清除定時(shí)器

? ? ? ? ? ? ? ? clearInterval(timer);

? ? ? ? ? ? ? ? //定義一個(gè)名為timer的定時(shí)器

? ? ? ? ? ? ? ? timer = setInterval(function() {

? ? ? ? ? ? ? ? ? ? if (one > pto.offsetLeft) {

? ? ? ? ? ? ? ? ? ? ? ? //當(dāng)0>pto.offsetLet時(shí),pto需要被顯示,所以speed為正值

? ? ? ? ? ? ? ? ? ? ? ? speed = 10;

? ? ? ? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? ? ? ? //同理,需要被隱藏時(shí),speed為負(fù)值

? ? ? ? ? ? ? ? ? ? ? ? speed = -10;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? if (pto.offsetLeft == one) {

? ? ? ? ? ? ? ? ? ? ? ? //當(dāng)pto的值達(dá)到0或者-200時(shí)候就達(dá)到需求了,需要停止定時(shí)器,

? ? ? ? ? ? ? ? ? ? ? ? clearInterval(timer);

? ? ? ? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? ? ? ? //沒(méi)有到0或者-200時(shí)候,就需要通過(guò)speed來(lái)自增或自減

? ? ? ? ? ? ? ? ? ? ? ? pto.style.left = pto.offsetLeft + speed + 'px';

? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? }, 30);

? ? ? ? ? ? }

? ? ? ? }

? ? </script>

</body>


</html>

更多課程代碼,可以去我的博客:http://www.cnblogs.com/WhiteM/

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
JS動(dòng)畫效果
  • 參與學(xué)習(xí)       113920    人
  • 解答問(wèn)題       1489    個(gè)

通過(guò)本課程JS動(dòng)畫的學(xué)習(xí),從簡(jiǎn)單動(dòng)畫開始,逐步深入各種動(dòng)畫框架封裝

進(jìn)入課程

本次課程的源碼

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)