javascript - 防止在 Firefox 中拖动图像
问题描述
我有一个与旋转木马中的背景图像的链接。问题在于,每当用户拖动轮播时,图像都会被拖动,而在拖动时会出现重影图像。这会导致轮播的拖动行为不一致。我尝试使用user-select : none
,但它只适用于 Chrome 和 Edge。如何在 Firefox 中禁用图像拖动?添加draggable="false"
锚标记也不起作用
在 Firefox 中运行以下代码进行测试。尝试拖动图像并观察行为。
.disable-dragging {
display: block;
width: 200px;
height: 200px;
background-image: url("https://homepages.cae.wisc.edu/~ece533/images/fruits.png");
background-size: cover;
background-color: #cccccc;
user-select: none;
}
<a href="#" class="disable-dragging" draggable="false"></a>
解决方案
您错过了=
HTML 属性中的
<a href="#" class="disable-dragging" draggable="false"></a>
并删除user-select: none;
完整的工作代码
.disable-dragging {
display: block;
width: 200px;
height: 200px;
background-image: url('https://homepages.cae.wisc.edu/~ece533/images/fruits.png');
background-size: cover;
background-color: #cccccc;
/* user-select: none; */
}
<a href="https://google.com" class="disable-dragging" draggable="false"></a>
更新:
正如@kaiido 在评论user-select
中所说,这里有影响。
并且是 Firefox 中的一个未解决问题 - https://bugzilla.mozilla.org/show_bug.cgi?id=1376369
推荐阅读
- opencv - 如何修复“未定义对符号'vxCannyEdgeDetectorNode'的引用”错误在yocto上编译openvx
- asynchronous - 等待异步函数完成
- javascript - 为什么 HTML/JAVASCRIPT 无法识别我设置的密码?
- r - rmarkdown:编织 pdf 文档时的新行为
- firebase - Firebase 存储安全规则和上传文件的下载令牌
- apache-spark - 在纱线集群上提交火花作业时,Log4j 不显示日志
- r - 在 reactiveValues 函数中使用反应输出时 .getReactiveEnvironment()$currentContext() 出错
- c# - 如何在 WebApi 中对 XboxLive 用户进行身份验证
- css - CSS显示:无;不能在 Firefox 中工作。我怎样才能解决这个问题?
- python - 根据熊猫数据框中的条件分组查找匹配行