自定义 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 ...
随机推荐
- 涂抹Oracle—Flashback
11.1 基于flashback查询过去的数据 a.基于时间的查询(as of timestamp) 构造表falsh_tbl,删除数据然后查询 SQL>select * from flash ...
- 专门讲讲这个MYSQL授权当中的with grant option的作用
对象的owner将权限赋予某个用户(如:testuser1) grant select ,update on bd_corp to testuser1 [with grant option ]1.如果 ...
- ViewConfiguration滑动参数设置类
/** * 包含了方法和标准的常量用来设置UI的超时.大小和距离 */ public class ViewConfiguration { // 设定水平滚动条的宽度和垂直滚动条的高度,单位是像素px ...
- HDU_1016——素环问题DFS
Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ... ...
- HDU_2058——等差数列,子集,集合长度判断
Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-se ...
- HDU_2051——十进制到二进制转换
Problem Description Give you a number on base ten,you should output it on base two.(0 < n < 10 ...
- 【剑指offer】面试题24:二叉搜索树的后序遍历序列
题目: 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. 思路: 递归 注意,主要就是假定数组为空时结果为fa ...
- 深入理解linux网络技术内幕读书笔记(三)--用户空间与内核的接口
Table of Contents 1 概论 1.1 procfs (/proc 文件系统) 1.1.1 编程接口 1.2 sysctl (/proc/sys目录) 1.2.1 编程接口 1.3 sy ...
- java实现的23种设计模式 (个人推荐)
http://zz563143188.iteye.com/blog/1847029 mark下,个人用,大家会也可以看看写的不错.
- selenium page object model
Page Object Model (POM) & Page Factory in Selenium: Ultimate Guide 来源:http://www.guru99.com/page ...