Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery show and hide elements according to position
    primarykey
    data
    text
    <p>I am trying to make a carousel of sorts. I am kind of stuck with hiding and displaying the next and precious buttons once a div moves to the far left and right of its container.</p> <p>I think i have everything correct regarding calculating the widths but for some reason when you click the buttons, elements stay hidden irrespective of the conditional comments which should dictate when they should be hidden or shown.</p> <p>Here is a link to what i have thus far. Click the MoveLeft and MoveRight buttons. <a href="http://www.ehbeat.com/test/" rel="nofollow noreferrer">http://www.ehbeat.com/test/</a></p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function () { //Check width of Gallery div var galleryWidth = $("#Gallery").innerWidth(); //Check width of GalleryItem var galleryItemWidth = $(".GalleryItem").innerWidth(); //Check distance from left var position = $('.GalleryItem').position(); var galleryItemLeft = position.left; $(".MoveRight").click(function () { $(".GalleryItem").animate({ "left": "+=50px" }, "slow"); $(".GalleryItem2").animate({ "left": "+=100px" }, "slow"); }); $(".MoveLeft").click(function () { $(".GalleryItem").animate({ "left": "-=50px" }, "slow"); $(".GalleryItem2").animate({ "left": "-=100px" }, "slow"); }); $(".Controls").live('click', function () { if (galleryItemLeft &gt;= "0") { $('.MoveRight').hide(); } else { $('.MoveRight').show(); } }); if (galleryItemWidth == galleryWidth - galleryItemWidth) { $('.MoveLeft').hide(); } }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload