【发布时间】: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