hscroll.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //水平滚动
  2. var ScrollTime;
  3. function ScrollAutoPlay(contID,scrolldir,showwidth,textwidth,steper){
  4. var PosInit,currPos;
  5. with($('#'+contID)){
  6. currPos = parseInt(css('margin-left'));
  7. if(scrolldir=='left'){
  8. if(currPos<0 && Math.abs(currPos)>textwidth){
  9. css('margin-left',showwidth);
  10. }
  11. else{
  12. css('margin-left',currPos-steper);
  13. }
  14. }
  15. else{
  16. if(currPos>showwidth){
  17. css('margin-left',(0-textwidth));
  18. }
  19. else{
  20. css('margin-left',currPos-steper);
  21. }
  22. }
  23. }
  24. }
  25. //--------------------------------------------左右滚动效果----------------------------------------------
  26. /*
  27. AppendToObj: 显示位置(目标对象)
  28. ShowHeight: 显示高度
  29. ShowWidth: 显示宽度
  30. ShowText: 显示信息
  31. ScrollDirection: 滚动方向(值:left、right)
  32. Steper: 每次移动的间距(单位:px;数值越小,滚动越流畅,建议设置为1px)
  33. Interval: 每次执行运动的时间间隔(单位:毫秒;数值越小,运动越快)
  34. */
  35. function ScrollText(AppendToObj,ShowHeight,ShowWidth,ShowText,ScrollDirection,Steper,Interval){
  36. var TextWidth,PosInit,PosSteper;
  37. with(AppendToObj){
  38. html('');
  39. css('overflow','hidden');
  40. css('height',ShowHeight+'px');
  41. css('line-height',ShowHeight+'px');
  42. css('width',ShowWidth);
  43. }
  44. if (ScrollDirection=='left'){
  45. PosInit = ShowWidth;
  46. PosSteper = Steper;
  47. }
  48. else{
  49. PosSteper = 0 - Steper;
  50. }
  51. if(Steper<1 || Steper>ShowWidth){Steper = 1}//每次移动间距超出限制(单位:px)
  52. if(Interval<1){Interval = 10}//每次移动的时间间隔(单位:毫秒)
  53. var Container = $('<div></div>');
  54. var ContainerID = 'ContainerTemp';
  55. var i = 0;
  56. while($('#'+ContainerID).length>0){
  57. ContainerID = ContainerID + '_' + i;
  58. i++;
  59. }
  60. with(Container){
  61. attr('id',ContainerID);
  62. css('float','left');
  63. css('cursor','default');
  64. appendTo(AppendToObj);
  65. html(ShowText);
  66. TextWidth = width();
  67. if(isNaN(PosInit)){PosInit = 0 - TextWidth;}
  68. css('margin-left',PosInit);
  69. mouseover(function(){
  70. clearInterval(ScrollTime);
  71. });
  72. mouseout(function(){
  73. ScrollTime = setInterval("ScrollAutoPlay('"+ContainerID+"','"+ScrollDirection+"',"+ShowWidth+','+TextWidth+","+PosSteper+")",Interval);
  74. });
  75. }
  76. ScrollTime = setInterval("ScrollAutoPlay('"+ContainerID+"','"+ScrollDirection+"',"+ShowWidth+','+TextWidth+","+PosSteper+")",Interval);
  77. }