显示Div时显示标题
Show Heading when Div is visible
我试图显示两个标题中的一个,这取决于页面上是否有一些DOM元素可用/可见。出于某种原因,它不起作用。。。这是迄今为止的现场演示。
我有以下代码:
$('h3.list_heading').css('display', 'none');
$('h3#error').css('display', 'none');
if ( $('div.availableNowListing').filter(':visible').length == 0) {
$('h3#error').css('display', 'block');
} else {
$('h3.list_heading').css('display', 'block');
}
目前,无论我选择什么,我只会显示一个标题。。。
编辑只是为了解释应该发生什么:单击要排序的存储时,它应该只显示与该存储关联的条目。如果没有与该商店相关的水果,则标题为:
我们对xxxxx本周最佳产品的建议
应更改为
运气不好!本周我们似乎在xxxxx商店找不到任何好水果
编辑2尝试使用以下代码,但无论我选择哪个存储进行排序,即使我要查找的div存在,我也会收到错误消息。。。
$('h3.list_heading').hide();
$('h3#error').hide();
if ( $('div.availableNowListing:visible').length) {
$('h3#error').show();
} else {
$('h3.list_heading').show();
}
尝试更改switch
中的这些行
$('div.availableNowListing').not(':first').find('div.available_now_entry').fadeOut('fast');
check_heading();
相反,将函数调用转换为fadeOut()
的回调。
$('div.availableNowListing').not(':first').find('div.available_now_entry').fadeOut('fast', check_heading);
不确定这是否有帮助,但尝试将代码更改为:
$('h3.list_heading').hide();
$('h3#error').hide();
if ($('div.availableNowListing:visible').length) {
$('h3#error').show();
} else {
$('h3.list_heading').show();
}
function onscreen_sort (get_store) {
var check = false;
$('div.availableNowListing').each( function() {
// Reset Display
var correct = $(this).children('.' + get_store).not(':first-child')
var incorrect = $(this).children(':not(.' + get_store + ') ').not(':first-child')
if(correct.length > 0) record = true;
correct.find(":hidden").fadeIn('fast'); //only hide which is not correct ->less dom overlow
incorrect.find(":visible").fadeOut('fast'); //any only show which is correct but hidden
});
check_heading(check)
}
function check_heading(boo) {
$('h3#error').hide();
$('h3.list_heading').hide();
if (boo) {
$('h3.list_heading').show();
} else {
$('h3#error').show();
}
}
switch ( store_selected ) {
case "all" :
var class_match = "in_all"
onscreen_sort(class_match);
$('span.store_change').text( ' All Stores' );
$('div.availableNowListing').not(':first').find('div.available_now_entry').fadeOut('fast');
//check_heading(); //no more needed!
break;
case "asda" :
...
...
...
我希望这能奏效。祝你好运!
相关文章:
- 当我悬停使用php连接到mysql的图像时显示标题
- 如何使用 bootstrap3 和 php 突出显示标题中的活动页面
- chart js:如何显示标题或标签
- 从下拉菜单选项中显示“标题”标签
- 如何在可展开菜单中正确显示标题
- Spotify 应用程序 - 列表不显示播放列表的曲目,只显示标题
- 在 asp.net 中使用 javascript 显示标题属性消息
- 引导灯箱:显示标题属性中的图像说明
- 在浏览器的选项卡中显示标题
- 如何按焦点在 HTML 元素上显示标题
- 加载随机背景音乐并显示标题
- 如何使用ES6 angular 1.3控制器显示标题
- 在图像下方垂直和水平居中显示标题
- 如何使用d3.js在SVG图表上居中显示标题
- 在网页上显示标题或替换文本
- 如何有一个淘汰网格显示标题和基于下拉结果的数据
- 谷歌地图显示标题的信息框
- 仅在切换类时显示标题和段落
- JQuery在图像悬停显示标题标签内容,可能的
- JQuery周日历:在初始加载时只显示标题