views:

248

answers:

3

This code works is FF and IE but not in Chrome. Any help would be greatly appreciated. Thank You! Realized that this code works fine on its own but when its hosted on this page (http://www.automotive-fleet.com) it doesn't work in Chrome and Safari. I can't figure out why. Any help would be appreciated.

here is the html

<div id="popularsearches">
<div id="popularsearches-inside">
    <div id="popularsearches-left">
                <ul>
                <li>Item One </li>
                <li>Item Two </li>
                <li>Item Three </li>
                <li>Item Four </li>
                <li>Item Five</a> </li>
                </ul>
    </div>
    <div id="popularsearches-right">
                <ul>
                <li>Item Six </li>
                <li>Item Seven </li>
                <li>Item Eight </li>
                <li>Item Nine </li>
                <li>Item ten </li>
                </ul>
    </div>
</div>
</div>

here is the css

#popularsearches
{
    border-bottom: 1px solid #D4D4D4;
    border-left: 1px solid #D4D4D4;
    border-right: 1px solid #D4D4D4;
    overflow:hidden;    
    height: 130px;    width:248px;
   margin-bottom:20px;
}

#popularsearches ul
{
    padding:0 5px 0 0;
    margin:0;
}

#popularsearches ul li
{
    list-style-type:none;
    list-style-position:inside;
    border-bottom: solid 1px #D4D4D4;
    font-size:14px;
    padding:3px 0 3px 0;
    margin:0 0 0 10px;
    text-align:left;
}

#popularsearches ul li a
{
    text-decoration:none;
}

#popularsearches ul li a:hover, a:link, a:visited
{
    text-decoration:none;
}

#popularsearches-inside
{
    width: 500px;
}

#popularsearches-left
{       
    float:left;
    width:250px;
    height:100px;
}

#popularsearches-right
{       
    float:left;
    width:250px;
    height:100px;
}

here is the jQuery

    var closeinterval = 0;

    function scrollContent() {
        //Toggle left between 250 and 0
        var top = jQuery("#popularsearches").scrollLeft() == 0 ? 250 : 0;            
        jQuery("#popularsearches").animate({ scrollLeft: top }, "slow");
    }

    // Call scrollContent function every 6 secs
    closeinterval = setInterval("scrollContent()", 6000);

    jQuery(document).ready(function() {
        jQuery("#popular-button-left").bind("click", function() {
            if (closeinterval) {
                window.clearInterval(closeinterval);
                closeinterval = null;
            }

            jQuery("#popularsearches").animate({ scrollLeft: 0 }, 1000);
        });
        jQuery("#popular-button-right").bind("click", function() {
            if (closeinterval) {
                window.clearInterval(closeinterval)
                closeinterval = null;
            }

            jQuery("#popularsearches").animate({ scrollLeft: 250 }, 1000);                
        });
    });
+1  A: 

Could it be the iffy markup in the following div?

<div id="popularsearches-left">
            <ul>
            <li>Item One </li>
            <li>Item Two </li>
            <li>Item Three </li>
            <li>Item Four </li>
            <li>Item Five</a> <-- renegade closing tag</li>
            </ul>
</div>
karim79
+4  A: 

Change this line:

closeinterval = setInterval("scrollContent()", 6000);

To this:

closeinterval = setInterval(scrollContent, 6000);

This fixed it for me.. see example here

Matt
@Matt - `setInerval` takes Javascript expressions so `setInterval("scrollContent()", 6000)` is valid. The reason it isn't working is because your code on jsfiddle is wrapped in an onLoad callback function and the function `scrollContent` does not exist outside of it. However, when you simply pass the function to `setInterval`, it has a direct reference to the function so scope doesn't matter. Change the setting from `onLoad` to `No wrap` on the top left, and OP's code should work as is.
Anurag
@Anurag - I was wondering why Matt's wasn't working with `"scrollContent()"` and yours was until I noticed the `No wrap` option for the first time. Was about to leave a comment, but you covered it. :)
patrick dw
That makes me feel better, actually, because I was just removing it because I hate `eval`. I was taken by complete surprise that it made a difference, but, eh, I'm too willing to accept mysteries I guess ;)
Matt
Sorry for the poor formatting on the jquery code. I tried removing the quotes from "scrollContent()" on the setInterval() function and it still doesn't work in Chrome. Works in IE and FF though. Thanks for you input. Much appreciated!
Paul
@Paul I'm using Chrome and it works great.. are you getting any errors in the console? In fact, as the comments above point out, your code (without changes) does actually work. See [here](http://jsfiddle.net/PkxvF/).
Matt
The `no wrap` setting tripped me a lot of times. It's a tiny little setting that can be super hard to spot.
Anurag
I was getting and error on the console. It said something about a bad token. I couldn't pin point. Just rewrote the code. and it works. Not sure what the problem is. Well I appreciate your help. Take care.
Paul
A: 

Validate your HTML...

zazk
not sure what you mean by this.
Paul