0

Hey all, I'm new to JavaScript and I'm using the jQuery library for this. Basically I'm trying to create multiples of this line and I'm using ":eq(0) to do it. The issue is that :eq(0) repeats 3 times in the code and with the loop that I'm doing every time it repeats it has a different number.

This is what I'm getting from it i think (:eq(0), :eq(1),:eq(2), :eq(3), etc..) I need it to do this (:eq(0),:eq(0),:eq(0), :eq(1) :eq(1) :eq(1), etc...)

for (i = 0; i < 6; ++i) {
    var $titleMarquee = '<marquee scrollamount="5" direction="left" width="233" align="left" behavior="alternate" loop="1"><span>';
    var $lieq = "li:eq("+i+")";
    $("ul.side-block-content "+$lieq+"").mouseenter(function() {
        $("ul.side-block-content "+$lieq+" .article-title a span")
            .replaceWith($titleMarquee+$("ul.side-block-content "+$lieq+" .article-title a").text()+"</span></marquee>");
    });
}

If anyone can let me know how to do this loop correctly, or maybe how to recreate the code for it to do the same thing that would be great.

Thanks in advance.

@Nick's answer:

var $titleMarquee = '<marquee scrollamount="5" direction="left" width="233" align="left" behavior="alternate" loop="1"><span>';
    for (i = 0; i < 6; ++i) {
        for (j = 0; j < 7; ++j) {
        $("ul.side-block-content li:eq("+i+")").mouseenter(function(){$("ul.side-block-content li:eq("+i+") .article-title a span").replaceWith($titleMarquee+$("ul.side-block-content li:eq("+i+") .article-title a").text()+"</span></marquee>");});
        $("ul.side-block-content li:eq("+i+")").mouseleave(function(){$("ul.side-block-content li:eq("+i+") .article-title a marquee").replaceWith('<span>'+$("ul.side-block-content li:eq("+i+") .article-title a").text()+"</span>");});  
        }
    }

This is what I'm using now and it's not working. Am I doing it correctly?

@Gilly3

$("ul.side-block-content li marquee").each(function() {
    this.stop();              // prevent the marquee from scrolling initially
    }).mouseenter(function() {
    this.start();             // start the scroll onmouseenter
    });

<marquee scrollamount="5" direction="left" width="233" align="left" behavior="alternate">
7
  • 3
    marquee has been deprecated outside of the first child of blink. Commented Apr 18, 2011 at 23:30
  • @alex: Shhhh. We're trying to let the blink tag die peacefully. Commented Apr 18, 2011 at 23:39
  • marquee isn't in HTML it's a browser-based code. But that's irrelevant to the question. Commented Apr 18, 2011 at 23:42
  • @user Here. :) Commented Apr 18, 2011 at 23:46
  • Didn't you already ask this question? Commented Apr 18, 2011 at 23:48

2 Answers 2

1

It looks like you are trying to make your <li> text scroll when you hover over it. Is that right?

Just put the marquee code in the original html and do this:

$(function ()
{
    $("ul.side-block-content li marquee").each(function() {
        this.stop();              // prevent the marquee from scrolling initially
    }).mouseenter(function() {
        this.start();             // start the scroll onmouseenter
    });
});

I also want to say not to use the marquee tag since it is deprecated and to use a jQuery plugin instead, but the last jQuery marquee plugin I saw was actually using a <marquee> in the back end anyway. So... pfft.

Sign up to request clarification or add additional context in comments.

2 Comments

That's a genius way to do it! But I tried it and it doesn't stop it initially. Maybe I'm doing it wrong? I've updated my question with what I'm doing.
Make sure your code is run inside a domready handler. Ie, $(function () { /* your code here */ });
0

You could embed another for loop inside, like so:

for (i = 0; i < 6; ++i) {
  for (j = 0; j < 3; ++j) {
    // repeat i three times, and use :eq("+i+")
  }
}

3 Comments

Could you be more specific in that answer, I tried that but it wasn't doing anything for me.
@user Think of it as for every time the outer loop loops, the inner loop will loop three times.
I've edited my question with what I changed according to this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.