【问题标题】:draggable background image not displaying on ipad可拖动的背景图像不显示在 ipad 上
【发布时间】:2013-06-07 09:01:24
【问题描述】:

我很绝望。我已经尝试了一百万种方法来让这个图像在桌面上工作,现在它是,我注意到它没有显示在 ipad 上。它可以在我的手机(galaxy s3)上使用,但不可拖动! :(

这是一张世界地图,希望它从欧洲开始,但可以拖动它以便查看整个图片。

当你看到这段代码时,你可能会感到恶心......对不起!!!

HTML

</div>
    <div id="screen"><h6>CTS WORLDWIDE INSTALLATIONS</h6>
</div>

CSS

#screen {
display:block;
float:left;
margin:25px 0 0 0;
width:699px; 
height:358px; 
background-image: url(http://ctsmedia.co.uk/_images/desktop/EMEA_map.png);
background-position: 50% 35%;
background-repeat: no-repeat;

}

脚本

$(document).ready(function(){
var $bg = $('#screen'),
    elbounds = {
        w: parseInt($bg.width()),
        h: parseInt($bg.height())
    },
    bounds = {w: 3609 - elbounds.w, h: 1858 - elbounds.h},
    origin = {x: -1361, y: -315},
    start = {x: -1361, y: -315},
    movecontinue = false;

function move (e){
    var inbounds = {x: false, y: false},
        offset = {
            x: start.x - (origin.x - e.clientX),
            y: start.y - (origin.y - e.clientY)
        };

    inbounds.x = offset.x < 0 && (offset.x * -1) < bounds.w;
    inbounds.y = offset.y < 0 && (offset.y * -1) < bounds.h;

    if (movecontinue && inbounds.x && inbounds.y) {
        start.x = offset.x;
        start.y = offset.y;

        $(this).css('background-position', start.x + 'px ' + start.y + 'px');
    }

    origin.x = e.clientX;
    origin.y = e.clientY;

    e.stopPropagation();
    return false;
}

function handle (e){
    movecontinue = false;
    $bg.unbind('mousemove', move);

    if (e.type == 'mousedown') {
        origin.x = e.clientX;
        origin.y = e.clientY;
        movecontinue = true;
        $bg.bind('mousemove', move);
    } else {
        $(document.body).focus();
    }

    e.stopPropagation();
    return false;
}

function reset (){
    start = {x: 0, y: 0};
    $(this).css('backgroundPosition', '0 0');
}

$bg.bind('mousedown mouseup mouseleave', handle);
$bg.bind('dblclick', reset);
});
</script>

非常感谢这位绝望的设计师的任何想法。

非常感谢

Ps.:哦,我对脚本一无所知。甚至没有 jquery 和 javascript 之间的区别......我是一个自学者

【问题讨论】:

  • 尝试在代码的倒数第四行使用$bg.bind('mousedown mouseup mouseleave touch touchstart touchend', handle);!您的代码中没有支持触摸设备的事件。也许这就是原因。
  • 谢谢,我会试一试,但我认为这可能是尺寸问题,dKen 指出如下。我会添加那行。谢谢!

标签: javascript jquery ipad draggable


【解决方案1】:

你的图片有多大?出于内存考虑,Mobile Safari 对图像的建议限制为 1024x1024,当超过该大小时,我已经让它的行为无法预测。我建议为手机/平板电脑尝试较小的图像。见:

Image size limitations in mobile safari?

编辑:我刚刚看到它是 3609x2105 像素。试试更小的版本

【讨论】:

  • 我要试试这个。图像很大,这可能是原因。谢谢!
  • 就是那个人。非常感谢。我现在需要为无法正确看到图标的问题找到解决方案...
猜你喜欢
  • 2018-01-09
  • 2013-09-30
  • 1970-01-01
  • 2017-07-27
  • 1970-01-01
  • 1970-01-01
  • 2014-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多