zoukankan      html  css  js  c++  java
  • 图片无缝无间隙滚动代码 DIV+script

    1. 先了解一下对象的几个的属性:
    2. innerHTML:设置或获取位于对象起始和结束标签内的 HTML
    3. scrollHeight: 获取对象的滚动高度。
    4. scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
    5. scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
    6. scrollWidth:获取对象的滚动宽度
    7. offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度
    8. offsetLeft:获取对象相对于版面或由 offsetParent 属性指定的父坐标的计算左侧位置
    9. offsetTop:获取对象相对于版面或由 offsetTop 属性指定的父坐标的计算顶端位置
    10. offsetWidth:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的宽度
    11. 图片上无缝滚动
    12. <style type="text/css">
    13. <!--
    14. #demo {
    15. background: #FFF;
    16. overflow:hidden;
    17. border: 1px dashed #CCC;
    18. height: 100px;
    19. text-align: center;
    20. float: left;
    21. }
    22. #demo img {
    23. border: 3px solid #F2F2F2;
    24. display: block;
    25. }
    26. -->
    27. </style>
    28. 向上滚动
    29. <div id="demo">
    30. <div id="demo1">
    31. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    32. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    33. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    34. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    35. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    36. </div>
    37. <div id="demo2"></div>
    38. </div>
    39. <script>
    40. <!--
    41. var speed=10; //数字越大速度越慢
    42. var tab=document.getElementById("demo");
    43. var tab1=document.getElementById("demo1");
    44. var tab2=document.getElementById("demo2");
    45. tab2.innerHTML=tab1.innerHTML; //克隆demo1为demo2
    46. function Marquee(){
    47. if(tab2.offsetTop-tab.scrollTop<=0)//当滚动至demo1与 demo2交界时
    48. tab.scrollTop-=tab1.offsetHeight //demo跳到最顶端
    49. else{
    50. tab.scrollTop++
    51. }
    52. }
    53. var MyMar=setInterval(Marquee,speed);
    54. tab.onmouseover=function() {clearInterval(MyMar)};//鼠标移上时清除定时器达到滚动停止的目的
    55. tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};//鼠标移开时重设定时器
    56. -->
    57. </script>
    58. 图片下无缝滚动
    59. <style type="text/css">
    60. <!--
    61. #demo {
    62. background: #FFF;
    63. overflow:hidden;
    64. border: 1px dashed #CCC;
    65. height: 100px;
    66. text-align: center;
    67. float: left;
    68. }
    69. #demo img {
    70. border: 3px solid #F2F2F2;
    71. display: block;
    72. }
    73. -->
    74. </style>
    75. 向下滚动
    76. <div id="demo">
    77. <div id="demo1">
    78. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    79. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    80. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    81. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    82. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    83. </div>
    84. <div id="demo2"></div>
    85. </div>
    86. <script>
    87. <!--
    88. var speed=10; //数字越大速度越慢
    89. var tab=document.getElementById("demo");
    90. var tab1=document.getElementById("demo1");
    91. var tab2=document.getElementById("demo2");
    92. tab2.innerHTML=tab1.innerHTML; //克隆demo1为demo2
    93. tab.scrollTop=tab.scrollHeight
    94. function Marquee(){
    95. if(tab1.offsetTop-tab.scrollTop>=0)//当滚动至demo1与 demo2交界时
    96. tab.scrollTop+=tab2.offsetHeight //demo跳到最顶端
    97. else{
    98. tab.scrollTop--
    99. }
    100. }
    101. var MyMar=setInterval(Marquee,speed);
    102. tab.onmouseover=function() {clearInterval(MyMar)};//鼠标移上时清除定时器达到滚动停止的目的
    103. tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};//鼠标移开时重设定时器
    104. -->
    105. </script>
    106. 图片左无缝滚动
    107. <style type="text/css">
    108. <!--
    109. #demo {
    110. background: #FFF;
    111. overflow:hidden;
    112. border: 1px dashed #CCC;
    113. 500px;
    114. }
    115. #demo img {
    116. border: 3px solid #F2F2F2;
    117. }
    118. #indemo {
    119. float: left;
    120. 800%;
    121. }
    122. #demo1 {
    123. float: left;
    124. }
    125. #demo2 {
    126. float: left;
    127. }
    128. -->
    129. </style>
    130. 向左滚动
    131. <div id="demo">
    132. <div id="indemo">
    133. <div id="demo1">
    134. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    135. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    136. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    137. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    138. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    139. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    140. </div>
    141. <div id="demo2"></div>
    142. </div>
    143. </div>
    144. <script>
    145. <!--
    146. var speed=10; //数字越大速度越慢
    147. var tab=document.getElementById("demo");
    148. var tab1=document.getElementById("demo1");
    149. var tab2=document.getElementById("demo2");
    150. tab2.innerHTML=tab1.innerHTML;
    151. function Marquee(){
    152. if(tab2.offsetWidth-tab.scrollLeft<=0)
    153. tab.scrollLeft-=tab1.offsetWidth
    154. else{
    155. tab.scrollLeft++;
    156. }
    157. }
    158. var MyMar=setInterval(Marquee,speed);
    159. tab.onmouseover=function() {clearInterval(MyMar)};
    160. tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};
    161. -->
    162. </script>
    163. 图片右无缝滚动
    164. <style type="text/css">
    165. <!--
    166. #demo {
    167. background: #FFF;
    168. overflow:hidden;
    169. border: 1px dashed #CCC;
    170. 500px;
    171. }
    172. #demo img {
    173. border: 3px solid #F2F2F2;
    174. }
    175. #indemo {
    176. float: left;
    177. 800%;
    178. }
    179. #demo1 {
    180. float: left;
    181. }
    182. #demo2 {
    183. float: left;
    184. }
    185. -->
    186. </style>
    187. 向右滚动
    188. <div id="demo">
    189. <div id="indemo">
    190. <div id="demo1">
    191. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    192. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    193. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    194. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    195. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    196. <a href="#"><img src="http://www.fu80.com/other/link/Clear_logo.gif" border="0" /></a>
    197. </div>
    198. <div id="demo2"></div>
    199. </div>
    200. </div>
    201. <script>
    202. <!--
    203. var speed=10; //数字越大速度越慢
    204. var tab=document.getElementById("demo");
    205. var tab1=document.getElementById("demo1");
    206. var tab2=document.getElementById("demo2");
    207. tab2.innerHTML=tab1.innerHTML;
    208. function Marquee(){
    209. if(tab.scrollLeft<=0)
    210. tab.scrollLeft+=tab2.offsetWidth
    211. else{
    212. tab.scrollLeft--
    213. }
    214. }
    215. var MyMar=setInterval(Marquee,speed);
    216. tab.onmouseover=function() {clearInterval(MyMar)};
    217. tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};
    218. -->
    219. </script>
  • 相关阅读:
    SQL Server创建表
    SQL Server创建数据库
    SQL Server创建索引
    SQL Server创建视图
    SQL Server创建存储过程
    SQL Server创建触发器
    Unity3D与VS2008结合,加快Unity3D C#开发!
    c#哈希表的用法
    长沙做网站公司解密如何编写高效率的SQL语句
    高效SQL语句必杀技
  • 原文地址:https://www.cnblogs.com/buffer/p/1711344.html
Copyright © 2011-2022 走看看