No Description

index.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //var userId = null;
  2. //var str=location.href; //取得整个地址栏
  3. //var num=str.indexOf("?");
  4. //str=str.substr(num+1); //str得到?之后的字符串
  5. //var brr=str.split("&");
  6. //for(var i = 0 ; i<brr.length; i++){
  7. // if(brr[i].indexOf('userId') != -1){
  8. // userId = brr[i].split('=')[1];//用户id
  9. // }
  10. //}
  11. //页面加载,显示数据
  12. window.onload = function () {
  13. Lead() ;
  14. }
  15. //领红包
  16. function collarRed() {
  17. $("#index").css("display","none");
  18. $("#invitation").css("display","block")
  19. // $.ajax({
  20. // type:"post",
  21. // url:"/api/V2/receiveRedPacket",
  22. // data:{
  23. // user_id:userId
  24. // },
  25. // success: function (res) {
  26. // var data =JSON.parse(res)
  27. // console.log(data)
  28. // if(data.code == 0){
  29. // copyPassword();
  30. // }else if(data.code == 4003){
  31. // showMsg("领取失败")
  32. // }else if(data.code == 4002){
  33. //// showMsg(data.message)
  34. // copyPassword();//不限制新老用户
  35. // }
  36. // }
  37. // })
  38. }
  39. //已领红包
  40. function Lead() {
  41. $.ajax({
  42. type:"post",
  43. url:"/api/V2/returnRedPacket",
  44. success: function (res) {
  45. var data =JSON.parse(res)
  46. // console.log(data)
  47. if(data.code == 0){
  48. var dataArr = data.res.list,html = '',numHtml = '', name = '' , img = '';
  49. numHtml +='已有'+ data.res.count +'位用户领取红包';
  50. dataArr.forEach(function (item, index) {
  51. if(item.user_name){
  52. name = item.user_name;
  53. }else{
  54. name = '匿名';
  55. }
  56. if(item.user_img){
  57. img = item.user_img;
  58. }else{
  59. img = 'images/moren.png'
  60. }
  61. html += '<li><img src='+ img +' /><span class="username">'+ name +'</span><span class="ed">领取了红包</span><span class="day">'+ item.received_time +'</span></li>'
  62. })
  63. $('.num').html(numHtml);
  64. $('.roll-wrap ul').html(html)
  65. }
  66. new scrollTxt().init();
  67. }
  68. })
  69. }
  70. function scrollTxt(){
  71. var controls={},
  72. values={},
  73. t1=800, /*播放动画的时间*/
  74. t2=1500, /*播放时间间隔*/
  75. si;
  76. controls.rollWrap=$("#roll-wrap");
  77. controls.rollWrapUl=controls.rollWrap.children();
  78. controls.rollWrapLIs=controls.rollWrapUl.children();
  79. values.liNums=controls.rollWrapLIs.length;
  80. values.liHeight=45;
  81. values.ulHeight=controls.rollWrap.height();
  82. this.init=function(){
  83. autoPlay();
  84. // pausePlay();
  85. }
  86. /*滚动*/
  87. function play(){
  88. controls.rollWrapUl.animate({"margin-top" : "-"+values.liHeight}, t1, 'linear',function(){
  89. $(this).css("margin-top" , "0").children().eq(0).appendTo($(this));
  90. });
  91. }
  92. /*自动滚动*/
  93. function autoPlay(){
  94. /*如果所有li标签的高度和大于.roll-wrap的高度则滚动*/
  95. if(values.liHeight*values.liNums > values.ulHeight){
  96. si=setInterval(function(){
  97. play();
  98. },t2);
  99. }
  100. }
  101. /*鼠标经过ul时暂停滚动*/
  102. function pausePlay(){
  103. controls.rollWrapUl.on({
  104. "mouseenter":function(){
  105. clearInterval(si);
  106. }
  107. ,
  108. "mouseleave":function(){
  109. autoPlay();
  110. }
  111. });
  112. }
  113. }
  114. /**
  115. * [showMsg 提示各种错误信息,3s后消失]
  116. */
  117. function showMsg(msg) {
  118. var msgBox = $('.alert-info');
  119. msgBox.children('p').text(msg);
  120. msgBox.show();
  121. setTimeout(function() {
  122. msgBox.hide();
  123. }, 3000);
  124. }