文件
2026-10-08 16:23:22 +08:00

359 行
15 KiB
JavaScript

//导航下拉开始
$(document).ready(function () {
// $(this).children('div.subMenu').stop().slideToggle(600);
$('ul.navigationlist li').mousemove(function () {
// $(this).find('ul').css('height','auto');
$(this).find('ul').stop(true, true).slideDown(280); //you can give it a speed
});
$('ul.navigationlist li').mouseleave(function () {
$(this).find('ul').stop(true, true).slideUp(280);
});
$("#logo_main").scrollFix({
zIndex: 1000
});
});
//导航下拉结束
/*====scrool插件 开始====*/
(function ($) {
$.fn.scrollFix = function (options) {
return this.each(function () {
var opts = $.extend({}, $.fn.scrollFix.defaultOptions, options);
var obj = $(this),
base = this,
selfTop = 0,
selfLeft = 0,
toTop = 0,
parentOffsetLeft = 0,
parentOffsetTop = 0,
outerHeight,
outerWidth,
objWidth = 0,
placeholder = jQuery('<div>'), //创建一个jquery对象
optsTop = opts.distanceTop, //定义到顶部的高度
endfix = 0; //开始停止固定的位置
var originalPosition;
var originalOffsetTop;
var originalZIndex;
var lastOffsetLeft = -1;
var isUnfixed = true;
//如果没有找到节点,不进行处理
if (obj.length <= 0) {
return;
}
// 如果 obj 元素存在并且长度大于 0
if (lastOffsetLeft == -1) {
originalZIndex = obj.css('z-index');
position = obj.css('position');
originalPosition = obj.css('position');
originalOffsetTop = obj.css('top');
}
var zIndex = obj.css('zIndex');
if (opts.zIndex != 0) {
zIndex = opts.zIndex;
}
//获取相对定位或者绝对定位的父类
var parents = obj.parent();
var Position = parents.css('position');
while (!/^relative|absolute$/i.test(Position)) { //检测浮动元素的父类元素定位为'relative'或者'absolute',是的话退出,否则的话,执行循环,继续寻找它的父类
parents = parents.parent();
Position = parents.css('position');
if (/^body|html$/i.test(parents[0].tagName)) break; //假如父类元素的标签为body或者HTML,说明没有找到父类为以上的定位,退出循环
}
var ie6 = !-[1,] && !window.XMLHttpRequest; //兼容IE6
var resizeWindow = false;
function resetScroll() {
setUnfixed();
selfTop = obj.offset().top; //对象距离顶部高度
selfLeft = obj.offset().left; //对象距离左边宽度
outerHeight = obj.outerHeight(); //对象高度
outerHeight = parseFloat(outerHeight) + parseFloat(obj.css('marginBottom').replace(/auto/, 0));
outerWidth = obj.outerWidth(); //对象外宽度
objWidth = obj.width();
var documentHeight = $(document).height(); //文档高度
var startTop = $(opts.startTop), //开始浮动固定对象
startBottom = $(opts.startBottom),
toBottom, //停止滚动位置距离底部的高度
ScrollHeight; //对象滚动的高度
//计算父类偏移值
if (/^body|html$/i.test(parents[0].tagName)) { //当父类元素非body或者HTML时,说明找到了一个父类为'relative'或者'absolute'的元素,得出它的偏移高度
parentOffsetTop = 0, parentOffsetLeft = 0;
} else {
parentOffsetLeft = parents.offset().left, parentOffsetTop = parents.offset().top;
}
// 计算父节点的上边到顶部距离
// 如果 body 有 top 属性, 消除这些位移
var bodyToTop = parseInt(jQuery('body').css('top'), 10);
if (!isNaN(bodyToTop)) {
optsTop += bodyToTop;
}
//计算停在底部的距离
if (!isNaN(opts.endPos)) {
toBottom = opts.endPos;
} else {
toBottom = parseFloat(documentHeight - $(opts.endPos).offset().top);
}
//计算需要滚动的高度以及停止滚动的高度
ScrollHeight = parseFloat(documentHeight - toBottom - optsTop), endfix = parseFloat(ScrollHeight - outerHeight);
//计算顶部的距离值
if (startTop[0]) {
var startTopOffset = startTop.offset(),
startTopPos = startTopOffset.top;
selfTop = startTopPos;
}
if (startBottom[0]) {
var startBottomOffset = startBottom.offset(),
startBottomPos = startBottomOffset.top,
startBottomHeight = startBottom.outerHeight();
selfTop = parseFloat(startBottomPos + startBottomHeight);
}
toTop = selfTop - optsTop;
toTop = (toTop > 0) ? toTop : 0;
var selfBottom = documentHeight - selfTop - outerHeight;
//如果滚动停在底部的值不为0,并且自身到底部的高度小于上面这个值,不执行浮动固定
if ((toBottom != 0) && (selfBottom <= toBottom)) {
return;
}
}
function setUnfixed() {
if (!isUnfixed) {
lastOffsetLeft = -1;
placeholder.css("display", "none");
obj.css({
'z-index': originalZIndex,
'width': '',
'position': originalPosition,
'left': '',
'top': originalOffsetTop,
'margin-left': ''
});
obj.removeClass('scrollfixed');
isUnfixed = true;
}
}
function onScroll() {
lastOffsetLeft = 1;
var ScrollTop = $(window).scrollTop();
if (opts.bottom != -1) {
ScrollTop = ScrollTop + $(window).height() - outerHeight - opts.bottom;
}
if (ScrollTop > toTop && (ScrollTop < endfix)) {
if (ie6) { //IE6则使用这个样式
obj.addClass(opts.baseClassName).css({
"z-index": zIndex,
"position": "absolute",
"top": opts.bottom == -1 ? ScrollTop + optsTop - parentOffsetTop : ScrollTop - parentOffsetTop,
"bottom": 'auto',
"left": selfLeft - parentOffsetLeft,
'width': objWidth
})
} else {
obj.addClass(opts.baseClassName).css({
"z-index": zIndex,
"position": "fixed",
"top": opts.bottom == -1 ? optsTop : '',
"bottom": opts.bottom == -1 ? '' : opts.bottom,
"left": selfLeft,
"width": objWidth
});
}
placeholder.css({
'height': outerHeight,
'width': outerWidth,
'display': 'block'
}).insertBefore(obj);
} else if (ScrollTop >= endfix) {
obj.addClass(opts.baseClassName).css({
"z-index": zIndex,
"position": "absolute",
"top": endfix - parentOffsetTop + optsTop,
'bottom': '',
"left": selfLeft - parentOffsetLeft,
"width": objWidth
});
placeholder.css({
'height': outerHeight,
'width': outerWidth,
'display': 'block'
}).insertBefore(obj)
} else {
obj.removeClass(opts.baseClassName).css({
"z-index": originalZIndex,
"position": "absolute",
"top": "",
"bottom": "",
"left": ""
});
placeholder.remove()
}
}
var Timer = 0;
// if (isUnfixed) {
resetScroll();
// }
$(window).on("scroll", function () {
if (Timer) {
clearTimeout(Timer);
}
Timer = setTimeout(onScroll, 0);
});
// 当发现调整屏幕大小时,重新执行代码
$(window).on("resize", function () {
if (Timer) {
clearTimeout(Timer);
}
Timer = setTimeout(function () {
isUnfixed = false;
resetScroll();
onScroll();
}, 0);
});
})
}
$.fn.scrollFix.defaultOptions = {
startTop: null, //滑到这个位置顶部时开始浮动,默认为空
startBottom: null, //滑到这个位置末端开始浮动,默认为空
distanceTop: 0, //固定在顶部的高度
endPos: 0, //停靠在底部的位置,可以为jquery对象
bottom: -1, //底部位置
zIndex: 0, //z-index值
baseClassName: 'scrollfixed' //开始固定时添加的类
};
})(jQuery);
/*====scrool插件 结束====*/
/*==! Lazy Load 1.9.1 - MIT license - Copyright 2010-2013 Mika Tuupola ==*/
! function (a, b, c, d) {
var e = a(b);
a.fn.lazyload = function (f) {
function g() {
var b = 0;
i.each(function () {
var c = a(this);
if (!j.skip_invisible || c.is(":visible"))
if (a.abovethetop(this, j) || a.leftofbegin(this, j));
else if (a.belowthefold(this, j) || a.rightoffold(this, j)) {
if (++b > j.failure_limit) return !1
} else c.trigger("appear"), b = 0
})
}
var h, i = this,
j = {
threshold: 0,
failure_limit: 0,
event: "scroll",
effect: "show",
container: b,
data_attribute: "original",
skip_invisible: !0,
appear: null,
load: null,
placeholder: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC"
};
return f && (d !== f.failurelimit && (f.failure_limit = f.failurelimit, delete f.failurelimit), d !== f.effectspeed && (f.effect_speed = f.effectspeed, delete f.effectspeed), a.extend(j, f)), h = j.container === d || j.container === b ? e : a(j.container), 0 === j.event.indexOf("scroll") && h.bind(j.event, function () {
return g()
}), this.each(function () {
var b = this,
c = a(b);
b.loaded = !1, (c.attr("src") === d || c.attr("src") === !1) && c.is("img") && c.attr("src", j.placeholder), c.one("appear", function () {
if (!this.loaded) {
if (j.appear) {
var d = i.length;
j.appear.call(b, d, j)
}
a("<img />").bind("load", function () {
var d = c.attr("data-" + j.data_attribute);
c.hide(), c.is("img") ? c.attr("src", d) : c.css("background-image", "url('" + d + "')"), c[j.effect](j.effect_speed), b.loaded = !0;
var e = a.grep(i, function (a) {
return !a.loaded
});
if (i = a(e), j.load) {
var f = i.length;
j.load.call(b, f, j)
}
}).attr("src", c.attr("data-" + j.data_attribute))
}
}), 0 !== j.event.indexOf("scroll") && c.bind(j.event, function () {
b.loaded || c.trigger("appear")
})
}), e.bind("resize", function () {
g()
}), /(?:iphone|ipod|ipad).*os 5/gi.test(navigator.appVersion) && e.bind("pageshow", function (b) {
b.originalEvent && b.originalEvent.persisted && i.each(function () {
a(this).trigger("appear")
})
}), a(c).ready(function () {
g()
}), this
}, a.belowthefold = function (c, f) {
var g;
return g = f.container === d || f.container === b ? (b.innerHeight ? b.innerHeight : e.height()) + e.scrollTop() : a(f.container).offset().top + a(f.container).height(), g <= a(c).offset().top - f.threshold
}, a.rightoffold = function (c, f) {
var g;
return g = f.container === d || f.container === b ? e.width() + e.scrollLeft() : a(f.container).offset().left + a(f.container).width(), g <= a(c).offset().left - f.threshold
}, a.abovethetop = function (c, f) {
var g;
return g = f.container === d || f.container === b ? e.scrollTop() : a(f.container).offset().top, g >= a(c).offset().top + f.threshold + a(c).height()
}, a.leftofbegin = function (c, f) {
var g;
return g = f.container === d || f.container === b ? e.scrollLeft() : a(f.container).offset().left, g >= a(c).offset().left + f.threshold + a(c).width()
}, a.inviewport = function (b, c) {
return !(a.rightoffold(b, c) || a.leftofbegin(b, c) || a.belowthefold(b, c) || a.abovethetop(b, c))
}, a.extend(a.expr[":"], {
"below-the-fold": function (b) {
return a.belowthefold(b, {
threshold: 0
})
},
"above-the-top": function (b) {
return !a.belowthefold(b, {
threshold: 0
})
},
"right-of-screen": function (b) {
return a.rightoffold(b, {
threshold: 0
})
},
"left-of-screen": function (b) {
return !a.rightoffold(b, {
threshold: 0
})
},
"in-viewport": function (b) {
return a.inviewport(b, {
threshold: 0
})
},
"above-the-fold": function (b) {
return !a.belowthefold(b, {
threshold: 0
})
},
"right-of-fold": function (b) {
return a.rightoffold(b, {
threshold: 0
})
},
"left-of-fold": function (b) {
return !a.rightoffold(b, {
threshold: 0
})
}
})
}(jQuery, window, document);
/*==Lazy Load 1.9.1 结束==*/