论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Javascript教程
Tag:验证,特效,入门,实例,验证,表单,特效,正则表达式,跑马灯,document,函数,代码,getElementByID,菜单,图片,视频教程

编写图片切换效果2(基于jquery) 源码

文章类别:Javascript | 发表日期:2010-3-27 12:19:05

21视频教程网3月27日整理

<!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">
<title>杂学</title>
<style type="text/css">
<!--
*{margin:0; padding:0}
li{list-style:none}
img{border:0}
body{background-color:#fff; font-size:12px; color:#2c2c2c; font-family:Arial, Helvetica, sans-serif}
a{color:#444; text-decoration:none}
a:hover{color:#900; text-decoration:underline}
.con{overflow:hidden; margin:30px auto; width:442px; height:100%; padding:10px 15px; border:solid 1px #FCBA79; background-color:#FFFBEC;}
#carousel_container{position:relative; height:100px; overflow:hidden;}
#carousel_inner{width:391px; height:95px; overflow: hidden; position:absolute;left:25px; top:5px;}
#left_scroll{position: absolute;left:0;top:43px;width:9px;height:9px;cursor: pointer;cursor: hand; background:url(http://www.cnblogs.com/images/cnblogs_com/chenjmdg/left.gif) no-repeat;}
#right_scroll{position: absolute;top:43px;right:0; width: 9px;height: 9px;cursor: pointer;cursor: hand; background: url(http://www.cnblogs.com/images/cnblogs_com/chenjmdg/right.gif) no-repeat;}
#carousel_ul{width:9999px; height:95px; position:relative;}
#carousel_ul li{float: left;width:84px; height:86px; border:solid 1px #FEDDAB; margin-right:15px; display:inline;}
-->
</style>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
<!--
var SellerScroll = function(options){
 this.SetOptions(options);
 this.lButton = this.options.lButton;
 this.rButton = this.options.rButton;
 this.oList = this.options.oList;
 this.showSum = this.options.showSum;
 
 this.iList = $("#" + this.options.oList + " > li");
 this.iListSum = this.iList.length;
 this.iListWidth = this.iList.outerWidth(true);
 this.moveWidth = this.iListWidth * this.showSum;
 
 this.dividers = Math.ceil(this.iListSum / this.showSum); //共分为多少块
 this.moveMaxOffset = (this.dividers - 1) * this.moveWidth;
 this.LeftScroll();
 this.RightScroll();
};
SellerScroll.prototype = {
 SetOptions: function(options){
  this.options = {
   lButton: "left_scroll",
   rButton: "right_scroll",
   oList: "carousel_ul",
   showSum: 4 //一次滚动多少个items
  };
  $.extend(this.options, options || {});
 },
 ReturnLeft: function(){
  return isNaN(parseInt($("#" + this.oList).css("left"))) ? 0 : parseInt($("#" + this.oList).css("left"));
 },
 LeftScroll: function(){
  if(this.dividers == 1) return;
  var _this = this, currentOffset;
  $("#" + this.lButton).click(function(){
   currentOffset = _this.ReturnLeft();
   if(currentOffset == 0){
    for(var i = 1; i <= _this.showSum; i++){
     $(_this.iList[_this.iListSum - i]).prependTo($("#" + _this.oList));
    }
    $("#" + _this.oList).css({ left: -_this.moveWidth });
    $("#" + _this.oList + ":not(:animated)").animate( { left: "+=" + _this.moveWidth }, { duration: "slow", complete: function(){
     for(var j = _this.showSum + 1; j <= _this.iListSum; j++){
      $(_this.iList[_this.iListSum - j]).prependTo($("#" + _this.oList));
     }
     $("#" + _this.oList).css({ left: -_this.moveWidth * (_this.dividers - 1) });
    } } );
   }else{
    $("#" + _this.oList + ":not(:animated)").animate( { left: "+=" + _this.moveWidth }, "slow" );
   }
  });
 },
 RightScroll: function(){
  if(this.dividers == 1) return;
  var _this = this, currentOffset;
  $("#" + this.rButton).click(function(){
   currentOffset = _this.ReturnLeft();
   if(Math.abs(currentOffset) >= _this.moveMaxOffset){
    for(var i = 0; i < _this.showSum; i++){
     $(_this.iList[i]).appendTo($("#" + _this.oList));
    }
    $("#" + _this.oList).css({ left: -_this.moveWidth * (_this.dividers - 2) });
    
    $("#" + _this.oList + ":not(:animated)").animate( { left: "-=" + _this.moveWidth }, { duration: "slow", complete: function(){
     for(var j = _this.showSum; j < _this.iListSum; j++){
      $(_this.iList[j]).appendTo($("#" + _this.oList));
     }
     $("#" + _this.oList).css({ left: 0 });
    } } );
   }else{
    $("#" + _this.oList + ":not(:animated)").animate( { left: "-=" + _this.moveWidth }, "slow" );
   }
  });
 }
};
$(document).ready(function(){
 var ff = new SellerScroll();
});
//-->
</script>
</head>
<body>
<div class="con">
    <div id="carousel_container">
        <div id="left_scroll"></div>
        <div id="carousel_inner">
            <ul id="carousel_ul">
                <li>1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
                <li>5</li>
                <li>6</li>
                <li>7</li>
                <li>8</li>
                <li>9</li>
                <li>10</li>
                <li>11</li>
                <li>12</li>
            </ul>
        </div>
        <div id="right_scroll"></div>
    </div>
</div>
</body>
</html>

视频教程列表
文章教程搜索
 
Javascript推荐教程
Javascript热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058