I have a list of items within a scrollable (jQuery tools)…
It’s shows 3 items/figures at a time, when clicking the next button, it’s shows the 3 next…
The thing im trying to do, is that i want do for example call a webservice, when the items that are showed within the scrollable area, the items that arent showed in the scrollable area, should do nothing – Only when clicking the next button, and the 3 next items are showed…
My HTML output looks like this:
<div id="adbelt">
<div class="ad-container">
<div id="prevnext">
<a class="next carouselbutton"><span>next</span></a>
<a class="prev carouselbutton"><span>prev</span></a>
</div>
<div id="belt">
<div class="scrollable" id="scrollable">
<div class="items">
<figure>
<a target="_blank" title="http://www.dis-play.dk/" href="http://www.dis-play.dk/">
</a>
<figcaption>
<span>Skarp</span>
<div class="fig-text">og lige til</div>
</figcaption>
<input type="hidden" name="ctl10$phadlist_0$hiddenFieldAdGuid" id="ctl10_phadlist_0_hiddenFieldAdGuid" value="B2A276D78E764528900B723F144117A7" />
</figure>
<figure>
<a target="_blank" title="DIS/Play" href="http://www.dis-play.dk">
<img src="~/media/DISPLAY/Default/defaultAdImage.ashx" class="slide-banner" alt="Kaffe" width="300" height="150" />
</a>
<figcaption>
<span>Forbrugsforeningen 2</span>
<div class="fig-text">har det hele</div>
</figcaption>
<input type="hidden" name="ctl10$phadlist_1$hiddenFieldAdGuid" id="ctl10_phadlist_1_hiddenFieldAdGuid" value="75011C876D04465D865B34FA6DC2CBE3" />
</figure>
<figure>
<a target="_blank" title="http://www.dis-play.dk/" href="http://www.dis-play.dk/">
</a>
<figcaption>
<span>Skarp</span>
<div class="fig-text">og lige til</div>
</figcaption>
<input type="hidden" name="ctl10$phadlist_2$hiddenFieldAdGuid" id="ctl10_phadlist_2_hiddenFieldAdGuid" value="B2A276D78E764528900B723F144117A7" />
</figure>
<figure>
<figcaption>
<span></span>
<div class="fig-text"></div>
</figcaption>
<input type="hidden" name="ctl10$phadlist_3$hiddenFieldAdGuid" id="ctl10_phadlist_3_hiddenFieldAdGuid" value="BE7DA9601D4840B981A1E5305E01786F" />
</figure>
<figure>
<a target="_blank" title="DIS/Play" href="http://www.dis-play.dk">
<img src="~/media/DISPLAY/Default/defaultAdImage.ashx" class="slide-banner" alt="Kaffe" width="300" height="150" />
</a>
<figcaption>
<span>Forbrugsforeningen 2</span>
<div class="fig-text">har det hele</div>
</figcaption>
<input type="hidden" name="ctl10$phadlist_4$hiddenFieldAdGuid" id="ctl10_phadlist_4_hiddenFieldAdGuid" value="75011C876D04465D865B34FA6DC2CBE3" />
</figure>
<figure>
<figcaption>
<span></span>
<div class="fig-text"></div>
</figcaption>
<input type="hidden" name="ctl10$phadlist_5$hiddenFieldAdGuid" id="ctl10_phadlist_5_hiddenFieldAdGuid" value="BE7DA9601D4840B981A1E5305E01786F" />
</figure>
</div>
</div>
</div>
</div>
I’ve tried this:
$("#belt figure").each(function () {
if ($(this).filter(':visible')) {
alert("visible");
//Do something, like calling a webservice
} else {
alert("not visible");
//Dont call webservice
}
});
I’ve tried looking at the jquery.appear plugin, but it doesnt seem to support the thing i want?
You could probably just loop through only visible figures if that’s the only ones you are interested in
Or if you’re looking to do something with each figure based on their visibility, I think you’re looking for the
is()method:edit: I now see that you’re trying something else. If you want to see if it’s visible within an area, you need to do something else.
:visiblewill be true if the element isn’tdisplay:noneorvisibility:hidden.So you need to check the height of the scrollable area and the
scrollTop, then check theoffsetof each figure against those numbers to see if it’s visibleedit2: Is it something like this you had in mind?