JQuery - Custom slider - Restricting the slide when it reaches the end -


i've written custom slider using jquery show thumbnails of images. i've outer div inside slider moves. when slides come end don't want slide further (both left , right). how can that?

here code - can save html , run -

<html> <head>     <title>content slider</title>     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>     <script type="text/javascript">         $(document).ready(function () {          });          function left() {             $('#inner').animate({                 'marginleft': "-=200px"             }, 1000, function () {             });         }          function right() {             if ($('#inner').css('marginleft') != "0px" && $('#inner').css('marginleft') != "auto") {                 $('#inner').animate({                     'marginleft': "+=200px"                 }, 1000, function () {                 });             }          }     </script> </head> <body>     <div style="width: 800px; height: 200px; border: 3px solid #dadada; overflow: hidden;         padding: 5px;">         <div id="inner" style="height: 190px; overflow: hidden;">             <table cellpadding="0" cellspacing="5" style="width: 100%; height: 190px;">                 <tr>                     <td valign="middle" align="center">                         <div style="width: 200px; height: 100px; background-color: #dadada">                         </div>                     </td>                     <td valign="middle" align="center">                         <div style="width: 200px; height: 100px; background-color: #dadada">                         </div>                     </td>                     <td valign="middle" align="center">                         <div style="width: 200px; height: 100px; background-color: #dadada">                         </div>                     </td>                     <td valign="middle" align="center">                         <div style="width: 200px; height: 100px; background-color: #dadada">                         </div>                     </td>                     <td valign="middle" align="center">                         <div style="width: 200px; height: 100px; background-color: #dadada">                         </div>                     </td>                     <td valign="middle" align="center">                         <div style="width: 200px; height: 100px; background-color: #dadada">                         </div>                     </td>                     <td valign="middle" align="center">                         <div style="width: 200px; height: 100px; background-color: #dadada">                         </div>                     </td>                     <td valign="middle" align="center">                         <div style="width: 200px; height: 100px; background-color: #dadada">                         </div>                     </td>                 </tr>             </table>         </div>     </div>     <table style="width: 800px">         <tr>             <td align="left">                 <a href="javascript:left();"><<</a>             </td>             <td align="right">                 <a href="javascript:right();">>></a>             </td>         </tr>     </table> </body> </html> 

any ideas?

i suggest check on total number of images not shown. in case = grand total - 4 (shown when page loaded)- call x. use sort of counter see margin left not decrease more 200*x.

code implementation:

 var x=4; //current total 8 (-4 gives x)         function left() { if( parseint($('#inner').css('marginleft'))>-x*200){ // 200 size of each image             $('#inner').animate({                 'marginleft': "-=200px"             }, 1000, function () {             });         } }  

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -