我有一個導航欄,有一個漢堡菜單按鈕。在添加打開/關閉JavaScript動畫之前,導航菜單適用於所有瀏覽器。在幾個較老的瀏覽器上,如果點擊該腳本,則不幸的是,該腳本將不能阻止菜單打開。但它適用於大多數較新的瀏覽器。如果腳本不能正確執行以讓舊瀏覽器能夠打開導航欄,我需要停止腳本。如果/否則Javascript語句禁用過渡動畫失敗
我已經編寫了一個簡單的修復程序來停止腳本執行,如果「某事」是錯誤的。
if (something == false) {
<!--animation script goes here -->
stop
}
將「某物」改變爲不同的東西給了我有趣的結果。如果我將其更改爲
if (data == false) {
<!--animation script goes here -->
stop
}
然後,即使在之前完美運行動畫的瀏覽器中,它也會完全停止腳本。
我的問題是,如果腳本沒有成功運行,我可以用什麼替換「某事」以使腳本停止?
這裏是動畫腳本,如果你需要的話。 (不要讓它嚇到你了。我需要的是,如果動畫無法停止此腳本。)
! function() {
"use strict";
function e() {
var e, t = document.createElement("div"),
n = {
transition: "transitionend",
OTransition: "otransitionend",
MozTransition: "transitionend",
WebkitTransition: "webkitTransitionEnd"
};
for (e in n)
if (n.hasOwnProperty(e) && void 0 !== t.style[e]) return n[e];
return !1
}
function t(e) {
var t = {};
e = e || window.event, t.evTarget = e.currentTarget || e.srcElement;
var n = t.evTarget.getAttribute("data-target");
return t.dataTarget = n ? document.querySelector(n) : !1, t
}
function n(e) {
var t = e.style.height;
e.style.height = "auto";
var n = getComputedStyle(e).height;
return e.style.height = t, e.offsetHeight, n
}
function a(e, t) {
if (document.createEvent) {
var n = document.createEvent("HTMLEvents");
n.initEvent(t, !0, !1), e.dispatchEvent(n)
} else e.fireEvent("on" + t)
}
function r(e, t) {
e.classList.remove("collapse"), e.classList.add("collapsing"), t.classList.remove("collapsed"), t.setAttribute("aria-expanded", !0), e.style.height = n(e), u ? e.addEventListener(u, function() {
s(e)
}, !1) : s(e)
}
function i(e, t) {
e.classList.remove("collapse"), e.classList.remove("in"), e.classList.add("collapsing"), t.classList.add("collapsed"), t.setAttribute("aria-expanded", !1), e.style.height = getComputedStyle(e).height, e.offsetHeight, e.style.height = "0px"
}
function s(e) {
e.classList.remove("collapsing"), e.classList.add("collapse"), e.setAttribute("aria-expanded", !1), "0px" !== e.style.height && (e.classList.add("in"), e.style.height = "auto")
}
function o(e) {
e.preventDefault();
var n = t(e),
a = n.dataTarget;
return a.classList.contains("in") ? i(a, n.evTarget) : r(a, n.evTarget), !1
}
function l(e) {
function n() {
try {
i.parentNode.removeChild(i), a(i, "closed.bs.alert")
} catch (e) {
window.console.error("Unable to remove alert")
}
}
e.preventDefault();
var r = t(e),
i = r.dataTarget;
if (!i) {
var s = r.evTarget.parentNode;
s.classList.contains("alert") ? i = s : s.parentNode.classList.contains("alert") && (i = s.parentNode)
}
return a(i, "close.bs.alert"), i.classList.remove("in"), u && i.classList.contains("fade") ? i.addEventListener(u, function() {
n()
}, !1) : n(), !1
}
function c(e) {
e = e || window.event;
var t = e.currentTarget || e.srcElement;
return t.parentElement.classList.toggle("open"), !1
}
function d(e) {
e = e || window.event;
var t = e.currentTarget || e.srcElement;
return t.parentElement.classList.remove("open"), e.relatedTarget && "dropdown" !== e.relatedTarget.getAttribute("data-toggle") && e.relatedTarget.click(), !1
}
for (var u = e(), g = document.querySelectorAll("[data-toggle=collapse]"), v = 0, f = g.length; f > v; v++) g[v].onclick = o;
for (var p = document.querySelectorAll("[data-dismiss=alert]"), h = 0, m = p.length; m > h; h++) p[h].onclick = l;
for (var L, T = document.querySelectorAll("[data-toggle=dropdown]"), y = 0, E = T.length; E > y; y++) L = T[y], L.setAttribute("tabindex", "0"), L.onclick = c, L.onblur = d}();
我想有人可能能夠只是說類似「如果(過渡==假) {停止}「或者那樣做,那將是完美的。
只是一個小提示:'transition == false'與'!transition'和'transition'是相同的。但與問題無關。 –
[這裏](http://stackoverflow.com/questions/6506349/if-browser-css3)是可以幫助你的東西。 –
@KevinKloet謝謝你的分享。我不知道這個JavaScript動畫與ccs3有什麼關係!那麼,通過這些信息,我應該在動畫腳本之前和之後添加哪些內容,以使其不能執行不兼容的瀏覽器? –