首页 > 编程语言 > 详细

JavaScript 无缝上下左右滚动加定高定宽停顿效果

时间:2014-03-15 12:38:01      阅读:460      评论:0      收藏:0      [点我收藏+]
根据无缝滚动八向滚动修改而来,特点是能同一程序中分别向四个方向移动。
对滚动框内的样式设置有些要求。

效果:
  • 顺德于1993年被批准为广东省综合改革试点。
  • 2006年顺德成为首个GDP超过1000亿的县级行政单位。
  • 2000至2003年顺德均在中国百强县排名中位居榜首。
  • 2005年顺德实现国内生产总值856.11亿元。
  • 顺德于1993年被批准为广东省综合改革试点。
  • 2006年顺德成为首个GDP超过1000亿的县级行政单位。
  • 2000至2003年顺德均在中国百强县排名中位居榜首。
  • 2005年顺德实现国内生产总值856.11亿元。
  • 顺德于1993年被批准为广东省综合改革试点。
  • 2006年顺德成为首个GDP超过1000亿的县级行政单位。
  • 2000至2003年顺德均在中国百强县排名中位居榜首。
  • 2005年顺德实现国内生产总值856.11亿元。
  • 顺德于1993年被批准为广东省综合改革试点。
  • 2006年顺德成为首个GDP超过1000亿的县级行政单位。
  • 2000至2003年顺德均在中国百强县排名中位居榜首。
  • 2005年顺德实现国内生产总值856.11亿元。

代码:
bubuko.com,布布扣<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
bubuko.com,布布扣
<html xmlns="http://www.w3.org/1999/xhtml">
bubuko.com,布布扣
<head>
bubuko.com,布布扣
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
bubuko.com,布布扣
<title>JavaScript 无缝上下左右滚动加定高定宽停顿效果(兼容ie/ff)</title>
bubuko.com,布布扣
</head>
bubuko.com,布布扣
<body>
bubuko.com,布布扣
<script type="text/javascript">
bubuko.com,布布扣
var $ = function (id) {
bubuko.com,布布扣    
return "string" == typeof id ? document.getElementById(id) : id;
bubuko.com,布布扣}
;
bubuko.com,布布扣
bubuko.com,布布扣
var Class = {
bubuko.com,布布扣  create: 
function() {
bubuko.com,布布扣    
return function() {
bubuko.com,布布扣      
this.initialize.apply(this, arguments);
bubuko.com,布布扣    }

bubuko.com,布布扣  }

bubuko.com,布布扣}

bubuko.com,布布扣
bubuko.com,布布扣Object.extend 
= function(destination, source) {
bubuko.com,布布扣    
for (var property in source) {
bubuko.com,布布扣        destination[property] 
= source[property];
bubuko.com,布布扣    }

bubuko.com,布布扣    
return destination;
bubuko.com,布布扣}

bubuko.com,布布扣
bubuko.com,布布扣
function addEventHandler(oTarget, sEventType, fnHandler) {
bubuko.com,布布扣    
if (oTarget.addEventListener) {
bubuko.com,布布扣        oTarget.addEventListener(sEventType, fnHandler, 
false);
bubuko.com,布布扣    }
 else if (oTarget.attachEvent) {
bubuko.com,布布扣        oTarget.attachEvent(
"on" + sEventType, fnHandler);
bubuko.com,布布扣    }
 else {
bubuko.com,布布扣        oTarget[
"on" + sEventType] = fnHandler;
bubuko.com,布布扣    }

bubuko.com,布布扣}
;
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣
var Scroller = Class.create();
bubuko.com,布布扣Scroller.prototype 
= {
bubuko.com,布布扣  initialize: 
function(idScroller, idScrollMid, options) {
bubuko.com,布布扣    
var oThis = this, oScroller = $(idScroller), oScrollMid = $(idScrollMid);
bubuko.com,布布扣    
bubuko.com,布布扣    
this.SetOptions(options);
bubuko.com,布布扣    
this.Side = this.options.Side || ["up"];//方向
bubuko.com,布布扣
    this.scroller = oScroller;            //对象
bubuko.com,布布扣
    this.speed = this.options.Speed;    //速度
bubuko.com,布布扣
    this.timer = null;                    //时间
bubuko.com,布布扣
    this.pauseHeight = 0;                //定高
bubuko.com,布布扣
    this.pauseWidth = 0;                //定宽
bubuko.com,布布扣
    this.pause = 0;                        //定高(宽)
bubuko.com,布布扣
    this.side = 0;                        //参数
bubuko.com,布布扣
    
bubuko.com,布布扣    
//用于上下滚动
bubuko.com,布布扣
    this.heightScroller = parseInt(oScroller.style.height) || oScroller.offsetHeight;
bubuko.com,布布扣    
this.heightList = oScrollMid.offsetHeight;
bubuko.com,布布扣    
bubuko.com,布布扣    
//用于左右滚动
bubuko.com,布布扣
    this.widthScroller = parseInt(oScroller.style.width) || oScroller.offsetWidth;
bubuko.com,布布扣    
this.widthList = oScrollMid.offsetWidth;
bubuko.com,布布扣    
bubuko.com,布布扣    
//js取不到css设置的height和width
bubuko.com,布布扣
    
bubuko.com,布布扣    oScroller.style.overflow 
= "hidden";
bubuko.com,布布扣    oScrollMid.appendChild(oScrollMid.cloneNode(
true));
bubuko.com,布布扣    oScrollMid.appendChild(oScrollMid.cloneNode(
true));
bubuko.com,布布扣    
bubuko.com,布布扣    addEventHandler(oScroller, 
"mouseover"function() { oThis.Stop(); });
bubuko.com,布布扣    addEventHandler(oScroller, 
"mouseout"function() { oThis.Start(); });
bubuko.com,布布扣    
bubuko.com,布布扣    
this.Start();
bubuko.com,布布扣  }
,
bubuko.com,布布扣  
//设置默认属性
bubuko.com,布布扣
  SetOptions: function(options) {
bubuko.com,布布扣    
this.options = {//默认值
bubuko.com,布布扣
      Step:            1,//每次变化的px量
bubuko.com,布布扣
      Speed:        20,//速度(越大越慢)
bubuko.com,布布扣
      Side:            ["up"],//滚动方向:"up"是上,"down"是下,"left"是左,"right"是右
bubuko.com,布布扣
      PauseHeight:    0,//隔多高停一次
bubuko.com,布布扣
      PauseWidth:    0,//隔多宽停一次
bubuko.com,布布扣
      //当上下和左右一起使用时必须设置PauseHeight和PauseWidth来设置转向位置
bubuko.com,布布扣
      PauseStep:    1000//停顿时间(PauseHeight或PauseWidth大于0该参数才有效)
bubuko.com,布布扣
    }
;
bubuko.com,布布扣    Object.extend(
this.options, options || {});
bubuko.com,布布扣  }

bubuko.com,布布扣  
//转向
bubuko.com,布布扣
  Turn: function() {
bubuko.com,布布扣    
//通过设置方向数组的排列来转向
bubuko.com,布布扣
    this.Side.push(this.Side.shift().toLowerCase());
bubuko.com,布布扣  }
,
bubuko.com,布布扣  
//上下滚动
bubuko.com,布布扣
  ScrollUpDown: function() {
bubuko.com,布布扣    
this.pause = this.pauseHeight;
bubuko.com,布布扣    
this.scroller.scrollTop = this.GetScroll(this.scroller.scrollTop, this.heightScroller, this.heightList, this.options.PauseHeight);
bubuko.com,布布扣    
this.pauseHeight = this.pause;
bubuko.com,布布扣    
bubuko.com,布布扣    
var oThis = this;
bubuko.com,布布扣    
this.timer = window.setTimeout(function(){ oThis.Start(); }this.speed);
bubuko.com,布布扣  }
,
bubuko.com,布布扣  
//左右滚动
bubuko.com,布布扣
  ScrollLeftRight: function() {
bubuko.com,布布扣    
this.pause = this.pauseWidth;
bubuko.com,布布扣    
//注意:scrollLeft超过1400会自动变回1400 注意长度
bubuko.com,布布扣
    this.scroller.scrollLeft = this.GetScroll(this.scroller.scrollLeft, this.widthScroller, this.widthList, this.options.PauseWidth);
bubuko.com,布布扣    
this.pauseWidth = this.pause;
bubuko.com,布布扣    
bubuko.com,布布扣    
var oThis = this;
bubuko.com,布布扣    
this.timer = window.setTimeout(function(){ oThis.Start(); }this.speed);
bubuko.com,布布扣  }
,
bubuko.com,布布扣  
//获取设置滚动数据
bubuko.com,布布扣
  GetScroll: function(iScroll, iScroller, iList, iPause) {
bubuko.com,布布扣    
var iStep = this.options.Step * this.side;
bubuko.com,布布扣    
bubuko.com,布布扣    
if(this.side > 0){
bubuko.com,布布扣        
if(iScroll >= (iList * 2 - iScroller)){ iScroll -= iList; }
bubuko.com,布布扣    }
 else {
bubuko.com,布布扣        
if(iScroll <= 0){ iScroll += iList; }
bubuko.com,布布扣    }

bubuko.com,布布扣    
bubuko.com,布布扣    
this.speed = this.options.Speed;
bubuko.com,布布扣    
if(iPause > 0){
bubuko.com,布布扣        
if(Math.abs(this.pause) >= iPause){
bubuko.com,布布扣            
this.speed = this.options.PauseStep; this.pause = iStep = 0this.Turn();
bubuko.com,布布扣        }
 else {
bubuko.com,布布扣            
this.pause += iStep;
bubuko.com,布布扣        }

bubuko.com,布布扣    }

bubuko.com,布布扣    
bubuko.com,布布扣    
return (iScroll + iStep);
bubuko.com,布布扣  }
,
bubuko.com,布布扣  
//开始
bubuko.com,布布扣
  Start: function() {    
bubuko.com,布布扣    
//方向设置
bubuko.com,布布扣
    switch (this.Side[0].toLowerCase()) {
bubuko.com,布布扣        
case "right" :
bubuko.com,布布扣            
if(this.widthList < this.widthScroller) return;
bubuko.com,布布扣            
this.side = -1;
bubuko.com,布布扣            
this.ScrollLeftRight();
bubuko.com,布布扣            
break;
bubuko.com,布布扣        
case "left" :
bubuko.com,布布扣            
if(this.widthList < this.widthScroller) return;
bubuko.com,布布扣            
this.side = 1;
bubuko.com,布布扣            
this.ScrollLeftRight();
bubuko.com,布布扣            
break;
bubuko.com,布布扣        
case "down" :
bubuko.com,布布扣            
if(this.heightList < this.heightScroller) return;
bubuko.com,布布扣            
this.side = -1;
bubuko.com,布布扣            
this.ScrollUpDown();
bubuko.com,布布扣            
break;
bubuko.com,布布扣        
case "up" :
bubuko.com,布布扣        
default :
bubuko.com,布布扣            
if(this.heightList < this.heightScroller) return;
bubuko.com,布布扣            
this.side = 1;
bubuko.com,布布扣            
this.ScrollUpDown();
bubuko.com,布布扣    }

bubuko.com,布布扣  }
,
bubuko.com,布布扣  
//停止
bubuko.com,布布扣
  Stop: function() {
bubuko.com,布布扣    clearTimeout(
this.timer);
bubuko.com,布布扣  }

bubuko.com,布布扣}
;
bubuko.com,布布扣
bubuko.com,布布扣window.onload 
= function(){
bubuko.com,布布扣    
new Scroller("idScroller""idScrollMid",{ Side:["up","left"], PauseHeight:50, PauseWidth:400 });
bubuko.com,布布扣}

bubuko.com,布布扣
</script>
bubuko.com,布布扣
<style>
bubuko.com,布布扣.Scroller 
{line-height:50px; border:1px solid #000000; padding:0px 10px; height:50px; width:400px;}
bubuko.com,布布扣.Scroller *
{margin:0px; padding:0px;}
bubuko.com,布布扣.ScrollMid 
{float:left;}
bubuko.com,布布扣.ScrollMid ul
{width:800px;float:left;}
bubuko.com,布布扣.ScrollMid li
{list-style:none; float:left; width:390px; padding-left:10px;}
bubuko.com,布布扣
</style>
bubuko.com,布布扣
<div id="idScroller" class="Scroller" style="width:400px; height:50px;">
bubuko.com,布布扣  
<div style="width:1600px">
bubuko.com,布布扣    
<div id="idScrollMid" class="ScrollMid">
bubuko.com,布布扣      
<ul>
bubuko.com,布布扣        
<li>111111111111</li>
bubuko.com,布布扣        
<li>2222222222222</li>
bubuko.com,布布扣        
<li>333333333333333</li>
bubuko.com,布布扣        
<li>4444444444444</li>
bubuko.com,布布扣      
</ul>
bubuko.com,布布扣    
</div>
bubuko.com,布布扣  
</div>
bubuko.com,布布扣
</div>
bubuko.com,布布扣
<div id="test"></div>
bubuko.com,布布扣
</body>
bubuko.com,布布扣
</html>
bubuko.com,布布扣

JavaScript 无缝上下左右滚动加定高定宽停顿效果,布布扣,bubuko.com

JavaScript 无缝上下左右滚动加定高定宽停顿效果

原文:http://www.cnblogs.com/emily167/p/3600993.html

(0)
(0)
   
举报
评论 一句话评论(0
分享档案
最新文章
教程昨日排行
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!