課程
/前端開發(fā)
/JavaScript
/JS動(dòng)畫效果
沒(méi)有全部的源碼?跪求源碼
2016-11-02
源自:JS動(dòng)畫效果 2-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);
? ? ? ? ? ? ? ? ? ? ? ? //沒(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/
舉報(bào)
通過(guò)本課程JS動(dòng)畫的學(xué)習(xí),從簡(jiǎn)單動(dòng)畫開始,逐步深入各種動(dòng)畫框架封裝
2 回答sos 課程中的jquery.js 的源碼是什么
1 回答求這節(jié)課的源碼
2 回答這個(gè)課程怎么沒(méi)有源碼下載了?
1 回答這一部分課程有源碼嗎? 想要源碼可見好好研究下。
3 回答請(qǐng)問(wèn)下老師課件源碼哪里下載?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-11-03
<!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/