jquery implements simple seamless scrolling

  • 2020-05-30 19:21:29
  • OfStack

jquery implements simple seamless scrolling


<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title></title>
  <script src="jquery-1.7.2.min.js" type="text/javascript"></script>
</head>
<style>
  *{ margin: 0px; padding: 0px;}
  li{ list-style: none;}
  .content{ width: 1020px; height:112px; overflow: hidden; border: #4e83c2 solid 1px; margin:50px auto; }
  .content ul{ width: 1020px; height:100px;}
  .content ul li{ float: left; width: 100px; height: 100px; border:#ccc solid 1px; display: block; margin: 5px;}

</style>
<body>
<div class="content">
<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
  <li>7</li>
  <li>8</li>
  <li>9</li>
  <li>10</li>
  <li>11</li>
  <li>12</li>
  <li>13</li>
  <li>14</li>
  <li>15</li>
  <li>16</li>
  <li>17</li>
  <li>18</li>
  <li>19</li>
  <li>20</li>
  <li>21</li>
  <li>22</li>
  <li>23</li>
  <li>24</li>
</ul>
</div>
<script>
 function scroll(){
 $(".content ul").animate({"margin-left":"-110px"},function(){
   $(".content ul li:eq(0)").appendTo($(".content ul"))
   $(".content ul").css({"margin-left":0})
 })
 }
  setInterval(scroll,1000)
</script>
</body>
</html>

scroll () usage:


function scroll(){
   $(".content ul").animate({"margin-left":"-110px"},function(){
   // This is to make the whole thing ul I'm going to slide it forward li , If you want to 1 Time sex sliding 5 a ~ It is 550px.
  // If I want to scroll up I'm going to change it  $(".content ul").animate({"margin-top":"-105px"}
  // If I want to scroll down, I'm going to change it  $(".content ul").animate({"margin-top":"105px"}
  // I want to scroll to the right  $(".content ul").animate({"margin-left":"110px"}
     $(".content ul li:eq(0)").appendTo($(".content ul"))
     $(".content ul").css({"margin-left":0})
  // This is this side right here 
  // If I want to scroll up I'm going to change it  $(".content ul").animate({"margin-top":0}
  // If I want to scroll down, I'm going to change it  $(".content ul").animate({"margin-top":0}
  // I want to scroll to the right  $(".content ul").animate({"margin-left":0}
   })
   }
    setInterval(scroll,1000)
  // This is up here 1000 It's the speed at which you roll, and you can adjust it 

That's all for this article, I hope you enjoy it.


Related articles: