【问题标题】:Images scaled in safari & chrome but not in ff & opera图像在 safari 和 chrome 中缩放,但在 ff 和 opera 中没有
【发布时间】:2013-02-25 15:10:34
【问题描述】:

我正在使用一个名为 jb gallery 3.0 的图像滑块 - 使用 jQuery 运行。

它只是一个普通的图像滑块,但它有一个功能可以检测浏览器的大小,然后将图像缩放到浏览器的大小,即。如果您在 iPad 上观看,它会给您一个较小的图像,以便您仍然可以看到整个图片。

每次在滑块中加载图像时都会调整大小,因此如果您在幻灯片之间调整窗口大小,则下次加载图像时它将被缩放...无需刷新页面。

这一切在 safari 和 chrome 中都可以正常工作,但在 Firefox 和 opera (12.14) 中却不行,它只提供裁剪后的全尺寸图像...

我已经对这里发生的事情做了一个 js 小提琴 - http://jsfiddle.net/ktvvW/5/ - 尝试在 chrome 或 safari 中调整“结果”面板的大小,看看会发生什么。

知道为什么这在 ff 或 opera 中不起作用吗?

.

干杯

【问题讨论】:

  • 不为我在 FF 中调整大小。
  • @isherwood,这就是它在 ff 中不起作用的问题
  • 抱歉。我看错了。不幸的是,目前我的 SO 时间有限,我无法提供帮助。

标签: javascript jquery css jquery-ui cross-browser


【解决方案1】:

在 jbgallery-3.0.js 脚本上强制执行 webkit 行为似乎可以解决问题。 请参阅下面的选项,我正在强制 webkit 为真(忽略 userAgent)。 我已经在 FF 和 Opera 上对此进行了测试,并且功能符合预期,图像以与 Chrome 中相同的缩放比例显示。

$(".jbgallery").jbgallery({  
    style    : "zoom",       //"centered"|"zoom"|"original" - image style  
    menu     : "simple",         //false|"numbers"|"simple"|"slider" - menu type  
    shortcuts: [37, 39],         //[prev,next] - keyboard code shortcuts  
    slideshow: true,            //true|false - autostart slideshow  
    fade     : true,             //true|false - disable all fade effects  
    popup    : false,            //true|false - modal box & traditional popup hack to display multiple gallery (3.0 : fullscreen:false)  
    randomize: 0,                //0|1|2 - randomize first image (1) or randomize "slideshow" (2) - blackout: http://www.grayhats.org  
    caption  : false,             //true|false - show/disable internal caption system  
    autohide : false,            //true|false - auto hide menu & caption  
    clickable: false,            //true|false - "image click & go"  
    current  : 1,                //number     - set initial photo (modal "hack" - see demo. don't use "hash". jbgallery use "location.hash" only in popup mode)  
//    webkit   : (navigator.userAgent.toLowerCase().search(/webkit/) != -1),  //boolean - used for specific browser hack. if you want, you can force disable this flag & try to find crossbrowser solution  
    webkit   : true,
    ie6      : (/MSIE 6/i.test(navigator.userAgent)), //boolean - IDEM  
    ie7      : (/MSIE 7/i.test(navigator.userAgent)), //boolean - IDEM  
    labels   : {                 //labels of internal menu  
        play : "play",  
        next : "next",  
        prev : "prev",  
        stop : "stop",  
        close: "close",  
        info : "info"  
    },  
    timers   : {                 //timers   
        fade    : 1000,           //fade duration  
        interval: 3000,          //slideshow interval  
        autohide: 7000           //autohide timeout  
    },  
    delays: {                    //delays (timers) to improve usability and reduce events  
        mousemove: 200,          //used by autohide. cancel autohide timeout every XXXms.   
        resize   : 10,          //used by ie6 to reduce events handled by window.resize  
        mouseover: 800           //used by tooltip. show tooltip only if the mouse STAY over thumb for XXXms  
    },  
    close    : function(){},     //callback handled by menu's button close. see demo. example : close : function(){window.close()}  
    before   : function(){},     //callback handled BEFORE image gallery loaded  
    after    : function(ev){},   //callback(ev) handled AFTER image gallery loaded. receive the native load event.  
    load     : function(ev){},   //callback(ev) handled AFTER native image load event. receive the native load event.  
    ready    : function(el){$('.jbg-menu').hide(); $('.jbg-loading').remove(); $('.jbg-caption').remove(); $('.jbg-menu-opacity').remove();},   //callback(el) handled AFTER jbgallery render. receive the HTML element.  
    fullscreen: false,            //true|false : the most important feature of jbgallery 3.0. now jbgallery can "stay in a box" and have multiple istance in one page.  
    push      : function(o){},   //callback handled by push public method (JBGALLERY API). receive the object/string/array of objects/array of strings passed from external. useful for external menu system  
    unshift   : function(o){},   //callback handled by unshift public method (JBGALLERY API). receive the object/string/array of objects/array of strings passed from external.  
    shift     : function(){},    //callback handled by shift public method   
    pop       : function(){},    //callback handled by pop public method   
    empty     : function(){}     //callback handled by empty public method   
});

这是link to my jsfiddle

【讨论】:

    【解决方案2】:

    似乎是 CSS 有问题。

    原创

    .jbgallery .jbgallery-target.zoom {
        min-height: 50%;
        min-width: 50%;
    }
    

    修改

    .jbgallery .jbgallery-target.zoom {
        height: 50%;
        width: 50%;
    }
    

    错误必须在css面板中添加css,因为原来是在插件css中

    这里是新 css 的链接http://jsfiddle.net/ktvvW/8/

    【讨论】:

    • 谢谢,但是将 css 更改为此会拉伸和扭曲图像的比例以使其适合浏览器窗口。与 chrome 和 safari 中的原始版本一样,它混合使用图像缩放和裁剪来不断填充浏览器窗口。
    【解决方案3】:

    我想我知道该怎么做:

    改变加载函数如下:

    load     : function(ev){$(".zoom").css("width",$("#slider").width()),$(".zoom").css("height","auto");$(".zoom").css("left","0px");$(".zoom").css("top","auto")},
    

    它适用于所有浏览器,经过测试并成功运行

    【讨论】:

      【解决方案4】:

      我没有完整的答案,但我过去也遇到过类似的问题。我了解到 Gecko (Firefox) 和 Webkit (Safari 和 Chrome) 处理图像的方式不同。当我尝试缩放图像时,图像大小的信息不可用,因此无法使用相同的代码对其进行缩放。

      我只能建议对图像 + onload 事件进行一些研究。在我看来,这将是一个 javascript 问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-09-27
        • 1970-01-01
        • 2015-04-27
        • 2011-12-09
        • 2011-02-15
        • 2014-09-06
        • 1970-01-01
        • 2016-07-07
        相关资源
        最近更新 更多