jquery.scroll.floor.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. (function(window){
  2. var defaults = {
  3. floorClass : '.scroll-floor',
  4. navClass : '.scroll-nav',
  5. activeClass : 'active',
  6. activeTop : 100,
  7. scrollTop : 100,
  8. delayTime : 200
  9. };
  10. var $body = $('body'),floorList = null,navList = null;
  11. function getItem(_list,newOptions){
  12. var data = [];
  13. _list.each(function() {
  14. var item = {};
  15. item.$obj = $body.find(this);
  16. item.$activeTop = $body.find(this).offset().top - newOptions.activeTop;
  17. item.$scrollTop = $body.find(this).offset().top + newOptions.scrollTop;
  18. data.push(item);
  19. });
  20. return data;
  21. }
  22. function scrollActive(_list,newOptions){
  23. var nowScrollTop = $(window).scrollTop();
  24. var data = getItem(floorList,newOptions);
  25. $.each(data,function(i,item){
  26. if(nowScrollTop > item.$activeTop){
  27. _list.removeClass(newOptions.activeClass).eq(i).addClass(newOptions.activeClass);
  28. }
  29. });
  30. var Xht = $('.y_v3Flow').offset().top;
  31. if (nowScrollTop > (Xht-200)) {
  32. $('.y_v3homeNav_main ul').scrollLeft(216);
  33. }else{
  34. $('.y_v3homeNav_main ul').scrollLeft(0);
  35. }
  36. }
  37. function clickActive(_index,newOptions){
  38. var data = getItem(floorList,newOptions);
  39. $('html,body').animate({'scrollTop' : data[_index].$scrollTop},newOptions.delayTime);
  40. }
  41. var scroll_floor = window.scrollFloor = function(options){
  42. var newOptions = $.extend({}, defaults, options);
  43. floorList = $body.find(newOptions.floorClass);
  44. navList = $body.find(newOptions.navClass);
  45. scrollActive(navList,newOptions);
  46. $(window).bind('scroll',function(){scrollActive(navList,newOptions);});
  47. navList.bind('click',function(){
  48. var _index = $body.find(this).index();
  49. clickActive(_index,newOptions);
  50. });
  51. }
  52. })(window);