[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

set/get a data attribute, for loop closure prob

jrough

3/12/2015 3:32:00 AM

I have a jsfiddle, http://jsfiddle.net/jlrough...
the images are missing but I can tell you what it is doing. If you click the previous or next links it moves the carousel image forward or backward okay.

The problem is when you do the hover. Whichever dot you hover on it makes all the images go forward to the end instead of stopping on the one you hover on.

The error I'm trying to fix is the For loop which is a closure. The hover function should not get the value of i from the For loop. So as a hack to solve it I tried to put the value of i in a data attribute. However it doesn't seem like my data method is setting or getting the data attribute. TIA,
2 Answers

Christoph M. Becker

3/13/2015 1:59:00 AM

0

JRough wrote:

> I have a jsfiddle, http://jsfiddle.net/jlrough...
> the images are missing but I can tell you what it is doing. If you click the previous or next links it moves the carousel image forward or backward okay.
>
> The problem is when you do the hover. Whichever dot you hover on it makes all the images go forward to the end instead of stopping on the one you hover on.
>
> The error I'm trying to fix is the For loop which is a closure. The hover function should not get the value of i from the For loop. So as a hack to solve it I tried to put the value of i in a data attribute. However it doesn't seem like my data method is setting or getting the data attribute. TIA,

Just a quick note. Don't use this:

for (var i = 0; i < $('.carousel-dots-nav-item').length; i++) {

but *rather* something like:

$(".carousel-dots-nav-item").each(...)

That should solve your binding issues.

--
Christoph M. Becker

jrough

3/13/2015 4:47:00 PM

0

On Wednesday, March 11, 2015 at 8:32:35 PM UTC-7, JRough wrote:
> I have a jsfiddle, http://jsfiddle.net/jlrough...
> the images are missing but I can tell you what it is doing. If you click the previous or next links it moves the carousel image forward or backward okay.
>
> The problem is when you do the hover. Whichever dot you hover on it makes all the images go forward to the end instead of stopping on the one you hover on.
>
> The error I'm trying to fix is the For loop which is a closure. The hover function should not get the value of i from the For loop. So as a hack to solve it I tried to put the value of i in a data attribute. However it doesn't seem like my data method is setting or getting the data attribute. TIA,

thanks it was supposed to be easy but I couldn't see it.