Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • sdfsfm 70 posts 94 karma points
    Sep 03, 2010 @ 10:48
    sdfsfm
    0

    Lazy loading images on scroll

    Hi I'm in the process of setting up my portfolio, But as the images & content associated with the image are fairly large in size I want to load them dynamic on a page scroll, Kind of simliar to how Bing and Google images works.

    I'm using Infinite Scroll jQuery plugin by Paul Irish, which i got working with a static html file, but can't figure out what to do for Umbraco.

    Do I create an xslt file which displays all the content i want to show, and then somehow hook that into the plugin? A web service(heard somewhere in the forum that it might be needed), but I have no .net coding experience.

     

    I've added in The script, and xslt i am currently using, if it helps.

      $(function(){
    /* */
    $('#portfolio').infinitescroll({

    navSelector : "a#next:last",
    loadingImg : "img/ajax-loader.gif",
    loadingText : "",
    donetext : "",
    nextSelector : "a#next:last",
    itemSelector : ".portfolio-item",
    contentSelector: null,
    //localMode : true
    // selector for all items you'll retrieve

    });

    });

    The xslt: basically i have a docType called work which needs to display the items on a page scroll, the single items are kept in work-item

    <!-- Input the documenttype you want here -->
    <xsl:variable name="documentTypeAlias" select="string('work-item')"/>
    <xsl:template match="/">

    <!-- The fun starts here -->


    <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">

    <article class="portfolio-item clearfix">
    <ul>
    <li>
    <xsl:if test="./workImage!=''">
    <a href="{umbraco.library:NiceUrl(@id)}" >
    <xsl:variable name="media" select="umbraco.library:GetMedia(./workImage, 0)" />
    <xsl:variable name="url" select="$media/umbracoFile" />
    <xsl:variable name="width" select="$media/umbracoWidth" />
    <xsl:variable name="height" select="$media/umbracoHeight" />
    <img src="{$url}" width="{$width}" height="{$height}" />

    </a>
    </xsl:if>
    <!--<img src="img/portfolio-temp.png" alt="icon" width="1060" height="346" border="0" />-->

    </li>
    </ul>
    <section class="column colWidth700">
    <h2 ><xsl:value-of select="workTitle"/></h2>
    <xsl:value-of select="workText" disable-output-escaping="yes" />

    </section>
    <section class="column colWidth280 fR portfolio">
    <h3>Services</h3>
    <xsl:value-of select="workServices" disable-output-escaping="yes"/>

    <a href="{umbraco.library:NiceUrl(@id)}" class="btn fR"><xsl:value-of select="workLinkText" disable-output-escaping="yes"/></a>
    <a id="next" href="{umbraco.library:NiceUrl(@id)}">next page?</a><!-- this is need to call the next item using the plugin-->
    </section>
    </article>


    </xsl:for-each>
    </xsl:template>
  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 03, 2010 @ 11:54
    Matt Brailsford
    0

    Hi Ivor,

    From what I've read, I reckon all you need is some paging system in your macro (so it only shows x many items at a time) then just create an alternative template that retuns just the content. Then when you're JS requests the next page, it just gets the content for the page (minus the surround) and drops it in the container.

    I did something similar on this site:

    http://www.todd-white-art.com/art/editions.aspx

    Not infinate scrolling, but similar idea, when you click the paging links, it loads the content dynamically rather than moving away.

    Not a solid answer to your problem, but hopefully gives you a starting point, and by all means rip any source you need from that site.

    Matt

  • sdfsfm 70 posts 94 karma points
    Sep 03, 2010 @ 12:13
    sdfsfm
    0

    HI Matt,

    Thanks for the reply, your link you posted doesn't work though.

  • Rich Green 2246 posts 4008 karma points
    Sep 03, 2010 @ 12:23
    Rich Green
    0

    It works if you change .co.uk to .com

    http://www.todd-white-art.com/art/editions.aspx

    (nice work matt, is that search XSLT or Examine?)

    Rich

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 03, 2010 @ 12:35
    Matt Brailsford
    0

    Ooops, my bad, you are right, it's .com not .co.uk (I've updated the link in my original post).

    @Rich - It's just XSLT based as it's Umbraco 4.0.x

    Matt

  • sdfsfm 70 posts 94 karma points
    Sep 03, 2010 @ 12:36
    sdfsfm
    0

    @Rich thanks for that :P

    @Matt, I like what you are doing there, however i dont want actually want pagination, The idea is that the user only needs to scroll to load up the next item. I'll have a play with your example and try modify it to fit my needs.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 03, 2010 @ 12:41
    Matt Brailsford
    0

    Hi Ivor,

    Infinate paging though isn't that different to what I've done, the only thing different is that you don't get rid of the previous set of results. The logic and everything else behind it should be exactly the same.

    1) Hit page show 10 results
    2) Scroll to bottom, trigger load (essentialy like clicking the next button on my paging example), load next 10 results and append to bottom
    3) Scroll to bottom, repeat previous step

    Matt

  • sdfsfm 70 posts 94 karma points
    Sep 03, 2010 @ 17:06
    sdfsfm
    0

    Hi Matt,

     

    This is how far I've got with the xslt. I got it from an old blogpost from www.nibble.be

    <xsl:template match="/">
    <!--
    =============================================================
    VARIABLES
    =============================================================
    -->
    <xsl:variable name="recordsPerPage" select="1"/>
    <xsl:variable name="pageNumber">
    <xsl:choose>
    <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 1 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name="numberOfRecords" select="count($currentPage/* [@isDoc])"/>

    <!--
    =============================================================
    For Each child node of the currentpage
    =============================================================
    -->
    <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
    <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber - 1) and position() &lt;= number($recordsPerPage * number($pageNumber - 1) + $recordsPerPage )">

    <article class="portfolio-item clearfix">
    <ul>
    <li>
    <img src="img/portfolio-temp.png" alt="icon" width="1060" height="346" border="0" />
    </li>
    </ul>
    <section class="column colWidth700">
    <h2 ><xsl:value-of select="workTitle"/></h2>
    <xsl:value-of select="workText" disable-output-escaping="yes" />

    </section>
    <section class="column colWidth280 fR portfolio">
    <h3>Services</h3>
    <xsl:value-of select="workServices" disable-output-escaping="yes"/>

    <a href="{umbraco.library:NiceUrl(@id)}" class="btn fR"><xsl:value-of select="workLinkText" disable-output-escaping="yes"/></a>

    </section>
    </article>

    </xsl:if>
    </xsl:for-each>

    <xsl:if test="(($pageNumber) * $recordsPerPage) &lt; ($numberOfRecords)">
    <p class='loadMore'>Load more <a id="next" href="{umbraco.library:NiceUrl(@id)}">next page?</a></p>
    </xsl:if>
    </xsl:template>

    How ever i just can't get it it to show any items on the page, any ideas?[sorry i'm still a toddler when it comes to xslt]

  • Iulia Maria Jensen 40 posts 71 karma points
    Oct 09, 2012 @ 15:06
    Iulia Maria Jensen
    0

    Hi Ivor,

    Did you manage to make this work? I am now trying to do something similar with using Paul Irish's infinite scroll and showcasing some elements on scroll out of an alternative template. Unfortunatelly, it doesn't seem to be able to pass my URL.

    I'd love to hear if you've found a solution for your situation.

     

  • ibrahim TUNC 55 posts 133 karma points
    Dec 08, 2015 @ 22:07
    ibrahim TUNC
    0

    Hi Julia.

    If you have a solution about this(Lazy Loading), can you share with us? Thanks best regards.

Please Sign in or register to post replies

Write your reply to:

Draft