HTML5网页设计

图片效果

鼠标可控制上下图片滚动代码

时间:2014-11-28 17:35来源:未知作者:点击:
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdhtml xmlns=http://www.w3.org/1999/xhtml xml:lang=enheadmeta http-equiv=Content-Type content=text/html;charset=UTF-8 /title鼠

<!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" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>鼠标可控制上下图片滚动代码</title>
</head>
<body>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title></title>
<style type="text/css">
body,ul,li,h2 {margin:0;padding:0;}
/*产品展示*/
.product {
    display:inline;
    float:left;
    width:255px;
	height:261px;
	margin-left:8px;
	overflow:hidden;
	background:#dddddd;
}
.product h2 {
	height:24px;
	line-height:24px;
	font-size:16px;
	padding-left:30px;
	overflow:hidden;
}
/*产品展示图片滚动*/
.rolltop {
    width:236px;
	height:16px;
	margin:5px auto 0 auto;
	cursor:pointer;
	overflow:hidden;
	color:#666666;
	text-align:center;
    background:#EEEEEE;
}
.rollbottom {
    width:236px;
	height:16px;
	cursor:pointer;
	overflow:hidden;
	margin:0 auto;
	color:#666666;
	text-align:center;
    background:#EEEEEE;
}
#ISL_Cont{
/*    float:left;*/
	width:236px;
	height:194px;
	margin:0 auto;
	overflow:hidden;
	background:#FFFFFF;
	border: 1px solid #BBBBBB;
}
#ISL_Cont .ScrCont{
    width:236px;
	height:1000000px;
}
#ISL_Cont ul {
    float:left;
	width:236px;
}
#ISL_Cont ul li{
	float:left;
	padding:0px;
	width:118px;
	height:96px;
	list-style:none;
}
#ISL_Cont ul li a {
    display:block;
	width:108px;
	height:86px;
    padding:1px;
	margin:6px 0 0 6px;
	background:url(../images/cp_bg.png) no-repeat;
}
#ISL_Cont ul li a img {
    display:block;
	width:83px;
	height:83px;
	margin:0 auto;
	overflow:hidden;
}</style>
<p style="margin-bottom:100px;color:#555555;">
	此资源来自[<a _fcksavedurl="http://www.shejicool.com" href="http://www.shejicool.com" target="_blank">设计酷</a>],更多实用资源请访问<a _fcksavedurl="http://www.shejicool.com" href="http://www.shejicool.com" target="_blank">www.shejicool.com</a></p>
<div class="product">
	<h2>
		鼠标点击控制向上向下</h2>
	<div class="rolltop" onmousedown="ISL_GoDown()" onmouseout="ISL_StopDown()" onmouseup="ISL_StopDown()">
		向上</div>
	<div class="Cont" id="ISL_Cont">
		<div class="ScrCont">
			<ul id="List1">
				<li>
					<a href="#" title="#"><img alt="" height="95" src="http://www.shejicool.com/uploads/allimg/201106/1-110624213944339.jpg" width="100" /></a></li>
				<li>
					<a href="#" title="#"><img alt="" height="95" src="http://www.shejicool.com/uploads/allimg/201106/1-110624213944339.jpg" width="100" /></a></li>
				<li>
					<a href="#" title="#"><img alt="" height="95" src="http://www.shejicool.com/uploads/allimg/201106/1-110624212553422.jpg" width="100" /></a></li>
				<li>
					<a href="#" title="#"><img alt="" height="95" src="http://www.shejicool.com/uploads/allimg/201106/1-110624212553422.jpg" width="100" /></a></li>
			</ul>
			<ul id="List2">
			</ul>
		</div>
	</div>
	<div class="rollbottom" onmousedown="ISL_GoUp()" onmouseout="ISL_StopUp()" onmouseup="ISL_StopUp()">
		向下</div>
</div>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
//图片滚动列表 mengjia 070816
var Speed = 1; //速度(毫秒)
var Space = 3; //每次移动(px)
var PageHeight = 96; //翻页宽度
var fill = 0; //整体移位
var MoveLock = false;
var MoveTimeObj;
var Comp = 0;
var AutoPlayObj = null;
GetObj("List2").innerHTML = GetObj("List1").innerHTML;
GetObj('ISL_Cont').scrollTop = fill;
GetObj("ISL_Cont").onmouseover = function(){clearInterval(AutoPlayObj);}
GetObj("ISL_Cont").onmouseout = function(){AutoPlay();}
AutoPlay();
function GetObj(objName){if(document.getElementById){return eval('document.getElementById("'+objName+'")')}else{return eval('document.all.'+objName)}}
function AutoPlay(){ //自动滚动
 clearInterval(AutoPlayObj);
 AutoPlayObj = setInterval('ISL_GoDown();ISL_StopDown();',5000); //间隔时间
}
function ISL_GoUp(){ //上翻开始
 if(MoveLock) return;
 clearInterval(AutoPlayObj);
 MoveLock = true;
 MoveTimeObj = setInterval('ISL_ScrUp();',Speed);
}
function ISL_StopUp(){ //上翻停止
 clearInterval(MoveTimeObj);
 if(GetObj('ISL_Cont').scrollTop % PageHeight - fill != 0){
  Comp = fill - (GetObj('ISL_Cont').scrollTop % PageHeight);
  CompScr();
 }else{
  MoveLock = false;
 }
 AutoPlay();
}
function ISL_ScrUp(){ //上翻动作
 if(GetObj('ISL_Cont').scrollTop <= 0){GetObj('ISL_Cont').scrollTop = GetObj('ISL_Cont').scrollTop + GetObj('List1').offsetHeight}
 GetObj('ISL_Cont').scrollTop -= Space ;
}
function ISL_GoDown(){ //下翻
 clearInterval(MoveTimeObj);
 if(MoveLock) return;
 clearInterval(AutoPlayObj);
 MoveLock = true;
 ISL_ScrDown();
 MoveTimeObj = setInterval('ISL_ScrDown()',Speed);
}
function ISL_StopDown(){ //下翻停止
 clearInterval(MoveTimeObj);
 if(GetObj('ISL_Cont').scrollTop % PageHeight - fill != 0 ){
  Comp = PageHeight - GetObj('ISL_Cont').scrollTop % PageHeight + fill;
  CompScr();
 }else{
  MoveLock = false;
 }
 AutoPlay();
}
function ISL_ScrDown(){ //下翻动作
 if(GetObj('ISL_Cont').scrollTop >= GetObj('List1').scrollHeight){GetObj('ISL_Cont').scrollTop = GetObj('ISL_Cont').scrollTop - GetObj('List1').scrollHeight;}
 GetObj('ISL_Cont').scrollTop += Space ;
}
function CompScr(){
 var num;
 if(Comp == 0){MoveLock = false;return;}
 if(Comp < 0){ //上翻
  if(Comp < -Space){
   Comp += Space;
   num = Space;
  }else{
   num = -Comp;
   Comp = 0;
  }
  GetObj('ISL_Cont').scrollTop -= num;
  setTimeout('CompScr()',Speed);
 }else{ //下翻
  if(Comp > Space){
   Comp -= Space;
   num = Space;
  }else{
   num = Comp;
   Comp = 0;
  }
  GetObj('ISL_Cont').scrollTop += num;
  setTimeout('CompScr()',Speed);
 }
}
//--><!]]>
</script>
</body>
</html>
阅完本篇文章?您还可以: 收藏本文 文章挑错 朋友推荐