troubleshooting Question

Jquery page jump

Avatar of Luey
LueyFlag for United States of America asked on
JavaScriptjQuery
6 Comments1 Solution495 ViewsLast Modified:
Hello I have some jquery code that works but has a problem of jumping about 200 pixels up the page every time I run the function.  It is an image slide show that is setting all children in the div to display none. Then sets the first child to display block.  Each time next_image is clicked i am just hiding the current element and fading in the next element.  It all works except for the page jump. (not back to the top)  Any help would be appreciated.

$(window).load(function () {
   
   var count = $("#pro_images > img").length;
     if  (count > 1){
   $("#next_image").show();
	 }
	 
   $("#pro_images").children().css('display', 'none');
    $("#pro_images img:first-child").css('display', 'block');
	$("#pro_images img:first-child").addClass('first');
	$("#pro_images img:last-child").addClass('last');

    $("#prev_image").click(leftNextImage);
    $("#next_image").click(rightNextImage);
  
var currentElement = $("#pro_images img:first-child")
 
function rightNextImage() {
	
	$(currentElement).hide().next().fadeIn(600);
	currentElement = currentElement.next();
	$("#prev_image").show();
	
	if   (currentElement.hasClass("last")) {
		$("#next_image").hide();
         }
		  
}///end rightNextImage


function leftNextImage() {
	
	$(currentElement).hide().prev().fadeIn(600);
	currentElement = currentElement.prev(); 
	$("#next_image").show();
	
	if   (currentElement.hasClass("first")) {
		$("#prev_image").hide();
         }
} ///end leftNextImage
});
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros