Results 1 to 3 of 3

Thread: Pairing the LazyLoad fade in effect with text

  1. #1
    Join Date
    Sep 2006

    Pairing the LazyLoad fade in effect with text


    I have a web page which has a number of images each in their own div and with html rendered text in each div too - something like:

    HTML Code:
    <div class="yui3-u-1-3 first promosLeft" style="width: 318px; margin: 0 0 0 15px;"> 
                <a href="/somepage" title="Image"><img class="lazy" src="http://www.mysite.com/image.gif")" alt="Alt Text" width="318" height="394"  style="display:block" border="0"></a> 
                <a class="ed1 textFade" href="/somepage" style="position: absolute; left: 412px; top:226px; font-family: Times,'Times New Roman', serif; font-size: 16px; line-height: 18px; text-align: center; text-decoration:none; color:#000;" title="Image">Text to fade in when image loads</a>
                <a class="textFade" href="/somepage" style="position: absolute; left: 439px; top:276px; font-family:Helvetica, Arial, sans-serif; text-decoration:none; color:#000; font-size:18px; font-weight: bold !important;" title="Sell Link">More text to fade in when image loads</a>
    So the page loads fine, LazyLoad works perfectly on the images, as the page is scrolled the images fade in. I have used the following coder to achieve this:

        effect : "fadeIn"
    What I am trying to do is fade in the html text relevant to each specific div - that is all text with the class textFade, at the same time as the image. I have achieved this through the following code, but through testing it seems a bit heavy in Firefox and IE7:

    <script type="text/javascript">
    $(document).ready(function () {
        $(".textFade").each(function() {
            var container = $(this).parent(),
            offset = container.offset(),
            pageBottom = $(window).scrollTop() + $(window).height();
            if (offset.top <= pageBottom) {
            } else {
                $(window).scroll(function() {
                    $(".textFade").each(function() {
                        var containerScrolled = $(this).parent(),
                        x = containerScrolled.offset(),
                        containerScrolledPosTop = x.top,
                        containerScrolledHeight = containerScrolled.height() *.9,
                        containerScrolledVisible = containerScrolledPosTop + containerScrolledHeight,
                        pageBottomScrolled = $(window).scrollTop() + $(window).height();
                        if (containerScrolledVisible <= pageBottomScrolled) {
    Does anyone have any ideas about how I can make this code more lightweight, or how I can actually plug this function into LazyLoad itself, so that it triggers each time after an image is loaded?

    I have seen this code on the LazyLoad website and think I can probably modify it?

    $(function() {          
            event : "sporty"
    $(window).bind("load", function() { 
        var timeout = setTimeout(function() {
        }, 5000);
    I'm not sure exactly what that code is doing, but if "sporty" is the name of a function, should I be able to give my function a name and simply replace "sporty" with whatever my function is called?

    I'm a bit lost with this and would appreciate any help!

  2. #2
    Join Date
    Jan 2013

    same Problem here.


    just read your post. i'm dealing with the same problem.

    Though as a complete beginner i cannot really follow the solution you illustrated and do all my coding in a more or less trial and error mode.

    Anyways. The same guy who developed LazyLoad also did something called Viewport Selector.

    I plugged that on my site and it......had an effect:


    The code does not look very clean or elegant but see what I mean? the text is triggered by the Viewport Selector.

    This piece of code can be also found in the LazyLoad Code, so I tried to trigger this one. So far no sucess. maybe you have an idea.

    How far is your own attempt? Could you manage to make it run?


  3. #3
    Join Date
    Sep 2006
    Hi Mic,

    Thanks for sharing this.

    Briefly let me explain, I'm quite a beginner too - but I got a book published by SitePoint called jQuery Novice to Ninja, and found a bit of code in there and coupled that with some code I had used on a previous website, to bring together two aspects of functionality to make my script work. What my script does is this.

    1) It targets text blocks with a class of "textFade" and fades them into the page - in my example these are anchor tags with the class "textFade".
    2) however before fading them in, it checks the position of the element containing the text blocks (the containing block - in my case an html div). If the containing block is in the viewport - calculated by using jQuery to detemine the window height plus the amount the window has been scrolled (value a) and comparing this with the offset of the containing block plus the containing blocks height (value b). So if value b is less than value a, the text with the class "textFade" within the containing block will fade in.

    The function is divided into 2, the first part checks for the text to fade in on page load, and the second part handles what happens once the page scrolls, note the $(window).scroll(function()...

    Hope that makes sense, not very good at explaining things!

    Anyway my code has problems in IE7 and to a lesser extent on Firefox, I have been working on a revised version which seems to be more lightweight, but needs more testing. The code on jsfiddle does work, but again it appears to have problems in IE7/8. I think I may end up running alternative code that simply fades the text blocks in regardless of where they are on the page for IE7/8.

    I will check all this out later this week and let you know. If you have any success, let me know too.
    Last edited by A_Tame_Lion; 01-07-2013 at 03:22 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.09723 seconds
  • Memory Usage 2,874KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (3)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates