gpt4 book ai didi

javascript - 汉堡菜单展开并立即关闭

转载 作者:行者123 更新时间:2023-11-30 15:04:58 25 4
gpt4 key购买 nike

我的 wordpress 网站上有汉堡菜单。说到响应能力,一切正常,但 iPad 纵向。问题是 - 当我点击汉堡包菜单时,它会展开一秒钟然后立即关闭。相反,它应该保持打开状态。我有以下 app.js 文件:

!function ($) {


/* COLLAPSE PUBLIC CLASS DEFINITION
* ================================ */

var Collapse = function (element, options) {
this.$element = $(element)
this.options = $.extend({}, $.fn.collapse.defaults, options)

if (this.options.parent) {
this.$parent = $(this.options.parent)
}

this.options.toggle && this.toggle()
}

Collapse.prototype = {

constructor: Collapse

, dimension: function () {
var hasWidth = this.$element.hasClass('width')
return hasWidth ? 'width' : 'height'
}

, show: function () {
var dimension
, scroll
, actives
, hasData

if (this.transitioning || this.$element.hasClass('in')) return

dimension = this.dimension()
scroll = $.camelCase(['scroll', dimension].join('-'))
actives = this.$parent && this.$parent.find('> .accordion-group > .in')

if (actives && actives.length) {
hasData = actives.data('collapse')
if (hasData && hasData.transitioning) return
actives.collapse('hide')
hasData || actives.data('collapse', null)
}

this.$element[dimension](0)
this.transition('addClass', $.Event('show'), 'shown')
$.support.transition && this.$element[dimension](this.$element[0][scroll])
}

, hide: function () {
var dimension
if (this.transitioning || !this.$element.hasClass('in')) return
dimension = this.dimension()
this.reset(this.$element[dimension]())
this.transition('removeClass', $.Event('hide'), 'hidden')
this.$element[dimension](0)
}

, reset: function (size) {
var dimension = this.dimension()

this.$element
.removeClass('collapse')
[dimension](size || 'auto')
[0].offsetWidth

this.$element[size !== null ? 'addClass' : 'removeClass']('collapse')

return this
}

, transition: function (method, startEvent, completeEvent) {
var that = this
, complete = function () {
if (startEvent.type == 'show') that.reset()
that.transitioning = 0
that.$element.trigger(completeEvent)
}

this.$element.trigger(startEvent)

if (startEvent.isDefaultPrevented()) return

this.transitioning = 1

this.$element[method]('in')

$.support.transition && this.$element.hasClass('collapse') ?
this.$element.one($.support.transition.end, complete) :
complete()
}

, toggle: function () {
this[this.$element.hasClass('in') ? 'hide' : 'show']()
}

}


/* COLLAPSE PLUGIN DEFINITION
* ========================== */

var old = $.fn.collapse

$.fn.collapse = function (option) {
return this.each(function () {
var $this = $(this)
, data = $this.data('collapse')
, options = $.extend({}, $.fn.collapse.defaults, $this.data(), typeof option == 'object' && option)
if (!data) $this.data('collapse', (data = new Collapse(this, options)))
if (typeof option == 'string') data[option]()
})
}

$.fn.collapse.defaults = {
toggle: true
}

$.fn.collapse.Constructor = Collapse


/* COLLAPSE NO CONFLICT
* ==================== */

$.fn.collapse.noConflict = function () {
$.fn.collapse = old
return this
}


/* COLLAPSE DATA-API
* ================= */

$(document).on('click.collapse.data-api', '[data-toggle=collapse]', function (e) {
var $this = $(this), href
, target = $this.attr('data-target')
|| e.preventDefault()
|| (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
, option = $(target).data('collapse') ? 'toggle' : $this.data()
$this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
$(target).collapse(option)
})

}(window.jQuery);


jQuery(document).ready(function ($) {

var lastId,
topMenu = $("#top-navigation"),
topMenuHeight = topMenu.outerHeight(),
// All list items
menuItems = topMenu.find("a"),
// Anchors corresponding to menu items
scrollItems = menuItems.map(function () {
var item = $($(this).attr("href"));
if (item.length) {
return item;
}
});


// Bind to scroll
$(window).scroll(function () {

//Display or hide scroll to top button
if ($(this).scrollTop() > 300) {
$('.scrollup').fadeIn();
} else {
$('.scrollup').fadeOut();
}

if ($(this).scrollTop() > 330) {
$('.navbar').addClass('navbar-fixed-top animated fadeInDown');
} else {
$('.navbar').removeClass('navbar-fixed-top animated fadeInDown');
}

// Get container scroll position
var fromTop = $(this).scrollTop() + topMenuHeight + 10;

// Get id of current scroll item
var cur = scrollItems.map(function () {
if ($(this).offset().top < fromTop)
return this;
});

// Get the id of the current element
cur = cur[cur.length - 1];
var id = cur && cur.length ? cur[0].id : "";

if (lastId !== id) {
lastId = id;
// Set/remove active class
menuItems
.parent().removeClass("active")
.end().filter("[href=#" + id + "]").parent().addClass("active");
}
});

/*
Function for scroliing to top
************************************/
$('.scrollup').click(function () {
$("html, body").animate({
scrollTop: 0
}, 600);
return false;
});


$(window).load(function () {
function filterPath(string) {
return string.replace(/^\//, '').replace(/(index|default).[a-zA-Z]{3,4}$/, '').replace(/\/$/, '');
}
$('a[href*=#]').each(function () {
if (filterPath(location.pathname) == filterPath(this.pathname) && location.hostname == this.hostname && this.hash.replace(/#/, '')) {
var $targetId = $(this.hash),
$targetAnchor = $('[name=' + this.hash.slice(1) + ']');
var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;

if ($target) {

$(this).click(function () {

//Hack collapse top navigation after clicking
topMenu.parent().attr('style', 'height:0px').removeClass('in'); //Close navigation
$('.navbar .btn-navbar').addClass('collapsed');
var targetOffset = $target.offset().top - 63;
$('html, body').animate({
scrollTop: targetOffset
}, 800);
return false;
});



}
}
});
});
});

我还有以下 css 文件:

.animated{-webkit-animation-fill-mode:both;-moz-animation-fill-mode:both;-ms-animation-fill-mode:both;-o-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:1s;-moz-animation-duration:1s;-ms-animation-duration:1s;-o-animation-duration:1s;animation-duration:1s;}
.animated.hinge{-webkit-animation-duration:1s;-moz-animation-duration:1s;-ms-animation-duration:1s;-o-animation-duration:1s;animation-duration:1s;}


@-webkit-keyframes fadeInDown {
0% {
opacity: 0;
-webkit-transform: translateY(-20px);
}

100% {
opacity: 1;
-webkit-transform: translateY(0);
}
}

@-moz-keyframes fadeInDown {
0% {
opacity: 0;
-moz-transform: translateY(-20px);
}

100% {
opacity: 1;
-moz-transform: translateY(0);
}
}

@-o-keyframes fadeInDown {
0% {
opacity: 0;
-o-transform: translateY(-20px);
}

100% {
opacity: 1;
-o-transform: translateY(0);
}
}

@keyframes fadeInDown {
0% {
opacity: 0;
transform: translateY(-20px);
}

100% {
opacity: 1;
transform: translateY(0);
}
}

.fadeInDown {
-webkit-animation-name: fadeInDown;
-moz-animation-name: fadeInDown;
-o-animation-name: fadeInDown;
animation-name: fadeInDown;
cursor: pointer;

}

我很想做这个,但我不知道怎么做,因为我在这方面的经验不是很多。任何建议都非常感谢。谢谢

最佳答案

经过几个小时的绝望,我意识到我有一个 .js 文件与其他 .js 文件冲突。由于那个特定的 .js 文件只连接到汉堡包菜单,我所做的就是重命名它,因此让它在整个页面上都不存在,瞧,一切都完美无缺。我希望这可以帮助别人。始终检查您的 .js 文件是否相互冲突。

关于javascript - 汉堡菜单展开并立即关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45924773/

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