tympaniplayer
tympaniplayer

Reputation: 171

How can I can I get scrollTo to work correctly

I have a multiple select list defined like this

<select id="MyId" multiple="multiple">
    <option value = 1>This is one</option>
     etc...
</select>

I am trying to use the scrollTo plugin like this

$("#MyId option").scrollTo("[value=1]", 100)

I have tried a few different combinations with no results.

Does anyone have any idea what I am doing wrong?

Edit: I want to be able to scroll to any given value. Not just 1

Upvotes: 0

Views: 98

Answers (2)

tympaniplayer
tympaniplayer

Reputation: 171

.scrollTop, nor.position() returned a pixel value (they returned 0). So instead I used .index() on the value I was searching for in my option elements. I then multiplied it by the height of one element in the select lis. Ithen used scrollTop(), passing in the value found previous

Upvotes: 0

Amit
Amit

Reputation: 22076

You should use scrollTop() of jQuery

$("#MyId option").scrollTop(100);

Here you can read about it. and try it.

Upvotes: 1

Related Questions