Skip to content

Re-size/orientation change with background images #42

@cscd98

Description

@cscd98

Hi,

When I use b-lazy to lazy load a background image set as data-src this works well. But my site is responsive so I am specifying data-src (default e.g. 320px or should that be the largest?), medium (770px) and large (> 771). When I re-size or re-orientate the device, the new image is not being used - only the one used first time is applied.

Also the data-src attributes are destroyed when b-lazy has finished applying.

My div:

<div class="b-lazy" src="placeholder.jpg"
     data-src-medium="/images/600/Specifications.jpg')"
     data-src-large="images/template/landingpage/features/980/Specifications.jpg">
</div>

My java script:

<script type="text/javascript">
        jQuery(document).ready(function($j) {
            var bLazy = new Blazy({
                breakpoints: [
                {
                    width: 770, // max-width
                    src: 'data-src-medium',
                    mode: 'viewport'
                },
                {
                    width: 99999, // max-width
                    src: 'data-src-large',
                    mode: 'viewport'
                }],
                selector: 'img,.b-lazy', // all images
                offset: 200 // Loads images 200px before they're visible
            });
        });
    </script>

I tried the following, but as of yet have been unable to get it to work:

var isIOS = /safari/g.test(navigator.userAgent.toLowerCase());
            var ev = isIOS ? 'orientationchange' : 'resize';
            var diff = (window.innerWidth-window.innerHeight);
            $j(window).bind(ev,function(){
                setTimeout(function(){
                    if(diff*((window.innerWidth-window.innerHeight)) < 0)
                        orientationChanged();
                }, 500);
            });

            function orientationChanged() {
                console.log("orientation changed");
                $j('div.b-lazy').removeClass('b-loaded');
                bLazy.revalidate();
            }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions