newhip Posted May 12, 2013 Share Posted May 12, 2013 Hey guys, I modified a script that i found on the web and and i'm trying to use it as a thumbnail gallery scroller (for lack of better words).The problem i'm running into right now is that when i click either the left or the right buttons all of the boxes scroll. I'm trying to use the (this) "selector" but i'm having trouble figuring it out can someone perhaps help me a bit with this one? would be greatly appreciated. Here's the html. <div class="container"> <div class="arrowL"><img src="left.png" width:'20'; height:'100'; /> </div> <div class="arrowR"><img src="right.png" width:'20'; height:'100';/> </div> <div class="list-container"> <div class='list'> <div class="item"> </div> <div class="item"> </div> <div class="item"> </div> <div class="item"> </div> <div class="item"> </div> <div class="item"> </div> </div> </div> </div> The css. .item{ background-color:#FFFFFF; width:120px; height:90px; margin:5px; float:left; position:relative; } .container{ width:1000px; height:100px; } .list-container { display:inline-block; overflow:hidden; width: 960px; float:left; } .list{ background:grey; min-width:1500px; float:left; } .arrowR{ width:20px; height:100px; float:right; cursor:pointer; opacity:0.5; } .arrowL{ width:20px; height:100px; float:left; cursor:pointer; opacity:0.5; } And the js. <script> $(document).ready(function() { var $item = $('div.item'), visible = 7, index = 0, endIndex = ( $item.length / visible ) - 1; $('div.arrowR').click(function(){ if(index < endIndex ){ index++; $item.animate({'left':'-=300px'}); } }); $('div.arrowL').click(function(){ if(index > 0){ index--; $item.animate({'left':'+=300px'}); } }); }); </script> Anyone know what i'm doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/277916-animate-one-at-the-time/ Share on other sites More sharing options...
jazzman1 Posted May 12, 2013 Share Posted May 12, 2013 Simple mathematic, in that case if endIndex = ( $item.length / visible ) - 1 the result should be a signed integer (negative number). So, use (*) instead (/) - endIndex = ( $item.length * visible ) - 1 and try again. Quote Link to comment https://forums.phpfreaks.com/topic/277916-animate-one-at-the-time/#findComment-1429664 Share on other sites More sharing options...
newhip Posted May 12, 2013 Author Share Posted May 12, 2013 hmm i'm not quite sure if i know what you're talking bout. I'm trying use the same javascript code and several sliders. Quote Link to comment https://forums.phpfreaks.com/topic/277916-animate-one-at-the-time/#findComment-1429667 Share on other sites More sharing options...
jazzman1 Posted May 12, 2013 Share Posted May 12, 2013 Hey newhip, the entindex is equal to "(6 / 7) -1", so you will get a negative number as a result and that statement has never been executed - if(index < endIndex ) b/s the index is set to zero! I don't know what exactly your code is doing but after a quick check yesterday night I saw that error. PS: A nice cat, I have a one which weights 15 pounds Quote Link to comment https://forums.phpfreaks.com/topic/277916-animate-one-at-the-time/#findComment-1429728 Share on other sites More sharing options...
newhip Posted May 12, 2013 Author Share Posted May 12, 2013 oh, the script still works though ill check that part out i guess ill just write different ones for each bar i make. lol i have a fat cat too but that's not a picture of mine Quote Link to comment https://forums.phpfreaks.com/topic/277916-animate-one-at-the-time/#findComment-1429778 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.