excel下拉框实现复选 select实现多选下拉框功能


excel下拉框实现复选 select实现多选下拉框功能

文章插图
各位朋友大家早上好!
今天给大家带来的是 八种select下拉选择特效源码!
在日常工作中会经常遇到!
大家可以按照自己的意愿,做成喜欢的样子!
有想要文件版源码的可以私聊小编!
废话不多说,上源码!
JS:/**
* selectFx.js v1.0.0
* http://www.codrops.com
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright 2014, Codrops
* http://www.codrops.com
*/
;( function( window ) {
‘use strict’;
/**
* based on from https://github.com/inuyaksa/jquery.nicescroll/blob/master/jquery.nicescroll.js
*/
function hasParent( e, p ) {
if (!e) return false;
var el = e.target||e.srcElement||e||false;
while (el && el != p) {
el = el.parentNode||false;
}
return (el!==false);
};
/**
* extend obj function
*/
function extend( a, b ) {
for( var key in b ) {
if( b.hasOwnProperty( key ) ) {
a[key] = b[key];
}
}
return a;
}
/**
* SelectFx function
*/
function SelectFx( el, options ) {
this.el = el;
this.options = extend( {}, this.options );
extend( this.options, options );
this._init();
}
/**
* SelectFx options
*/
SelectFx.prototype.options = {
// if true all the links will open in a new tab.
// if we want to be redirected when we click an option, we need to define a data-link attr on the option of the native select element
newTab : true,
// when opening the select element, the default placeholder (if any) is shown
stickyPlaceholder : true,
// callback when changing the value
onChange : function( val ) { return false; }
}
/**
* init function
* initialize and cache some vars
*/
SelectFx.prototype._init = function() {
// check if we are using a placeholder for the native select box
// we assume the placeholder is disabled and selected by default
var selectedOpt = this.el.querySelector( ‘option[selected]’ );
this.hasDefaultPlaceholder = selectedOpt && selectedOpt.disabled;
// get selected option (either the first option with attr selected or just the first option)
this.selectedOpt = selectedOpt || this.el.querySelector( ‘option’ );
// create structure
this._createSelectEl();
// all options
this.selOpts = [].slice.call( this.selEl.querySelectorAll( ‘li[data-option]’ ) );
// total options
this.selOptsCount = this.selOpts.length;
// current index
this.current = this.selOpts.indexOf( this.selEl.querySelector( ‘li.cs-selected’ ) ) || -1;
// placeholder elem
this.selPlaceholder = this.selEl.querySelector( ‘span.cs-placeholder’ );
// init events
this._initEvents();
}
/**
* creates the structure for the select element
*/
SelectFx.prototype._createSelectEl = function() {
var self = this, options = ”, createOptionHTML = function(el) {
var optclass = ”, classes = ”, link = ”;
if( el.selectedOpt && !this.foundSelected && !this.hasDefaultPlaceholder ) {
classes += ‘cs-selected ‘;
this.foundSelected = true;
}
// extra classes
if( el.getAttribute( ‘data-class’ ) ) {
classes += el.getAttribute( ‘data-class’ );
}
// link options
if( el.getAttribute( ‘data-link’ ) ) {
link = ‘data-link=’ + el.getAttribute( ‘data-link’ );


以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!

「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助: