一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

jQuery Select(單選) 模擬插件 V1.3.62 改進版

首先感謝jQuery.Select.js的作者張經緯,jQuery.Select.js項目地址:http://www.zhangjingwei.com/archives/jquery-select%E5%8D%95%E9%80%89-%E6%A8%A1%E6%8B%9F%E6%8F%92%E4%BB%B6-v1-3-6/ 
 項目中需要使用基于jQuery的Select模擬效果,主要是想實現select的onmouseover事件,而不需要點擊在經過時即可進行選擇,找了很多沒有理想的,最后決定在jQuery.Select.js 1.3.6的基礎上改進。

下面是增加mouseover事件后的代碼:(如需原版請在作者主頁下載)
復制代碼 代碼如下:
/*
* jQuery Select Plugins v1.3.6.2
* Copyright (c) 2009 zhangjingwei
* Dual licensed under the MIT and GPL licenses.
* Date: 2009-11-17 09:37
* Revision: 1.3.6.2
* www.leadwit.com-浪子 modify in 2010-07-26 14:26
*/
(function($){
$.fn.extend({
sSelect: function() {
return this.each(function(i,obj){
var selectId = (this.name||this.id)+'__jQSelect'+i||'__jQSelect'+i;
if(obj.style.display != 'none' && $(this).parents()[0].id.indexOf('__jQSelect')<0){
var tabindex = this.tabIndex||0;
$(this).before("<div class='dropdown' id="+selectId+" tabIndex="+tabindex+"></div>").prependTo($("#"+selectId));
var selectZindex = $(this).css('z-index'),selectIndex = $('#'+selectId+' option').index($('#'+selectId+' option:selected')[0]);
$('#'+selectId).append('<div class="dropselectbox"><h4></h4><ul></ul></div>');
$('#'+selectId+' h4').empty().append($('#'+selectId+' option:selected').text());
var selectWidth=$('#'+selectId+' select').width();
if($.browser.safari){selectWidth = selectWidth+15}
$('#'+selectId+' h4').css({width:selectWidth});
var selectUlwidth = selectWidth + parseInt($('#'+selectId+' h4').css("padding-left")) + parseInt($('#'+selectId+' h4').css("padding-right"));
$('#'+selectId+' ul').css({width:selectUlwidth+'px'});
$('#'+selectId+' select').hide();
$('#'+selectId+' div').hover(function(){
$('#'+selectId+' h4').addClass("over");
},function(){
$('#'+selectId+' h4').removeClass("over");
});
var timeobj;
$('#'+selectId+' ul').bind("mouseover",function(e){
clearTimeout(timeobj);
});
var click_fun =function(){
$('#'+selectId+' h4').addClass("current");
$('#'+selectId+' ul').show();
var selectZindex = $('#'+selectId).css('z-index');
if ($.browser.msie || $.browser.opera){$('.dropdown').css({'position':'relative','z-index':'0'});}
$('#'+selectId).css({'position':'relative','z-index':'999'});
$.fn.setSelectValue(selectId);
selectIndex = $('#'+selectId+' li').index($('.selectedli')[0]);
var windowspace = ($(window).scrollTop() + document.documentElement.clientHeight) - $('#'+selectId).offset().top;
var ulspace = $('#'+selectId+' ul').outerHeight(true);
var windowspace2 = $('#'+selectId).offset().top - $(window).scrollTop() - ulspace;
windowspace < ulspace && windowspace2 > 0?$('#'+selectId+' ul').css({top:-ulspace}):$('#'+selectId+' ul').css({top:$('#'+selectId+' h4').outerHeight(true)});
$(window).scroll(function(){
windowspace = ($(window).scrollTop() + document.documentElement.clientHeight) - $('#'+selectId).offset().top;
windowspace < ulspace?$('#'+selectId+' ul').css({top:-ulspace}):$('#'+selectId+' ul').css({top:$('#'+selectId+' h4').outerHeight(true)});
});
$('#'+selectId+' li').click(function(e){
selectIndex = $('#'+selectId+' li').index(this);
$.fn.keyDown(selectId,selectIndex);
$('#'+selectId+' h4').empty().append($('#'+selectId+' option:selected').text());
$.fn.clearSelectMenu(selectId,selectZindex);
e.stopPropagation();
e.cancelbubble = true;
})
.hover(
function(){
$('#'+selectId+' li').removeClass("over");
$(this).addClass("over").addClass("selectedli");
selectIndex = $('#'+selectId+' li').index(this);
},
function(){
$(this).removeClass("over");
}
);
}
$('#'+selectId)
.bind("focus",function(){
//$.fn.clearSelectMenu(selectId,selectZindex);
$('#'+selectId+' h4').addClass("over");
})
.bind("click",function(e){
if($('#'+selectId+' ul').css("display") == 'block'){
$.fn.clearSelectMenu(selectId,selectZindex);
return false;
}else{
click_fun();
};
e.stopPropagation();
})
.bind("mouseover",function(e){
if($('#'+selectId+' ul').css("display") == 'block'){
//$.fn.clearSelectMenu(selectId,selectZindex);
return false;
}else{
click_fun();
};
e.stopPropagation();
})
.bind("mouseout",function(e){
if($('#'+selectId+' ul').css("display") == 'block'){
timeobj = setTimeout(function(){
$.fn.clearSelectMenu(selectId,selectZindex);
},500);
return false;
}
e.stopPropagation();
})
.bind('mousewheel', function(e,delta) {
e.preventDefault();
var mousewheel = {
$obj : $('#'+selectId+' li.over'),
$slength : $('#'+selectId+' option').length,
mup:function(){
this.$obj.removeClass("over");
selectIndex == 0?selectIndex = 0:selectIndex--;
$.fn.keyDown(selectId,selectIndex);
},
mdown:function(){
this.$obj.removeClass("over");
selectIndex == (this.$slength - 1)?selectIndex = this.$slength - 1:selectIndex ++;
$.fn.keyDown(selectId,selectIndex);
}
}
delta>0?mousewheel.mup():mousewheel.mdown();
})
.bind("dblclick", function(){
$.fn.clearSelectMenu(selectId,selectZindex);
return false;
})
.bind("keydown",function(e){
$(this).bind('keydown',function(e){
if (e.keyCode == 40 || e.keyCode == 38 || e.keyCode == 35 || e.keyCode == 36){
return false;
}
});
var $obj = $('#'+selectId+' li.over'),$slength = $('#'+selectId+' option').length;
switch(e.keyCode){
case 9:
return true;
break;
case 13:
//enter
$.fn.clearSelectMenu(selectId,selectZindex);
break;
case 27:
//esc
$.fn.clearSelectMenu(selectId,selectZindex);
break;
case 33:
$obj.removeClass("over");
selectIndex = 0;
$.fn.keyDown(selectId,selectIndex);
break;
case 34:
$obj.removeClass("over");
selectIndex = ($slength - 1);
$.fn.keyDown(selectId,selectIndex);
break;
case 35:
$obj.removeClass("over");
selectIndex = ($slength - 1);
$.fn.keyDown(selectId,selectIndex);
break;
case 36:
$obj.removeClass("over");
selectIndex = 0;
$.fn.keyDown(selectId,selectIndex);
break;
case 38:
//up
e.preventDefault();
$obj.removeClass("over");
selectIndex == 0?selectIndex = 0:selectIndex--;
$.fn.keyDown(selectId,selectIndex);
break;
case 40:
//down
e.preventDefault();
$obj.removeClass("over");
selectIndex == ($slength - 1)?selectIndex = $slength - 1:selectIndex ++;
$.fn.keyDown(selectId,selectIndex);
break;
default:
e.preventDefault();
break;
};
})
.bind("blur",function(){
$.fn.clearSelectMenu(selectId,selectZindex);
return false;
})
.bind("selectstart",function(){
return false;
});
}else if($(this).parents()[0].id.indexOf('__jQSelect')>0){
selectId = $(this).parents()[0].id;
$.fn.setSelectValue(selectId);
var selectWidth=$('#'+selectId+' select').width();
if($.browser.safari){selectWidth = selectWidth+15}
$('#'+selectId+' h4').css({width:selectWidth});
var selectUlwidth = selectWidth + parseInt($('#'+selectId+' h4').css("padding-left")) + parseInt($('#'+selectId+' h4').css("padding-right"));
$('#'+selectId+' ul').css({width:selectUlwidth+'px'});
if(this.style.display != 'none'){$(this).hide();}
}})},
clearSelectMenu:function(selectId,selectZindex){
if(selectId != undefined){
selectZindex = selectZindex||'auto';
$('#'+selectId+' ul').empty().hide();
$('#'+selectId+' h4').removeClass("over").removeClass("current");
$('#'+selectId).css({'z-index':selectZindex});
}
},
setSelectValue:function(sID){
var content = [];
$.each($('#'+sID+' option'), function(i){
content.push("<li class='FixSelectBrowser'>"+$(this).text()+"</li>");
});
content = content.join('');
$('#'+sID+' ul').html(content);
$('#'+sID+' h4').html($('#'+sID+' option:selected').text());
$('#'+sID+' li').eq($('#'+sID+' select')[0].selectedIndex).addClass("over").addClass("selectedli");
},
keyDown:function(sID,selectIndex){
var $obj = $('#'+sID+' select');
$obj[0].selectedIndex = selectIndex;
$obj.change();
$('#'+sID+' li:eq('+selectIndex+')').toggleClass("over");
$('#'+sID+' h4').html($('#'+sID+' option:selected').text());
}
});
var types = ['DOMMouseScroll', 'mousewheel'];
$.event.special.mousewheel = {
setup: function() {
if ( this.addEventListener )
for ( var i=types.length; i; )
this.addEventListener( types[--i], handler, false );
else
this.onmousewheel = handler;
},
teardown: function() {
if ( this.removeEventListener )
for ( var i=types.length; i; )
this.removeEventListener( types[--i], handler, false );
else
this.onmousewheel = null;
}
};
$.fn.extend({
mousewheel: function(fn) {
return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
},
unmousewheel: function(fn) {
return this.unbind("mousewheel", fn);
}
});
function handler(event) {
var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
event = $.event.fix(event || window.event);
event.type = "mousewheel";
if ( event.wheelDelta ) delta = event.wheelDelta/120;
if ( event.detail ) delta = -event.detail/3;
args.unshift(event, delta);
return $.event.handle.apply(this, args);
}
})(jQuery);

演示地址 http://demo.jb51.NET/js/jQuery.Select/index.html
打包下載 http://www.jb51.NET/jiaoben/21397.html

JavaScript技術jQuery Select(單選) 模擬插件 V1.3.62 改進版,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 黄色网址中文字幕 | 91极品视频在线观看 | 成人a毛片一级 | 中文字幕精品亚洲无线码二区 | japanese无码中文字幕 | 欧美成人三级大全 | 欧美精品做人一级爱免费 | 91在线网址 | 国产亚洲一区二区在线观看 | 五月婷婷之综合激情 | 美女黄色免费网站 | 好吊色欧美一区二区三区四区 | 久久久久国产精品美女毛片 | 久久综合久久综合久久 | 91精品免费久久久久久久久 | 国产成人一区二区三区精品久久 | 好属妞这里只有精品久久 | 色女生影院| 国内精品欧美久久精品 | 欧美人体大胆艺术 | 国产精品欧美在线不卡 | 久久国产精品99久久久久久老狼 | 亚洲操片| 欧美日韩亚洲区久久综合 | 视频一区国产精品 | 欧美极品欧美精品欧美图片 | 国语自产自拍秒拍在线视频 | 四虎永久地址4hu紧急入口 | 日韩精品视频在线 | 三级黄网 | 夜色成人免费观看 | 在线播放真实国产乱子伦 | 国产精品国产 | 色综合久久中文色婷婷 | 国产亚洲视频在线观看 | 中文字幕一二三四区2021 | 日本理论片在线播放 | 国产免费一区二区三区在线观看 | 日韩精品一区二区三区国语自制 | 97起碰| 日一区二区三区 |