JS技术

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

字号+ 作者:H5之家 来源:H5之家 2015-10-01 09:05 我要评论( )

编写图片切换效果2(基于jquery) 源码,学习编写图片切换效果2(基于jquery) 源码,编写图片切换效果2(基于jquery) 源码,查看编写图片切换效果2(基于jquery) 源码,21

教程网3月27日整理

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<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() no-repeat;}
#right_scroll{position: absolute;top:43px;right:0; width: 9px;height: 9px;cursor: pointer;cursor: hand; background: url() 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=""></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>

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
网友点评