July 12, 201214 yr Hi guys, I have this script for a simple slideshow below and I need the box of the slideshow to be in percentage rather then pixels. I highlighted the part where I think it should go but how do i go about in doing this>? Thank you so much <script type="text/javascript"> $(document).ready(function() { var currentPosition = 0; var slideWidth = 600; var slides = $('.slide'); var numberOfSlides = slides.length; var slideShowInterval; var speed = 9000; slideShowInterval = setInterval(changePosition, speed); slides.wrapAll('<div id="slidesHolder"></div>') slides.css({ 'float' : 'left' }); $('#slidesHolder').css('width', slideWidth * numberOfSlides); function changePosition() { if(currentPosition == numberOfSlides - 1) { currentPosition = 0; } else { currentPosition++; } moveSlide(); } function moveSlide() { $('#slidesHolder') .animate({'marginLeft' : slideWidth*(-currentPosition)}); } }); </script><!-- Rotator script stops -->
July 12, 201214 yr I think you should get the width of the screen with screen.availWidth. Than you just have to divide the amount of pixels with the available width , and multiply it by 100. Lets say you want to have the precentage of 600 pixels: precentage=600/screen.availWidth*100; Now you can use precentage in your jQuery code. Edited July 12, 201214 yr by Leonvv
Create an account or sign in to comment