自定义 select 下拉菜单
.selectBeautifyMainStyle{ color: #9fa0a0; font-size: 14px; font-family: "alegreya_sansthin"; text-transform: uppercase; width:415px; height:45px; line-height:45px; border:1px solid #D1D1D1; float:left; padding: 0 50px 0 10px; cursor:pointer; position: relative; margin-bottom: 25px; }
.selectBeautifyMainStyle span { display: block; position: absolute; top: 8px; right:; border-left: 1px solid #d1d1d1; width: 50px; height: 29px; background: url(../images/crlaine/selectopen.png) no-repeat 15px 10px;}
.selectBeautifyMenuStyle{ color: #005e79; font-size: 14px; font-family: "alegreya_sansthin"; text-transform: uppercase; width:415px; height:300px; border:1px solid #D1D1D1; padding:10px; position:absolute; z-index:; left:; top:45px; background:#FFF; overflow-y:auto; display:none;}
.selectBeautifyMenuStyle *{ padding:; margin:; }
.selectBeautifyMenuStyle ul{ list-style-type: none; }
.selectBeautifyMenuStyle li{ height: 35px; line-height: 35px; cursor: pointer; }
.selectBeautifyMenuStyle li.current-selected { color: #9fa0a0; }
.selectBeautifyMenuStyle li.bg-color { background-color: #f1f1f1; }
// custom select-box function
function selectBeautify(id, mainStyle, menuStyle){
this.obj = $('#' + id);
this.mainStyle = mainStyle;
this.menuStyle = menuStyle;
this.run = function() {
this.obj.hide();
var cpObj = this.obj;
var mainHtml = '<div class="' + this.mainStyle + '">' + this.obj.find(":selected").html() + '<span></span></div>';
this.obj.after(mainHtml);
var menuHtml = '<div class="' + this.menuStyle + '"><ul>';
this.obj.find('option').each(function(){
menuHtml += "<li>"+$(this).html()+"</li>";
});
menuHtml += '</ul></div>';
this.obj.next().after(menuHtml); //Binding click event
this.obj.next().click(function(){
event.stopPropagation(); if($(this).next().is(':visible')){
$(this).next().slideUp(0);
return false;
}
$(this).parent().css({'position':'relative'});
$(this).next().slideDown();
$(this).next().css({'overflow-y':'auto'}); // current selected color
var currentText = $(this).text();
$(this).next().find('li').each(function() {
if ($(this).text() == currentText) {
$(this).addClass('current-selected').siblings().removeClass('current-selected');
}
}); //Binding the mouse events
// $(this).next().hover(function(){},function(){$(this).slideUp(0);});
$(document).click(function(){
cpObj.next().next().slideUp(0);
}); //Click select event binding
$(this).next().find('li').click(function(){
cpObj.next().html($(this).html() + '<span></span>');
cpObj.get(0).selectedIndex = $(this).index();
cpObj.find('option').eq($(this).index()).attr('selected', 'selected').siblings().removeAttr('selected');
cpObj.next().next().hide();
}); //mouse after li
$(this).next().find('li').hover(
function(){
$(this).addClass('bg-color');
},
function(){
$(this).removeClass('bg-color');
}
); });
}
}
var countrySelector = new selectBeautify('field69', 'selectBeautifyMainStyle', 'selectBeautifyMenuStyle');
countrySelector.run();
移出DIV后自动隐藏
// custom select-box function
function selectBeautify(id, mainStyle, menuStyle){
this.obj = $('#' + id);
this.run = function() {
this.obj.hide();
var cpObj = this.obj; var mainHtml = '<div class="select-box"><div class="' + mainStyle + '">' + this.obj.find(":selected").html() + '<span></span></div>';
var menuHtml = '<div class="' + menuStyle + '"><ul>';
this.obj.find('option').each(function(){
menuHtml += '<li>'+$(this).html()+'</li>';
});
menuHtml += '</ul></div></div>';
this.obj.after(mainHtml + menuHtml); //Binding click event
this.obj.next().children('.' + mainStyle).click(function(){
if($(this).next().is(':visible')){
$(this).next().stop().slideUp(0);
return false;
} $(this).parent().css({'position':'relative'});
$(this).next().slideDown();
$(this).next().css({'overflow-y':'auto'}); // current selected color
var currentText = $(this).text();
$(this).next().find('li').each(function() {
if ($(this).text() == currentText) {
$(this).addClass('current-selected').siblings().removeClass('current-selected');
}
}); //Binding the mouse events
cpObj.next().hover(function(){},function(){$(this).children('.' + menuStyle).stop().slideUp(0);});
// $(this).next().hover(function(){},function(){$(this).slideUp(0);}); //Click select event binding
$(this).next().find('li').click(function(){
cpObj.next().children('.' + mainStyle).html($(this).html() + '<span></span>');
cpObj.get(0).selectedIndex = $(this).index();
cpObj.find('option').eq($(this).index()).attr('selected', 'selected').siblings().removeAttr('selected');
cpObj.next().children('.' + menuStyle).hide();
}); //mouse after li
$(this).next().find('li').hover(
function(){
$(this).addClass('bg-color');
},
function(){
$(this).removeClass('bg-color');
}
); });
}
}
var countrySelector = new selectBeautify('field69', 'selectBeautifyMainStyle', 'selectBeautifyMenuStyle');
countrySelector.run();
自定义 select 下拉菜单的更多相关文章
- [k]自定义样式下拉菜单
自定义样式下拉菜单-1 <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> & ...
- CSS自定义select下拉选择框(不用其他标签模拟)
今天群里有人问到怎么自定义select下拉选择框的样式,于是群里就展开了激烈的讨论,刚开始一直就是考虑怎样使用纯CSS实现,把浏览器默认的样式覆盖掉,但最后均因兼容问题处理不好而失败告终,最后的解决方 ...
- jQuery插件:模拟select下拉菜单
没搞那么复杂,工作中,基本够用.. <!doctype html> <html> <head> <meta charset="utf-8" ...
- angular 实现自定义样式下拉菜单
自己闲着没事写了一个自定义的下拉菜单希望和大家交流一下!望能和大神们成为朋友. 下面上代码: <!doctype html> <html lang="en" ng ...
- select 下拉菜单Option对象使用add(elements,index)方法动态添加
原生js 的add函数为下拉菜单增加选项 1.object.add(oElement [, iIndex]) index 可选参数:指定元素放置所在的索引号,整形值.如果没有指定值,将添加到集合的最后 ...
- select下拉菜单反显不可改动,且submit能够提交数据
首先通过后台funcA()将下拉菜单反显不可改动的数据response到disable.jsp页面,disable.jsp: <script> var data1=${result.obj ...
- 微信小程序之自定义select下拉选项框组件
知识点:组件,animation,获取当前点击元素的索引与内容 微信小程序中没有select下拉选项框,所以只有自定义.自定义的话,可以选择模板的方式,也可以选择组件的方式来创建. 这次我选择了组件, ...
- 手写的select 下拉菜单
我们在进行表单设计时,可能要用到select下拉选项控件,遗憾的是,IE浏览器默认的select控件外观非常丑陋,而且不能用样式来控制,不能在选项中添加图片等信息.今天我将通过实例来讲解如何用CSS和 ...
- WeChat-SmallProgram:自定义select下拉选项框组件
1):创建组件所需的文件 2):自定义组件 CSS 及 JS 组件的wxml: <view class='com-selectBox'> <view class='com-sCont ...
随机推荐
- [POJ] 1606 Jugs(BFS+路径输出)
题目地址:http://poj.org/problem?id=1606 广度优先搜索的经典问题,倒水问题.算法不需要多说,直接BFS,路径输出采用递归.最后注意是Special Judge #incl ...
- android http协议post请求方式
方式一:HttpPost(import org.apache.http.client.methods.HttpPost 代码如下: private Button button1,button2,but ...
- c语言内存模型
文章一.C语言的内存分配模型 1.程序代码区:存放函数体的二进制代码. 2.全局区数据区:全局数据区划分为三个区域.全局变量和静态变量的存储是放在一块的,初始化的全局变量和静态变量在一块区域,未初始化 ...
- Android 按钮按下效果
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="htt ...
- HAVING 子句 (SQL Server Compact)
MSDN官方文献 原文地址:http://technet.microsoft.com/zh-cn/library/ms173260.aspx
- nutch和solr集成
Linux下的Nutch和solr集成 3.1.Nutch安装 l 解压 tar -zxvf apache-nutch-1.4-bin.tar.gz l 终端下cd到目录 apache-nutch- ...
- Oracle 常用语句汇总
1.查询当前用户的建表SQL: SELECT DBMS_METADATA.GET_DDL('TABLE','COL_MERCH_INFO') FROM DUAL; 2.查询当前用户的所有表: SELE ...
- css hack 兼容性
做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我们会极不情愿的使用这个不太友好的方式来 达到大家要求的页面表现.我个人是不太推荐使用hack的,要知 ...
- svn出现“Previous operation has not finished; run 'cleanup' if it was interrupted”,解决方法
1.首先不需要动svn的服务器端.2.在客户端安装svn的客户端工具,自定义工具中为:command line client tools 安装完之后,在本地目录有svn.exe执行程序3.然后c ...
- httpclient post请求实例(自己写的)
package com.gop.gplus.trade.common.utils; import org.apache.commons.httpclient.HttpClient;import org ...