前端之家 收集整理的这篇文章主要介绍了
18个非常棒的jQuery代码片段 ,
前端之家 小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1、jQuery实现的内链接 平滑滚动
不需要使用太复杂的插件 ,只要使用下载这段代码 即可实现基于内部链接 的平滑滚动
var anchor = this.hash,$target = $(target);
$('html,body').stop().animate({
'scrollTop': $target.offset().top
},500,'swing',function () {
window.location.hash = anchor;
});
});
2、使用jQuery获取 所有节点
3、限制选择框选择个数
4、jQuery使用通配 符来删除 class
$('.currency').removeClass (function (index,css) {
return (css.match (/\bicon-\S+/g) || []).join(' ');
}).addClass('icon-'+_c);
5、切换启用和禁用
|
|
*/
// Plugin
(function ($) {
$.fn.toggleDisabled = function () {
return this.each(function () {
var $this = $(this);
if ($this.attr('disabled')) $this.removeAttr('disabled');
else $this.attr('disabled','disabled');
});
};
})(jQuery);
// TEST
$(function () {
$('input:button').click(function () {
$('input:text').toggleDisabled();
});
});
Box = $(this).attr('id');
array1.push(form
Box );
console.log("you filled out
Box " + array1);
});
$('#submit').click(function () {
console.log('tracked ' + array1);
//alert('this is the order of
Box es you filled out: ' + array1);
_gaq.push(['_trackEvent','Form','completed','"' + array1 + '"']);
});
});
function positionFooter() {
footerHeight = $footer.height();
footerTop = ($(window).scrollTop() + $(window).height() - footerHeight) + "px";
/
DEBUGGING
console.log("Document height: ",$(document.body).height());
console.log("Window height: ",$(window).height());
console.log("Window scroll: ",$(window).scrollTop());
console.log("Footer height: ",footerHeight);
console.log("Footer top: ",footerTop);
/
if (($(document.body).height() + footerHeight) < $(window).height()) {
$footer.css({
position: "absolute"
}).stop().animate({
top: footerTop
});
} else {
$footer.css({
position: "static"
});
}
}
$(window)
.scroll(positionFooter)
.resize(positionFooter);
});
502_68@ maxWidth){
ratio = maxWidth / width;
$(this).css("width",maxWidth);
$(this).css("height",height * ratio);
height = height * ratio;
}
var width = $(this).width();
var height = $(this).height();
if(height > maxHeight){
ratio = maxHeight / height;
$(this).css("height",maxHeight);
$(this).css("width",width * ratio);
width = width * ratio;
}
});
//$("#contentpage img").show();
// IMAGE RESIZE
});
$(".thumbs img").hover(function(){
$(this).fadeTo("slow",1.0); // This should set the opacity to 100% on hover
},function(){
$(this).fadeTo("slow",0.6); // This should set the opacity back to 60% on mou
SEO ut
});
});
max_height) { max_height = $(this).height(); }
});
$("div.col").height(max_height);