gpt4 book ai didi

javascript 和 css 过渡属性不适用于 firefox

转载 作者:行者123 更新时间:2023-11-28 07:21:57 25 4
gpt4 key购买 nike

我在浏览器上使用幻灯片菜单脚本 Slide in menu .我已按照给定的所有说明进行操作。最后它开始工作但仅适用于 chrome 和 safari 浏览器, 但我的主要目标是让它在 Firefox 上启动,我通过更改一些 CSS 和修改 JavaScript 尝试了几种方法, 在 JavaScript 中,我给了 alert() 来测试它是否在脚本内部移动,我发现所有的警报都以完美的顺序执行。 我没有得到任何暗示为什么会发生这件事。下面是带有 html 页面、JavaScript 和 css 的代码

html 页面

<html>
<head>

<link rel="stylesheet" type="text/css" href="css/new.css">
<script type="text/javascript" src="js/slideinmenu.js"></script>

<script type="text/javascript">
var menu;
function loaded() {
document.addEventListener('touchmove', function(e){ e.preventDefault();

e.stopPropagation(); });
menu = new slideInMenu('slidedownmenu', true);
}
document.addEventListener('DOMContentLoaded', loaded);
</script>
</head>

<body>
<div id="slidedownmenu">
<ul>
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
<li>Option 4</li>
</ul>
<div class="handle"></div>
</div>

<div id="content">


<p>Click to <a href="#" onclick="menu.open();return false">Open</a>, <a

href="#" onclick="menu.close();return false">Close</a> and <a href="#"

onclick="menu.toggle();return false">Toggle</a> the menu programmatically.</p>
</div>

</body>
</html>

JavaScript

 function slideInMenu (el, opened) {
this.container = document.getElementById(el);
this.handle = this.container.querySelector('.handle');
this.openedPosition = this.container.clientHeight;
this.container.style.opacity = '1';
this.container.style.top = '-' + this.openedPosition + 'px';
this.container.style.webkitTransitionProperty = '-webkit-transform';
this.container.style.webkitTransitionDuration = '400ms';
if ( opened===true ) {
this.open();
}
this.handle.addEventListener('touchstart', this);
}
slideInMenu.prototype = {
pos: 0,
opened: false,
handleEvent: function(e) {
switch (e.type) {
case 'touchstart': this.touchStart(e); break;
case 'touchmove': this.touchMove(e); break;
case 'touchend': this.touchEnd(e); break;
}
},
setPosition: function(pos) {
this.pos = pos;
this.container.style.webkitTransform = 'translate(0,' + pos + 'px)';
if (this.pos == this.openedPosition) {
this.opened = true;
} else if (this.pos == 0) {
this.opened = false;
}
},
open: function() {
this.setPosition(this.openedPosition);
},
close: function() {
this.setPosition("0");
},
toggle: function() {
if (this.opened) {
this.close();
} else {
this.open();
}
}
}

CSS

    a{
color:#ffc;
}
ul, li, div {
margin:0;
padding:0;
list-style:none;
}
#content {
padding:40px 10px 10px 10px;
text-align:center;
text-shadow:0 1px 1px #000;
font-size:1.2em;
}
#slidedownmenu {
position:absolute;
width:100%;
height:115px;
left:0;
background:black url(drawer-bg.jpg);
}
#slidedownmenu .handle {
position:absolute;
bottom:-28px;
left:0;
width:100%;
height:28px;
border-top:1px solid #532500;
border-bottom:1px solid #111;
background-color:maroon;
background:url(handle.png) no-repeat 50% 50%, -webkit-gradient(linear, 0 0, 0 100%, color-stop(0, #e07b29), color-stop(0.1, #b85300), color-stop(0.8, #793600));
/* -webkit-box-shadow:0 0 5px rgba(0,0,0,0.7);*/
}
#slidedownmenu ul {
display:block;
width:auto;
}
#slidedownmenu li {
display:block;
float:left;
margin:20px 10px;
text-align:center;
font-weight:bold;
color:#fff;
text-shadow:0 1px 1px #000;
}

任何类型的建议将不胜感激。

最佳答案

我已经找到了上述问题的解决方案,实际上是的,webkit 是用于 safari,但 Firefox,chrome,Internet-Explorer 10 支持标准语法,即在上面的 JavaScript 中

   this.container.style.webkitTransitionProperty = '-webkit-transform';

替换为

  this.container.style.transitionProperty = 'transform';

同理

  this.container.style.webkitTransitionDuration = '400ms';

  this.container.style.transitionDuration = '400ms';

this.container.style.webkitTransform = 'translate(0,' + pos + 'px)';

this.container.style.transform = 'translate(0,' + pos + 'px)';

并且它已准备好用于 Firefox 桌面浏览器。

基本上,现在我已经遵循了标准语法,而不是使用在 Firefox 桌面浏览器中工作得很好的 webkit。Firefox 支持标准样式语法,所以根据这个搜索,当转换在 Firefox 上不起作用时,只需使用标准语法css 如果你想让它在 Firefox 上运行,我测试了它并且它在桌面 Firefox 上工作得很好,但在移动 Firefox 浏览器上运行不流畅。

关于javascript 和 css 过渡属性不适用于 firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32043028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com