开发者

jQuery.Cycle showing small images at first load

I've got problem with jQuery.cycle plugin. At first load of page (when imgs aren't cached) it's showing small imgs, like thumbnails. You can see it at (edit: sorry, old link) - just wait when the second img开发者_开发技巧 shows - it's small. Reload/refresh solves it, but it's not real solution, you know.

Does anybody know what's the solution of this problem? Thanks a lot


Use $(window).load(function() { }); rather than $(document).ready(function() { });


Use overflow:hidden on the images container DIV


Same issue. Random images were getting inline styles of 24px x 24px. Rather than setting each image height and width, I did so through CSS. Since my width was a fixed width, I set that but set the height to 100%:

.ParentDiv img { width: 400px !important; height: 100% !important; }

The !important is necessary to override the inline styles applied by jQuery cycle.

This also seemed to solve another issue I was having with IE8. The page would load fine, but the images seemed to be loading after all the CSS and jquery loaded. This caused the box to not expand to fit the height and width of the images within. I imagine setting the width and height, the box holding the images was sized right off the bat.


I had the same issue and it was driving me crazy! I tried pre-loading the images, checked versions on everything etc to no avail.. The only thing that seemed to fix this was setting width and height on each picture on the page, rather than in css.


I solved this by setting the width and height in the <img> tag. But since I'm using a script to generate the list of images, and they sometimes have various sizes, I used a tiny bit of php to solve this:

function displayimage($filename) {
    $imgsize = getimagesize("$filename");
    echo "<img src=\"$filename\" $imgsize[3] />\n";
}

$imgsize[3] is, for example, width="585" height="285".

And then, to show all jpgs in the directory in the slideshow:

<div class="slideshow">
<?php
foreach (glob("*.jpg") as $filename) {
    displayimage($filename);
}
?>
</div>

Output

<div class="slideshow">
<img src="cat.jpg" width="575" height="256" />
<img src="dog.jpg" width="475" height="350" />
<img src="frog.jpg" width="675" height="300" />
</div>


While possibly not directly answer to the question (the jQuery.cycle plugin is unknown to me), many of the answers here address the problem of processing images after loading and that's also what people come here to seek for. So here it goes what's going on:

The 24px come up due to faulty logic on browser side - returning prematurely dimensions for a placeholder control. They have a different control-logic for handling cached images, IE does not even trigger onload for them, and that's why all the confusion comes up.

More reliable than (width===0) checking to be found all over the internet if an image is loaded, the .complete DOM property seldom mentioned apparently supported by all major browsers: http://www.w3schools.com/jsref/prop_img_complete.asp

this worked for me:

$("img")
    .one('load', onLoadRoutine)
    .each(function() {
        if(!this.complete) {
            return; //.one() will fire eventually
        } else {
            onLoadRoutine({delegateTarget:this}); //fake event object
        }
    });

Note the event mockup object {delegateTarget:this}. Preferable would be jQuery(this).trigger('load'), but I can't recommend it, since I didn't try it out at the time...

the .complete test should solve the case of the faulty 24px placeholder control's logic, the .one('load').each(). covers the control-flow split on cached/distant.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜