Home  >  Article  >  Web Front-end  >  Javascript implements code sharing to control image playback

Javascript implements code sharing to control image playback

巴扎黑
巴扎黑Original
2017-09-06 10:21:131250browse

一般实现用鼠标控制图片的滚动效果都比较麻烦,大段大段的代码让新手头疼无从下手,下面我来写个简单的javascript控制图片滚动的效果。代码简洁明了,兼容ie、firefox和google浏览器。

分享代码如下:

<!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" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>javascript控制图片或p层的上下移动滚动效果</title>
</head>

<body>

<a href="javascript: void(0);" onmouseover="ScrollpUp_T=setInterval(ScrollpUp,10);" onmouseout="clearInterval(ScrollpUp_T)">上</a>
<p id="items" style="margin:5px 0px 5px 0px;width:100px;height:200px;border:1px solid #dddddd;overflow:hidden">
  图片1...<br />
  图片2...<br />
  图片3...<br />
  图片4...<br />
  图片5...<br />
  图片6...<br />
  图片7...<br />
  图片8...<br />
  图片9...<br />
  图片10...<br />
  图片11...<br />
  图片12...<br />
  图片13...<br />
  图片14...<br />
  图片15...<br />
  图片16...<br />
  图片17...<br />
  图片18...<br />
  图片19...<br />
  图片20...
</p>
<a href="javascript: void(0);" onmouseover="ScrollpDown_T=setInterval(ScrollpDown,10);" onmouseout="clearInterval(ScrollpDown_T)">下</a>
<script language="javascript">
  function ScrollpUp(){document.getElementById("items").scrollTop -= 1;}
  function ScrollpDown(){document.getElementById("items").scrollTop += 1;}
</script>

</body>

</html>

运行效果图:

The above is the detailed content of Javascript implements code sharing to control image playback. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn