droplist

来源:互联网 发布:网络票务系统 编辑:程序博客网 时间:2024/05/20 11:50
var self = this; 
  var curSelected=null; 
  var $container=null;
  var $dom=null;
  
  this.$inputbox=null;
  var $trigger=null;
  var $list=null;
  var $listInner=null;
  var items=[];
  this.isSingle = settings.isSingle;
  this.value = [];
  this.ids = [];
  
  var validateParamType = function(obj){
   if(!obj) return;
   if(typeof obj=="string"&&obj.indexOf("#")==-1&&obj.indexOf(".")==-1&&obj.indexOf(":")==-1&&$(obj).length == 0){
    obj = $("#"+obj);
   } else {
    obj = $(obj);
   }
   return obj;
  }
  $container = this.$container = validateParamType(settings.container);
  
  //输入框和下拉按钮
  var itemSelecting=false;//是否正在做选择,当鼠标经过弹出菜单时如此。  
  //设置下拉列表的位置
  function setListPosition(){
   if($list.offsetParent().is(":not(body)")){
    $list.css("left",$dom.position().left).css("top",$dom.position().top+$dom.outerHeight()+"px");
   } else {
    $list.css("left",$dom.offset().left).css("top",$dom.offset().top+$dom.outerHeight()+"px"); 
   }    
  }
  //位置调整,使用up down键时,被选中的item不会被遮挡
  function adjustListposition(obj){
   if(obj.length==0) return;
   var prevsTotalHeight = 0;//.over之前所有item总高度
   var listHeight = $list.height();//list可见高度
   var objHeight = obj.outerHeight(true);
   $.each(obj.prevAll(),function(){
    prevsTotalHeight += $(this).outerHeight(true);
   });
   if(obj.position().top<0){
    $list.scrollTop(prevsTotalHeight);
   }
   if(obj.position().top+objHeight>listHeight){
    $list.scrollTop(prevsTotalHeight+objHeight-listHeight);
   }
  }
原创粉丝点击