Saturday 15 February 2014

javascript - marginLeft only resets if called twice -


I created a basic carousel type slash, although for this to work, I had to call the following function twice Actually set margin-left property to 0 pixels.

$ ("# slide ul"). Stop (). CSS ('margin lift', '0 pixels');

I was wondering what I'm doing wrong, because I'm new to jquery.

The entire thing can be found here

Javascript for convenience: var offset = 0; Count count; Var width = 500; Var Height = 333; Var interval; $ (Document) .ready (function () {count = $ ("# slide ul"). Children (). Length; // Finally add the first image so that loops. $ ("# Slide ul"). First () clone (). Attachment ("# slide ul"); start ();}); The next image of the function () {$ ("# slide ul"). Stop (); Offset + = width; If (offset / width == calculation) {$ ("# slide ul"). ({'Margin left': '-' + offset + 'px', 700, 'linear', reset image); } $ ("# Slide ul") Chetan ({'margin left': '-' + offset + 'px', 700); Return Offset; } Function resetImage () {$ ("# slide ul"). Stop (). CSS ('margin lift', '0 px'); $ ("# Slide ul"). Stop (). CSS ('margin lift', '0 pixels'); Offset = 0; //Start(); } Function stop () {clear interval (interval); } Start function () {interval = set interval (Next image, 3000); }

I JQuery 1.9.1

Are you loading two animations in the queue?

  if (offset / width == calculation) {$ ("# slide ul"). Emimate ({'margin left': '-' + offset + 'px', 700, 'linear', reset image); } $ ("# Slide ul") Chetan ({'margin left': '-' + offset + 'px', 700);   

Maybe you want to:

  if (offset / width == calculation) {$ ("# slide ul"). (Chetan ({'marginLeft': '-' + offset + 'px'}, 700, 'linear', reset image); and {$ ("# slide ul"). Chetan ({'margin left': ' - '+ offset +' px '', 700);}   

I think that .stop () only stops the current animation and clears the queue So do not miss the animation before.

No comments:

Post a Comment