js如何实现滑动导航效果


当前第2页 返回上一页

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

<!doctype html>

<html>

<head>

 <meta charset="UTF-8">

 <meta name="viewport"

   content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

 <meta http-equiv="X-UA-Compatible" content="ie=edge">

 <title>Document</title>

 <style>

  * {

   padding: 0;

   margin: 0;

  }

  ul {

   list-style-type: none;

   height: 42px;

   position: absolute;

  }

  img {

   vertical-align: middle;

  }

  li,

  a {

   cursor: pointer;

  }

  a {

   text-decoration: none;

   color: #000000;

   display: block;

  }

  li {

   width: 83px;

   height: 42px;

   /*background-color: pink;*/

   float: left;

   text-align: center;

   line-height: 42px;

  }

  .box {

   position: relative;

   width: 530px;

   height: 42px;

   border: 1px solid deepskyblue;

   margin: 100px auto;

   -webkit-border-radius: 10px;

   -moz-border-radius: 10px;

   border-radius: 10px;

  }

  .box img#cloud {

   width: 83px;

   height: 42px;

   position: absolute;

   left: 0;

   top: 0;

  }

  .box img#xinhao {

   position: absolute;

   right: 0;

   top: 50%;

   transform: translateY(-50%);

  }

 </style>

</head>

<body>

<div id="box">

 <img id="cloud" src="images/cloud.gif" alt="" />

 <ul id="ull">

  <li><a href="#">长沙校区</a></li>

  <li><a href="#">长沙校区</a></li>

  <li><a href="#">长沙校区</a></li>

  <li><a href="#">长沙校区</a></li>

  <li><a href="#">长沙校区</a></li>

  <li><a href="#">长沙校区</a></li>

 </ul>

 <img id="xinhao" src="images/rss.png" alt="" />

</div>

<script src="js/common.js"></script>

<script src="js/changespead.js"></script>

<script>

 //获取每一个li

 var list=my$('ull').children;

 console.log(list);

 //获取到筋斗云图片

 var im=my$('cloud');

 //获取图片的宽度

 var imgWidth=im.offsetWidth;

 console.log(imgWidth);

 for(var i=0;i<list.length;i++){

  //设置index值用来储存移动的距离

  list[i].setAttribute('index',i);

  //遍历所有li,每个li绑定三个时间指向同一个函数f1

  list[i].onmouseover=f1;

  list[i].onmouseout=f1;

  list[i].onclick=f1;

  //实现函数f1

  function f1(e){

   switch(e.type) {

    case 'mouseover':

     //获取当前li的index值

     index=this.getAttribute('index');

     //调用变速移动函数

     movecs(im,imgWidth*index);

     break;

    case 'click':

     index=this.getAttribute('index');

     //点击之后固定

     im.style.left=imgWidth*index+'px';

     //点击了其中一个li之后的操作,移开鼠标之后不会弹回去

     this.onmouseout=false;

     for(var k=0;k<list.length;k++){

      list[k].setAttribute('jndex',k);

 

      list[k].onmouseover=function(){

       jndex=this.getAttribute('jndex');

       movecs(im,imgWidth*jndex);

      };

      list[k].onmouseout=function(){

       movecs(im,imgWidth*index);

      };

     }

     break;

    case 'mouseout':

 

     index=0;

     movecs(im,imgWidth*index);

     break;

   }

  }

 }

 

 

 

 /*list[i].onmouseover=function(){

   index=this.getAttribute('index');

   console.log(index);

   movecs(im,imgWidth*index);

  };

  list[i].onmouseout=function(){

   index=0;

   // im.style.left='0px';

   movecs(im,imgWidth*index);

  };

 

  list[i].onclick=function(){

   index=this.getAttribute('index');

   im.style.left=imgWidth*index+'px';

   alert(index);

  };*/

</script>

</body>

</html>

更多炫酷CSS3、html5、javascript特效代码,尽在:js特效大全

以上就是js如何实现滑动导航效果的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

h5和js有什么区别

如何用js统计字符串中每个字符出现的次数?

html如何引入js文件

js底层是什么语言

vue 轻量级图表组件

js变量的基本使用方法介绍

变量必须以什么开头javascript

原生js封装ajax方法

示例js 数组和对象的深拷贝操作

js中的typeof和instanceof和===的区别

更多相关阅读请进入《js》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...