Morsusy2k Posted October 6, 2013 Share Posted October 6, 2013 Okay so I have 10 images in one div in a row (with overflow:hidden). I would like to make them move to the left so the others can show up. I added two div-buttons and my code looks like this: $(document).ready(function(){ $(function(){ //next button $('#napred').click(function(){ //div holding the images $('#nove').animate({left: "-=500"}, 200); }); //back button $('#nazad').click(function(){ $('#nove').animate({left: "+=500"}, 200); }); });}); And this works what its supposed to do, BUT there is one problem and that is that you can keep scrolling the images till infinity. I would like to add restrictions eg. if #nove left property is higher than 15px you are able to click next but not back button, and if less than -1350 you could click on back button but not on the next. This is what I came up to but it fails to work: $(document).ready(function(){ $(function(){ var b = 15; var c = -1350; $('#napred').click(function(){ var a = $("#nove").css('left'); if (a < { $('#nove').animate({left: "-=500"}, 200); } }); $('#nazad').click(function(){ var a = $("#nove").css('left'); if (a) > c){ $('#nove').animate({left: "+=500"}, 200); } }); });}); I would appreciate if someone could help me solve this problem and I can bet that solution is simple :DThanks Link to comment Share on other sites More sharing options...
dsonesuk Posted October 6, 2013 Share Posted October 6, 2013 1) is 1350 total width of images?, because as left: works from the left side you require length to left edge of last image, so if total width of all images is 1350 and last image is 350 width, you should be working to 1000, not 1350. 2) check when you are retrieving left value, it does not include unit, some browsers will give -350px instead of -350, use parseInt(). Link to comment Share on other sites More sharing options...
Morsusy2k Posted October 6, 2013 Author Share Posted October 6, 2013 Thanks for the tip I made it work Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now