账号通
    

账号  

密码  

4132

查看

1

回复
主题:[分享]jQuery元素定位插件-浮动定位 一行代码搞定! [收藏主题]  
licaifuwu 当前离线

653

主题

10

广播

17

粉丝
添加关注
级别:六年级

用户积分:1585 分
登录次数:361 次
注册时间:2010/11/19
最后登录:2019/5/7
licaifuwu 发表于:2011/1/26 16:48:48   | 显示全部帖子 查看该作者主题 楼主 

做右下角广告 QQ客服等等 不会被清理广告软件清理的哦!仅需一行代码搞定!



  1. /*
  2. * jQuery Plugins elementFixed v1205
  3. * 使用说明:
  4. * $('#div1').elementFixed({position:"leftTop"}); //定位左上
  5. * $('#div2').elementFixed({position:"leftBottom"}); //定位左下
  6. * $('#div3').elementFixed({position:"rightTop"}); //定位右上
  7. * $('#div4').elementFixed({position:"rightBottom"}); //定位右下
  8. * $('#div5').elementFixed({position:"leftCenter"}); //定位左中
  9. * $('#div6').elementFixed({position:"rightCenter"}); //定位右中
  10. * $('#div7').elementFixed({position:"topCenter"}); //定位上居中
  11. * $('#div8').elementFixed({position:"bottomCenter"}); //定位底居中
  12. * $('#div9').elementFixed({position:"center"}); //定位居中
  13. * $('#div4').elementFixed(); //不给参数默认定位为右下
  14. */
  15. (function($) {
  16. jQuery.fn.elementFixed = function(options) {
  17. var own = this;
  18. var settings = {
  19. position: "rightBottom"
  20. };
  21. jQuery.extend(settings, options);
  22. own.css({
  23. position: "absolute",
  24. left: 0,
  25. top: 0,
  26. zIndex: 1000
  27. });
  28. $(window).bind("scroll resize load",
  29. function() {
  30. var left = 0;
  31. var top = 0;
  32. if (settings.position == "leftTop") {
  33. left = $(window).scrollLeft();
  34. top = $(window).scrollTop();
  35. } else if (settings.position == "rightTop") {
  36. left = $(window).width() + $(window).scrollLeft() - own.outerWidth();
  37. top = $(window).scrollTop();
  38. } else if (settings.position == "leftBottom") {
  39. left = $(window).scrollLeft();
  40. top = $(window).height() + $(window).scrollTop() - own.outerHeight();
  41. } else if (settings.position == "rightBottom") {
  42. left = $(window).width() + $(window).scrollLeft() - own.outerWidth();
  43. top = $(window).height() + $(window).scrollTop() - own.outerHeight();
  44. } else if (settings.position == "leftCenter") {
  45. left = $(window).scrollLeft();
  46. top = $(window).height() * 0.5 + $(window).scrollTop() - own.outerHeight() * 0.5;
  47. } else if (settings.position == "rightCenter") {
  48. left = $(window).width() + $(window).scrollLeft() - own.outerWidth();
  49. top = $(window).height() * 0.5 + $(window).scrollTop() - own.outerHeight() * 0.5;
  50. } else if (settings.position == "topCenter") {
  51. left = $(window).width() * 0.5 + $(window).scrollLeft() - own.outerWidth() * 0.5;
  52. top = $(window).scrollTop();
  53. } else if (settings.position == "bottomCenter") {
  54. left = $(window).width() * 0.5 + $(window).scrollLeft() - own.outerWidth() * 0.5;
  55. top = $(window).height() + $(window).scrollTop() - own.outerHeight();
  56. } else if (settings.position == "center") {
  57. left = $(window).width() * 0.5 + $(window).scrollLeft() - own.outerWidth() * 0.5;
  58. top = $(window).height() * 0.5 + $(window).scrollTop() - own.outerHeight() * 0.5;
  59. }
  60. own.stop(true, false).animate({
  61. left: left,
  62. top: top
  63. });
  64. });
  65. }
  66. })(jQuery);

 
  支持(0) | 反对(0) 回到顶部顶端 回到底部底部
<上一主题 | 下一主题 >
Powered By KesionCMS Version X1
厦门科汛软件有限公司 © 2006-2016 页面执行0.07813秒 powered by KesionCMS 9.0