首頁 web前端 js教程 JS實作響應滑鼠點選動畫漸層彈出層效果碼_javascript技巧

JS實作響應滑鼠點選動畫漸層彈出層效果碼_javascript技巧

May 16, 2016 pm 03:08 PM
js 回應 彈出層 滑鼠點擊

本文實例講述了JS實現響應滑鼠點擊動畫漸變彈出層效果。分享給大家參考,具體如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>动画弹出层</title>

<style>

.list{

 position:relative;;

 background:#eee;

 border:1px #ccc solid;

 margin:10px;

 height:30px;

 width:100px;

 cursor :pointer ;

}

.listShow{

 position:relative;

 background:#eff;

 border:1px #ddd solid;

 margin:10px;

 height:30px;

 width:100px;

 cursor :pointer ;

}

.comment{

 position:absolute;

 left:0;

 display:none;

 position:absolute;

 border:1px #ccc solid;

 background:#fee;

 width:200px;

 height:200px;

 overflow:hidden;

 z-index:100;

}

</style>

</head>

<body>

<div class="" id="show">

0

</div>

<div class="list" id="list1">1

 <div class="comment" id="comment1">脚本之家<br/>

</div>

<div class="list" id="list2">2

 <div class="comment" id="comment2">新浪搜狐</div>

</div>

<div class="list" id="list3">3

 <div class="comment" id="comment3">网页特效</div>

</div>

</body>

</html>

<script>

 var zindex=0;

 function $id(id){

 return document.getElementById(id);

 }

 var Bind = function(object,fun){

 var args = Array.prototype.slice.call(arguments).slice(2);

 return function(){

  return fun.apply(object,args);

 }

 }

 function addEventHandler(oTarget, sEventType, fnHandler){

  if(oTarget.addEventListener){oTarget.addEventListener(sEventType, fnHandler, false);}

  else if(oTarget.attachEvent){oTarget.attachEvent('on' + sEventType, fnHandler);}

  else{oTarget['on' + sEventType] = fnHandler;}

 }

 var Shower=function(){

 this.list=null;

 this.comment=null;

 this.moveLeft=80;

 this.moveTop=20;

 this.height=150;

 this.width=250;

 this.time=800;

 this.init=function(lisObj,comObj){

  this.list=lisObj;

  this.comment=comObj;

  var _this=this;

  this._fnMove=Bind(this,this.move);

  (function(){

  var obj=_this;

  addEventHandler(obj.list,"click",obj._fnMove);

  })();

 };

 this.move=function(){

  var _this=this;

  var w=0;

  var h=0;

  var height=0; //弹出div的高

  var width=0; //弹出div的宽

  var t=0;

  var startTime = new Date().getTime();//开始执行的时间

  if(!_this.comment.style.display||_this.comment.style.display=="none"){

   _this.comment.style.display="block";

   _this.comment.style.height=0+"px";

   _this.comment.style.width=0+"px";

   _this.list.style.zIndex=++zindex;

   _this.list.className="listShow";

   var comment=_this.comment.innerHTML;

   _this.comment.innerHTML=""; //去掉显示内容

   var timer=setInterval(function(){

   var newTime = new Date().getTime();

   var timestamp = newTime - startTime;

   _this.comment.style.left=Math.ceil(w)+"px";

   _this.comment.style.top=Math.ceil(h)+"px";

   _this.comment.style.height=height+"px";

   _this.comment.style.width=width+"px";

   t++;

  var change=(Math.pow((timestamp/_this.time-1), 3) +1); //根据运行时间得到基础变化量

   w=_this.moveLeft*change;

   h=_this.moveTop*change;

   height=_this.height*change;

   width=_this.width*change;

   $id("show").innerHTML=w;

    if(w>_this.moveLeft){

clearInterval(timer);

_this.comment.style.left=_this.moveLeft+"px";

_this.comment.style.top=_this.moveTop+"px";

_this.comment.style.height=_this.height+"px";

_this.comment.style.width=_this.width+"px";

_this.comment.innerHTML=comment; //回复显示内容

}

},1,_this.comment);

  }else{

   _this.hidden();

  }

}

this.hidden=function(){

 var _this=this;

 var flag=1;

 var hiddenTimer=setInterval(function(){

 if(flag==1){

 _this.comment.style.height=parseInt(_this.comment.style.height)-10+"px";

 }else{    _this.comment.style.width=parseInt(_this.comment.style.width)-15+"px";

 _this.comment.style.left=parseInt(_this.comment.style.left)+5+"px";

 }

 if(flag==1 && parseInt(_this.comment.style.height)<10){

 flag=-flag;

 }

   if(parseInt(_this.comment.style.width)<20){

    clearInterval(hiddenTimer);

    _this.comment.style.left="0px";

    _this.comment.style.top="0px";

    _this.comment.style.height="0px";

    _this.comment.style.width="0px";

    _this.comment.style.display="none";

    if(_this.list.style.zIndex==zindex){

    zindex--;

    };

    _this.list.style.zIndex=0;

    _this.list.className="list";

   }

  },1)

 }

 }

 window.onload=function(){

 //建立各个菜单对象

 var shower1=new Shower();

 shower1.init($id("list1"),$id("comment1"));

 var shower2=new Shower();

 shower2.init($id("list2"),$id("comment2"));

 var shower3=new Shower();

 shower3.init($id("list3"),$id("comment3"));

 }

</script>

登入後複製

更多關於JavaScript相關內容有興趣的讀者可查看本站專題:《JavaScript查找演算法技巧總結》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調試技巧總結》、《JavaScript資料結構與演算法技巧總結》、《JavaScript遍歷演算法與技巧總結》及《Java數學運算用法總結

希望本文所述對大家JavaScript程式設計有所幫助。

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1664
14
CakePHP 教程
1423
52
Laravel 教程
1317
25
PHP教程
1268
29
C# 教程
1248
24
建議:優秀JS開源人臉偵測辨識項目 建議:優秀JS開源人臉偵測辨識項目 Apr 03, 2024 am 11:55 AM

人臉偵測辨識技術已經是一個比較成熟且應用廣泛的技術。而目前最廣泛的網路應用語言非JS莫屬,在Web前端實現人臉偵測辨識相比後端的人臉辨識有優勢也有弱勢。優點包括減少網路互動、即時識別,大大縮短了使用者等待時間,提高了使用者體驗;弱勢是:受到模型大小限制,其中準確率也有限。如何在web端使用js實現人臉偵測呢?為了實現Web端人臉識別,需要熟悉相關的程式語言和技術,如JavaScript、HTML、CSS、WebRTC等。同時也需要掌握相關的電腦視覺和人工智慧技術。值得注意的是,由於Web端的計

股票分析必備工具:學習PHP和JS繪製蠟燭圖的步驟 股票分析必備工具:學習PHP和JS繪製蠟燭圖的步驟 Dec 17, 2023 pm 06:55 PM

股票分析必備工具:學習PHP和JS繪製蠟燭圖的步驟,需要具體程式碼範例隨著網路和科技的快速發展,股票交易已成為許多投資者的重要途徑之一。而股票分析是投資人決策的重要一環,其中蠟燭圖被廣泛應用於技術分析。學習如何使用PHP和JS繪製蠟燭圖將為投資者提供更多直觀的信息,幫助他們更好地做出決策。蠟燭圖是一種以蠟燭形狀來展示股票價格的技術圖表。它展示了股票價格的

如何使用PHP和JS創建股票蠟燭圖 如何使用PHP和JS創建股票蠟燭圖 Dec 17, 2023 am 08:08 AM

如何使用PHP和JS創建股票蠟燭圖股票蠟燭圖是股票市場中常見的技術分析圖形,透過繪製股票的開盤價、收盤價、最高價和最低價等數據,幫助投資者更直觀地了解股票的價格波動情形。本文將教你如何使用PHP和JS創建股票蠟燭圖,並附上具體的程式碼範例。一、準備工作在開始之前,我們需要準備以下環境:1.一台運行PHP的伺服器2.一個支援HTML5和Canvas的瀏覽器3

如何使用JS和百度地圖實現地圖平移功能 如何使用JS和百度地圖實現地圖平移功能 Nov 21, 2023 am 10:00 AM

如何使用JS和百度地圖實現地圖平移功能百度地圖是一款廣泛使用的地圖服務平台,在Web開發中經常用於展示地理資訊、定位等功能。本文將介紹如何使用JS和百度地圖API實作地圖平移功能,並提供具體的程式碼範例。一、準備工作使用百度地圖API前,首先需要在百度地圖開放平台(http://lbsyun.baidu.com/)上申請一個開發者帳號,並建立一個應用程式。創建完成

PPT滑鼠點擊文字出現底線動畫製作方法 PPT滑鼠點擊文字出現底線動畫製作方法 Mar 26, 2024 pm 06:40 PM

1、輸入文字。 2、選擇插入下的形狀,並在其中選擇直線。 3.在愛字下方畫一條直線。 4.選擇直線,再選擇動畫選單,從中選擇一種動畫效果。 5.播放動畫,此時文字下面沒有橫線。 6.點選滑鼠,此時文字下面就出現橫線。

純CSS實現滑鼠點擊水波紋效果的實現步驟 純CSS實現滑鼠點擊水波紋效果的實現步驟 Oct 16, 2023 am 08:57 AM

純CSS實現滑鼠點擊水波紋效果的實現步驟,需要具體程式碼範例滑鼠點擊水波紋效果是Web開發中常見的互動效果之一,它能夠為使用者帶來更生動的體驗。在本文中,我們將分享如何使用純CSS來實現此效果,並提供具體的程式碼範例。實作步驟如下:步驟1:HTML結構首先,在HTML檔案中建立一個具有滑鼠點擊效果的元素。可以使用一個&lt;div&gt;元素作為容器,並設定一

如何使用JS和百度地圖實現地圖點擊事件處理功能 如何使用JS和百度地圖實現地圖點擊事件處理功能 Nov 21, 2023 am 11:11 AM

如何使用JS和百度地圖實現地圖點擊事件處理功能概述:在網路開發中,經常需要使用地圖功能來展示地理位置和地理資訊。而地圖上的點擊事件處理是地圖功能中常用且重要的一環。本文將介紹如何使用JS和百度地圖API來實現地圖的點擊事件處理功能,並給出具體的程式碼範例。步驟:匯入百度地圖的API檔案首先,要在HTML檔案中匯入百度地圖API的文件,可以透過以下程式碼實現:

如何使用JS和百度地圖實現地圖熱力圖功能 如何使用JS和百度地圖實現地圖熱力圖功能 Nov 21, 2023 am 09:33 AM

如何使用JS和百度地圖實現地圖熱力圖功能簡介:隨著互聯網和行動裝置的快速發展,地圖成為了普遍的應用場景。而熱力圖作為一種視覺化的展示方式,能夠幫助我們更直觀地了解數據的分佈。本文將介紹如何使用JS和百度地圖API來實現地圖熱力圖的功能,並提供具體的程式碼範例。準備工作:在開始之前,你需要準備以下事項:一個百度開發者帳號,並建立一個應用,取得到對應的AP

See all articles