做右下角广告 QQ客服等等 不会被清理广告软件清理的哦!仅需一行代码搞定!
- /*
- * jQuery Plugins elementFixed v1205
- * 使用说明:
- * $('#div1').elementFixed({position:"leftTop"}); //定位左上
- * $('#div2').elementFixed({position:"leftBottom"}); //定位左下
- * $('#div3').elementFixed({position:"rightTop"}); //定位右上
- * $('#div4').elementFixed({position:"rightBottom"}); //定位右下
- * $('#div5').elementFixed({position:"leftCenter"}); //定位左中
- * $('#div6').elementFixed({position:"rightCenter"}); //定位右中
- * $('#div7').elementFixed({position:"topCenter"}); //定位上居中
- * $('#div8').elementFixed({position:"bottomCenter"}); //定位底居中
- * $('#div9').elementFixed({position:"center"}); //定位居中
- * $('#div4').elementFixed(); //不给参数默认定位为右下
- */
- (function($) {
- jQuery.fn.elementFixed = function(options) {
- var own = this;
- var settings = {
- position: "rightBottom"
- };
- jQuery.extend(settings, options);
- own.css({
- position: "absolute",
- left: 0,
- top: 0,
- zIndex: 1000
- });
- $(window).bind("scroll resize load",
- function() {
- var left = 0;
- var top = 0;
- if (settings.position == "leftTop") {
- left = $(window).scrollLeft();
- top = $(window).scrollTop();
- } else if (settings.position == "rightTop") {
- left = $(window).width() + $(window).scrollLeft() - own.outerWidth();
- top = $(window).scrollTop();
- } else if (settings.position == "leftBottom") {
- left = $(window).scrollLeft();
- top = $(window).height() + $(window).scrollTop() - own.outerHeight();
- } else if (settings.position == "rightBottom") {
- left = $(window).width() + $(window).scrollLeft() - own.outerWidth();
- top = $(window).height() + $(window).scrollTop() - own.outerHeight();
- } else if (settings.position == "leftCenter") {
- left = $(window).scrollLeft();
- top = $(window).height() * 0.5 + $(window).scrollTop() - own.outerHeight() * 0.5;
- } else if (settings.position == "rightCenter") {
- left = $(window).width() + $(window).scrollLeft() - own.outerWidth();
- top = $(window).height() * 0.5 + $(window).scrollTop() - own.outerHeight() * 0.5;
- } else if (settings.position == "topCenter") {
- left = $(window).width() * 0.5 + $(window).scrollLeft() - own.outerWidth() * 0.5;
- top = $(window).scrollTop();
- } else if (settings.position == "bottomCenter") {
- left = $(window).width() * 0.5 + $(window).scrollLeft() - own.outerWidth() * 0.5;
- top = $(window).height() + $(window).scrollTop() - own.outerHeight();
- } else if (settings.position == "center") {
- left = $(window).width() * 0.5 + $(window).scrollLeft() - own.outerWidth() * 0.5;
- top = $(window).height() * 0.5 + $(window).scrollTop() - own.outerHeight() * 0.5;
- }
- own.stop(true, false).animate({
- left: left,
- top: top
- });
- });
- }
- })(jQuery);