jquery插件编写思路
function(e) {
e.fn.floatNav = function(t) {
var i = e.extend({
start: null,
end: null,
fixedClass: "nav-fixed",
anchor: null,
targetEle: null,
range: 0,
onStart: function() {},
onEnd: function() {}
},
t),
s = e(this),
a = s.height(),
o = s.width(),
n = e('<div class="float-nav-wrap"/>'); //以逗号分隔各个值,一次定义多个变量
//return 返回用逗号隔开的各个值,这里用到了逗号表单式,把this单签这个对象放到最后,确保逗号表达式返回的是当前的这个jquery对象,这样写,确保了每个逗号
表达式中的语句都被执行
return s.css({ height: a, width: o }), s.parent().hasClass("float-nav-wrap") || s.wrap(n.css("height", a)), //先判断下父级是否有float-nav-wrap这个对象,如果有的话,则执行后面的s.wrap(n.css("height", a))语句 e(window).bind("scroll", function() { var t = e(document).scrollTop(), a = s.find("a").eq(0).attr("href"), o = i.start || s.parent(".float-nav-wrap").offset().top, n = i.targetEle ? e(i.targetEle).offset().top: 1e4; t > o && (i.end || n) - i.range > t ? (s.addClass(i.fixedClass), i.anchor && a !== i.anchor && s.find("a").attr("href", i.anchor), i.onStart && i.onStart()) : (s.removeClass(i.fixedClass), i.anchor && s.find("a").attr("href", "javascript:;"), i.onEnd && i.onEnd()) }), this } } (jQuery),