码迷,mamicode.com
首页 > Web开发 > 详细

网页中需要用的一些原型方法

时间:2018-01-08 11:04:13      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:art   支持   focus   fixed   other   避免   ted   ecif   元素   

$.fn.extend({
propAttr: $.fn.prop || $.fn.attr,
_oldFocus: $.fn.focus,//为避免与jQuery ui冲突导致死循环,这里不要取名为‘_focus‘
//设置元素焦点(delay:延迟时间)
focus: function( delay, fn ) {
return typeof delay === "number" ?
this.each(function() {
var elem = this;
setTimeout(function() {
$( elem ).focus();
if ( fn ) {
fn.call( elem );
}
}, delay );
}) :
this._oldFocus.apply( this, arguments );
},
//获取设置滚动属性的 父元素
scrollParent: function() {
var scrollParent;
if (($.browser.msie && (/(static|relative)/).test(this.css(‘position‘))) || (/absolute/).test(this.css(‘position‘))) {
scrollParent = this.parents().filter(function() {
return (/(relative|absolute|fixed)/).test($.curCSS(this,‘position‘,1)) && (/(auto|scroll)/).test($.curCSS(this,‘overflow‘,1)+$.curCSS(this,‘overflow-y‘,1)+$.curCSS(this,‘overflow-x‘,1));
}).eq(0);
} else {
scrollParent = this.parents().filter(function() {
return (/(auto|scroll)/).test($.curCSS(this,‘overflow‘,1)+$.curCSS(this,‘overflow-y‘,1)+$.curCSS(this,‘overflow-x‘,1));
}).eq(0);
}
return (/fixed/).test(this.css(‘position‘)) || !scrollParent.length ? $(document) : scrollParent;
},
//设置或获取元素的垂直坐标
zIndex: function( zIndex ) {
if ( zIndex !== undefined ) {
return this.css( "zIndex", zIndex );
}
if ( this.length ) {
var elem = $( this[ 0 ] ), position, value;
while ( elem.length && elem[ 0 ] !== document ) {
// Ignore z-index if position is set to a value where z-index is ignored by the browser
// This makes behavior of this function consistent across browsers
// WebKit always returns auto if the element is positioned
position = elem.css( "position" );
if ( position === "absolute" || position === "relative" || position === "fixed" ) {
// IE returns 0 when zIndex is not specified
// other browsers return a string
// we ignore the case of nested elements with an explicit value of 0
// <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
value = parseInt( elem.css( "zIndex" ), 10 );
if ( !isNaN( value ) && value !== 0 ) {
return value;
}
}
elem = elem.parent();
}
}
return 0;
},
//设置元素不支持被选择
disableSelection: function() {
return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
".ued-disableSelection", function( event ) {
event.preventDefault();
});
},
//设置元素支持被选择
enableSelection: function() {
return this.unbind( ".ued-disableSelection" );
}
});

网页中需要用的一些原型方法

标签:art   支持   focus   fixed   other   避免   ted   ecif   元素   

原文地址:https://www.cnblogs.com/sunzhnan/p/8241250.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!